1

I have recently migrated my smart contract from Ropsten (changing only the Infura Node) to Kovan and the first thing that I encountered was an error:

Error by deploying transaction Error: Returned error: Insufficient funds. The account you tried to send transaction from does not have enough funds. Required 5596500000000000000 and got: 4747259100000000000.

The funds I had were 4.7 ETH, so way more than a transaction needed. So I got more ether from Kovan Faucet and pushed the transaction once more and it turned out that it only needed 0.0160552 Ether. I am a bit confused, where does this artificial requirement came from since both gasPrice and gasLimit are much smaller. The problem is semi solved right now by having higher balance than 5.5 ETH, but I would like to know the reason for it to eliminate it before migrating to mainnet. My code in NodeJS for deploying transaction looks like this:

  function deploying_transaction(event, callback){
    console.log("Data raw", event.dataContractCallRaw)
    web3.eth.getGasPrice(function(err,gasPriceWei){
        if (err){
            console.log("Error by getting Gas price", err)
            callback(err)
        }else {
            console.log("gasPrice", gasPriceWei)
            web3.eth.getBlock("latest", function(err,block){
                if(err){
                    console.log("Error by getting gas limit", err)
                    callback(err)
                } else {
                    console.log("Block Gas Limit", block.gasLimit)
                    web3.eth.getTransactionCount(event.addressSender,function(err,result){
                        if (!err){
                            var rawTx = {
                                nonce: web3.utils.toHex(result),
                                to: event.addressContract,
                                gasPrice: web3.utils.toHex(web3.utils.toWei('700','gwei')), // gasPriceWei in the future we can use gasPrice wei, but it is fucked up for now
                                gasLimit: web3.utils.toHex(block.gasLimit - 5000), 
                                value: 0,
                                data: event.dataContractCallRaw
                            }
                            console.log("rawTx", rawTx)
                            web3.eth.accounts.signTransaction(rawTx, event.privateKeySigner).then(signed => {
                                web3.eth.sendSignedTransaction(signed.rawTransaction, function(err, response, receipt){
                                    if(err){
                                        callback(err)
                                    } else {
                                        console.log("Response from network", response)
                                        callback(null,response)
                                    }
                                })
                            });
                        }else{
                            console.log('Error in getting transaction count ' + JSON.stringify(err));
                            callback(err)
                        }
                    });
                }

            });
        }

    })
}
TylerH
  • 20,799
  • 66
  • 75
  • 101

1 Answers1

0

I discovered that lowering the gasLimit makes the requirement for funds smaller.

TylerH
  • 20,799
  • 66
  • 75
  • 101