11

I am running into out of gas exception while calling this function : contractInstance.createProposal("ADHD", "Foo", 2, {from: web3.eth.accounts[1]}) . I'm super new to ethereum and I would really appreciate some help!

Here's my super simple contract

pragma solidity ^0.4.2;

contract DataProvider {

struct Proposal {
    address owner;
    uint id;
    bytes16 name;
    bytes32 desc;
    uint pool_size;
    address[] consents;
    bool initialized;
}

address public admin;
Proposal[] public proposals;

function DataProvider() {
    admin = msg.sender;
}

function createProposal(bytes16 nm, bytes32 ds, uint n) {
    address[] memory cons;
    proposals.push(Proposal({ owner: msg.sender, id: proposals.length, name: nm, desc: ds, consents: cons, pool_size: n, initialized: true }));
}


}
  • 1
    with a gas limit of 3000000 your code works properly – Badr Bellaj Sep 17 '17 at 8:44
  • 1
    @itachi first welcome to the community, since you seem to be new to the community, FYI, It's better and would be useful when answering an question if you can mention what you tried to solve the problem and what were the outputs of those when asking a question. Good luck :) . – Achala Dissanayake Sep 17 '17 at 10:36
  • 1
    @AchalaDissanayake Gotcha, will do next time for sure :) Thanks for being so kind about it! – itachi Sep 17 '17 at 12:57
10

First check your account balance : balance = web3.eth.getBalance(someAddress); then try to specify the gaslimit contractInstance.createProposal("ADHD", "Foo", 2, {from: web3.eth.accounts[1], gas:3000000})

  • 3
    Awesome, thanks! :) Also, I had a couple other functions too which I haven't included for simplicity but then they all worked fine. Why does this function consume so much more gas than others? – itachi Sep 17 '17 at 9:20
  • 1
    it depends on the computation and the used storage – Badr Bellaj Sep 17 '17 at 9:23
  • 1
    @BadrBellaj I changed the gas limit to 3000000 using remix. But its still giving me out of gas error. Did i have to change gas price as well? My current gas price is 20000000000. – Zeeshan Ahmad Khalil Sep 15 at 6:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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