3

I try to deploy the following code:

contract Sample {
struct Participant {
    address etherAddress;
    uint amount;
}

Participant[] public participants;
uint public amountRaised;

function() {
    enter();
}

function enter() {
    uint amount = msg.value;
    uint n = participants.length;

    participants.length += 1;
    participants[n].etherAddress = msg.sender;
    participants[n].amount = amount;

    amountRaised += amount;
}

}

In Mix IDE it works correctly but does not work on Ethereum testnet(balance not changed). You can try here: http://testnet.etherscan.io/address/0xea1410a6d5ef3d6d5a392b24087c24845e7170a3 . I noticed that contract works if delete participants[n].amount = amount OR amountRaised += amount line. So, I can use only one msg.value variable. How can I use msg.value twice?
eth
  • 85,679
  • 53
  • 285
  • 406

1 Answers1

4

Often, when removing a few lines solves an issue, it indicates an out-of-gas error.

To diagnose this problem, you can use a block explorer that shows EVM traces, like http://live.ether.camp, or start geth with --debug and watch the logs.

You can also use msg.gas to check the remaining gas from within the contract, and throw an event or some other error if it gets too low.

Tjaden Hess
  • 37,046
  • 10
  • 91
  • 118
  • see also http://ethereum.stackexchange.com/questions/1181/how-do-i-know-when-ive-run-out-of-gas/1182#1182 – Paul S Feb 16 '16 at 01:59