openethereum / pwasm-tutorial

A step-by-step tutorial on how to write contracts in Wasm for Kovan
GNU General Public License v3.0
229 stars 34 forks source link

Gas limit error deploying contract #10

Closed maurelian closed 6 years ago

maurelian commented 6 years ago

I think this is an issue with my Parity setup.

Steps

I run the deploy script, up until this point:

TokenContract.deploy({data: codeHex, arguments: [10000000]}) .send({from: web3.eth.defaultAccount}).then((a) => console.log(a));

to which I get: > (node:44643) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: The contract code couldn't be stored, please check your gas limit.

In the parity console output I have:

2018-03-23 21:23:01 Transaction mined (hash 5eb543c134d8c0e6f37f87037b95fc378392232552517cfa1040ca99bac39f3d) 2018-03-23 21:23:01 Imported #3 701a…9517 (1 txs, 0.94 Mgas, 1.14 ms, 12.45 KiB)

The transaction receipt has: cumulativeGasUsed: 940000, gasUsed: 940000,

When I look at the block it has a much higher gas limit.

things I tried:

  1. Increasing the gasLimit value in the genesis values.
  2. adding a higher --tx-gas-limit=ff5b8d80 value.

Neither of those seemed to do it.

lexfrl commented 6 years ago

Hi @maurelian! Thanks for the feedback! Have you tried to increase gasLimit for the transaction itself instead of block gasLimit?

lexfrl commented 6 years ago

Just checked it. Turns out that token contract deployment uses 4053388 of gas. For some reason Web.js fails to estimate gas for this transaction. I've fixed it with gasLimit: 5000000 for deploy

TokenContract.deploy({data: codeHex, arguments: [10000000]}).send({gasLimit: 5000000, from: web3.eth.defaultAccount}).then((a) => console.log(a));
maurelian commented 6 years ago

Thanks @fckt that resolved it!

One other small thing that's not working, after running TokenContract.deploy(...), I believe I should be able to run this command immediately:

var TokenContract = new web3.eth.Contract(abi, "0x3e0daec7b626bf173216ad18eaf2e349c1527ce2", { from: web3.eth.defaultAccount });

But I'm getting this error:

Error: This contract object doesn't have address set yet, please set an address first.

I just work around it by getting the address from the tx receipt, and the instantiating a new contract object with var TokenContract = new web3.eth.Contract(...).

Perhaps this is related to web3 1.0? Regardless, if there's a better way to get the address on the TokenContract object that would be helpful.

lexfrl commented 6 years ago

@maurelian

var TokenContract = new web3.eth.Contract(abi, "0x3e0daec7b626bf173216ad18eaf2e349c1527ce2", { from: web3.eth.defaultAccount });

works for me..

I've changed the script a bit:

web3.eth.personal.unlockAccount(web3.eth.defaultAccount, "user").then(() => TokenDeployTransaction.estimateGas()).then(gas => TokenDeployTransaction.send({gasLimit: gas, from: web3.eth.defaultAccount})).then(contract => { console.log("Address of new contract: " + contract.options.address); TokenContract = contract; }).catch(err => console.log(err));

(see full version in tutorial https://github.com/paritytech/pwasm-tutorial#deploy) This way: 1) make sure we have unlocked an account from which we deploy 2) we always have enough gas to deploy 3) TokenDeployTransaction.send returns a Promise which resolves to the contract itself. So we rewrite TokenContract to contract resolved with that promise (TokenContract = contract). As a result we have TokenContract with an associated address

maurelian commented 6 years ago

I guess my web3js-fu is a bit rusty. Thanks a lot @fckt!

mishaaaa commented 5 years ago

Just checked it. Turns out that token contract deployment uses 4053388 of gas. For some reason Web.js fails to estimate gas for this transaction. I've fixed it with gasLimit: 5000000 for deploy

TokenContract.deploy({data: codeHex, arguments: [10000000]}).send({gasLimit: 5000000, from: web3.eth.defaultAccount}).then((a) => console.log(a));

I tried this one. The error was resolved but the transaction is not getting commited. Its in pending state. Promise { <pending, domain: Domain { domain: null, _events: [Object: null prototype] { removeListener: [Function: updateExceptionCapture], newListener: [Function: updateExceptionCapture], error: [Function: debugDomainError] }, _eventsCount: 3, _maxListeners: undefined, members: [], [Symbol(kWeak)]: WeakReference {} } }