0

I'm trying to deploy a smart contract onto the Ethereum blockchain by signing the transaction on an offline computer and then transferring the byte code to an online system for deployment. Because of this, I am not able to query what the current gas price and gas limits are in real time.

I am getting an 'Error: Returned error: exceeds block gas limit'.

I believe the price for deploying a contract is based more on how many functions are run and resources used and so the size might be too crude of a measurement to tell what's going on, but mine is: 3984 bytes.

I currently have my gas limit set to 1,200,000 (1.2 million) and my gas price set to 2Gwei (2,000,000,000 or 2 billion). Note: I just tried it and it fails using a gas limit of 500,000! WTF??

I don't understand how I'm exceeding the block limit when https://ethstats.net/ consistently reports a block limit of around 8,000,000 (8 million).

I am using multiple solidity source files which I read into the sol_input_array, and then target the main file which draws on the dependent's functions with the parent_file_and_object string.

There seems to be more questions than answers on the internet concerning this particular error, so perhaps we could collaborate on an exhaustive list so this error won't be so perplexing when we run into it!

~$ geth version
Geth
Version: 1.8.2-stable
Architecture: amd64
Protocol Versions: [63 62]
Network Id: 1
Go Version: go1.10
Operating System: darwin
GOPATH=
GOROOT=/usr/local/opt/go/libexec

Project version data:

Node:             v9.10.0
web3:             [email protected]
file-system (fs): mac:[email protected]  linux: [email protected]
solc:             [email protected]
ethereumjs-tx:    [email protected] 

Here is my contract signing function:

function compile_and_sign_transaction_offline (p_key, address, gasPriceHex, parent_file_and_object){

    var privateKey = new Buffer(p_key, 'hex')

    const compiled_contract = solc.compile({sources: sol_input_array}, 1); 
    const bytecode = compiled_contract.contracts[parent_file_and_object].bytecode;
    const contractData = '0x' + bytecode;

    //I have currently have been testing gas prices of 1.2-3 Gwei
    const gasLimitHex = '0x124F80';     //1,200,000 gas

    const rawTx = { 
        nonce: 0x00,  
        gasPrice: gasPriceHex,
        gasLimit: gasLimitHex,
        data: contractData,
        from: address 
    };  

    const tx = new Tx(rawTx);
    tx.sign(privateKey);

    const serializedTx = tx.serialize();
    const signed_transaction = serializedTx.toString('hex');
    fs.writeFileSync("signed_tx", signed_transaction);
}
3
  • How do you send the signed transaction? If you miss the starting '0x' it will interpret the rest as string not as hexadecimal. Also check the signed transaction is correctly copied from the offline computer.
    – Ismael
    Apr 21, 2018 at 22:16
  • It seems that the cost of deploying a contract is 200 gas per byte plus some constants. So for 4kB, 1m gas should be sufficient. ethereum.stackexchange.com/questions/32831/… Apr 28, 2018 at 0:39
  • For the record, here are the stats for the mainnet deployment: Gas Limit: 5200000 Gas Used By Txn: 1119499 Gas Price: 0.0000000045 Ether (4.5 Gwei) Actual Tx Cost/Fee: 0.0050377455 Ether ($3.31) Apr 28, 2018 at 0:52

1 Answer 1

1

So it turns out that this function works fine. The problem was somewhere in the pipe to the blockchain. I'm not sure if my sender function, instance of geth, or my downloaded blockchain itself was the problem.

The craziest thing though was that using the same code (both the offline signing AND the online deployment flow), I was able to deploy to the rinkeby testnet just fine while deploying to mainnet returned this 'exceeds block gas limit' error.

So kids, make sure that in addition to testnet testing you do testing on the mainnet before release!

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.