1

I keep getting this "Error: The contract code couldn't be stored, please check your gas amount." message when I try to deploy my contract to the blockchain.

I read that is a generic error so I'd like to ask you for your help to find the problem.

Here is my contract's code, im trying to store in a byte32 array some sha256 hashes and then check if some hash already exists in the array.

pragma solidity ^0.4.0;

contract Mortal {
   address owner;

   function Mortal() public { owner = msg.sender; }

   function kill() public { if (msg.sender == owner) selfdestruct(owner); }
}

contract Log is Mortal {
    bytes32[] id;

    function Log (string data) public Mortal(){
        id.push(sha256(abi.encodePacked(data)));
    }

    function mainId() public view returns (bytes32) {
        return id[0];
    }

    function check(string data) public view returns (bool){
        bytes32 d = sha256(abi.encodePacked(data));
        uint i = 0;
        bool enc = false;
        while(!enc && i < id.length){
            if(id[i] == d){
                enc = true;
            }
            i++;
        }

        return enc;
    }
    function add(string data) public {
        id.push(sha256(abi.encodePacked(data)));
    }
}

And here is my web3deploy code:

var data = "12345";
var logContract = web3.eth.contract([{"constant":true,"inputs":[],"name":"mainId","outputs":[{"name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"kill","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"data","type":"string"}],"name":"add","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"data","type":"string"}],"name":"check","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"inputs":[{"name":"data","type":"string"}],"payable":false,"stateMutability":"nonpayable","type":"constructor"}]);
var log = logContract.new(
   data,
   {
     from: web3.eth.accounts[0], 
     data: '0x608060405234801561001057600080fd5b506040516106f83803806106f883398101806040528101908080518201929190505050336000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060016002826040516020018082805190602001908083835b6020831015156100b0578051825260208201915060208101905060208303925061008b565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040526040518082805190602001908083835b60208310151561011957805182526020820191506020810190506020830392506100f4565b6001836020036101000a0380198251168184511680821785525050505050509050019150506020604051808303816000865af115801561015d573d6000803e3d6000fd5b5050506040513d602081101561017257600080fd5b8101908080519060200190929190505050908060018154018082558091505090600182039060005260206000200160009091929091909150906000191690555050610536806101c26000396000f300608060405260043610610062576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff16806314d6d2141461006757806341c0e1b51461009a578063b0c8f9dc146100b1578063b6f921ad1461011a575b600080fd5b34801561007357600080fd5b5061007c61019b565b60405180826000191660001916815260200191505060405180910390f35b3480156100a657600080fd5b506100af6101bd565b005b3480156100bd57600080fd5b50610118600480360381019080803590602001908201803590602001908080601f016020809104026020016040519081016040528093929190818152602001838380828437820191505050505050919291929050505061024e565b005b34801561012657600080fd5b50610181600480360381019080803590602001908201803590602001908080601f0160208091040260200160405190810160405280939291908181526020018383808284378201915050505050509192919290505050610390565b604051808215151515815260200191505060405180910390f35b6000600160008154811015156101ad57fe5b9060005260206000200154905090565b6000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16141561024c576000809054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b565b60016002826040516020018082805190602001908083835b60208310151561028b5780518252602082019150602081019050602083039250610266565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040526040518082805190602001908083835b6020831015156102f457805182526020820191506020810190506020830392506102cf565b6001836020036101000a0380198251168184511680821785525050505050509050019150506020604051808303816000865af1158015610338573d6000803e3d6000fd5b5050506040513d602081101561034d57600080fd5b8101908080519060200190929190505050908060018154018082558091505090600182039060005260206000200160009091929091909150906000191690555050565b6000806000806002856040516020018082805190602001908083835b6020831015156103d157805182526020820191506020810190506020830392506103ac565b6001836020036101000a0380198251168184511680821785525050505050509050019150506040516020818303038152906040526040518082805190602001908083835b60208310151561043a5780518252602082019150602081019050602083039250610415565b6001836020036101000a0380198251168184511680821785525050505050509050019150506020604051808303816000865af115801561047e573d6000803e3d6000fd5b5050506040513d602081101561049357600080fd5b8101908080519060200190929190505050925060009150600090505b801580156104c1575060018054905082105b156104ff5782600019166001838154811015156104da57fe5b90600052602060002001546000191614156104f457600190505b8160010191506104af565b8093505050509190505600a165627a7a7230582010ec72b950c87e36e8b36c492e1c6087adf278c914cae12487acc2669cbf87b50029', 
     gas: '5000000000'
   }, function (e, contract){
    console.log(e, contract);
    if (typeof contract.address !== 'undefined') {
         console.log('Contract mined! address: ' + contract.address + ' transactionHash: ' + contract.transactionHash);
    }
 })

I have enough funds in my account so I dont really know whats going on. Im using Remix to create and compile the code and Geth to deploy the contract into the blockchain.

Update

I find out that the problem resides in the Log constructor. If I remove the id.push(sha256(abi.encodePacked(data))); line I can actually deploy the contract into the chain, but I dont know why and how to make It work just the way it is.

  • Have you tried a lower gas limit? 5,000,000,000 is way past the maximum block size of 8,000,000. I don't know if that issue causes that error message, but it's probably worth trying a lower number if you haven't already (e.g. 2,000,000). – user19510 Jul 1 '18 at 20:26
  • @smarx I already tried with lower gas limits and it didnt work either. – Kurosh D. Jul 1 '18 at 20:31

Your Answer

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

Browse other questions tagged or ask your own question.