0

Context

  • geth: Geth/v1.4.18-stable/linux/go1.5.1
  • solc: 0.4.6

I am writing a contract testing it on a private network with a large amount of pre-allocated gas. The following works perfectly fine:

pragma solidity ^0.4.0;

contract accountList {

    address[] allowedClient;

    function add(address client) returns (bool) {
        allowedClient.push(client);
        return true;
    }

    function get() constant returns (address[]) {
        return allowedClient;
    }

}

Addresses are well added when I call the add method. I can retrieve them calling the get method. This cost me nothing since I use the same account to call the contract and to mine the transaction (I earn more gas mining the transaction than I use to call the contract).

Issue

I run out of gas when I add a second array with the same behaviour:

pragma solidity ^0.4.0;

contract accountList {

    address[] allowedClient;        
    address[] test;

    function add(address client) returns (bool) {
        allowedClient.push(client);
        test.push(client);
        return true;
    }

    function get() constant returns (address[]) {
        return allowedClient;
    }

}

Calling the add method make me run out of gas

 contractInstance.add(coinbase, {from: coinbase}, function(error, result) {
    ...
 }

Debug in the geth console:

> eth.getBalance(eth.accounts[0])
1.245e+21
> var t = web3.debug.traceTransaction('0x456...')
> t.structLogs[t.structLogs.length-1].error
"Out of gas"

A balance of 1.245e+21 should be enough isn't it? Which configuration can I use to avoid gas limitation on my private network?

  • How did you call the add method? Can you show that too? – atomh33ls Dec 8 '16 at 14:47
2

By default, the gas will be set to 90,000 when executing a transaction to a smart contract, and 21,000 when execution a transaction to transfer ethers to another account.

Here's a screenshot showing that you will need more than the default 90,000 gas and at least 103,866 enter image description here

You will need to manually specify what your gas limits are, e.g.:

eth.sendTransaction({from: ..., to: ..., gas: 150000})

And for comparison, if you omit the test.push(...) statement, the gas cost for executing add(...) is 63,383 and the gas in this situation is much smaller than the 90,000 default gas limit:

enter image description here

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.