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?

3
  • 1
    You should be able to use it as many times as you'd like. Have you tried sending more gas? That could be the issue. Feb 13, 2016 at 22:27
  • Ok, contract works with bigger gas. Thank you for help! :) Feb 13, 2016 at 23:06
  • No problem. That's usually the problem Feb 13, 2016 at 23:08

1 Answer 1

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.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.