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);
}