2

I'm trying to run an example Solidity program - Congress from Etherum.org which I believe it should be right, but I always got "transact to Congress.addMember errored: Gas required exceeds limit: 300000000. An important gas estimation might also be the sign of a problem in the contract code. Please check loops and be sure you did not sent value to a non payable function (that's also the reason of strong gas estimation). " when I call a function in Remix while it can be called successfully from an ether wallet. The function I called is addmember(address targetMember, string memberName):

mapping (address => uint) public memberId;
Member[] public members;
struct Member {
    address member;
    string name;
    uint memberSince;
}
function Congress (
    uint minimumQuorumForProposals,
    uint minutesForDebate,
    int marginOfVotesForMajority
)  payable public {
    changeVotingRules(minimumQuorumForProposals, minutesForDebate, marginOfVotesForMajority);
    // It’s necessary to add an empty first member
    addMember(0, "");
    // and let's add the founder, to save a step later
    addMember(owner, 'founder');
}

function addMember(address targetMember, string memberName) onlyOwner public {
    uint id = memberId[targetMember];
    if (id == 0) {
        memberId[targetMember] = members.length;
        id = members.length++;
    }

    members[id] = Member({member: targetMember, memberSince: now, name: memberName});
    MembershipChanged(targetMember, true);
}

More strange thing is if I call addmember(0x45598A0733111F1Cff340504dE74cbCDC54B101d,"Name1"), Remix told me this gas error, but if I call addmember(0x0,"Name1"), It can be done without any problem.

I use Injected web3 option and Ropsten testnet, and I send 0 ether as value, gas limit from 300000 to 300000000, all don't work. Any suggestion?

2
  • The function is onlyOwner are you sending from the owner account? Ropsten has a 6M gas limit you can't set gas higher than that. Also ir works correctly with "Javascript VM" consuming less than 120k gas.
    – Ismael
    Commented Feb 22, 2018 at 4:13
  • I call it from owner account. The gas limit doesn't matter because I tried many different figures, all failed.
    – PeterT
    Commented Feb 22, 2018 at 7:41

1 Answer 1

0

Sorry, It's my stupid mistake. I forgot to put "" into.

Your Answer

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

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