Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

estimateGas for ERC20 contract doesn't work #1236

Closed
felgarte opened this issue Dec 15, 2017 · 1 comment
Closed

estimateGas for ERC20 contract doesn't work #1236

felgarte opened this issue Dec 15, 2017 · 1 comment

Comments

@felgarte
Copy link

I'm trying to obtain estimate gas for an erc20 token contract deployed over kovan network, just like this:

var getCode = web3.eth.getCode(tokenAddress)

var transactionObject = {
  from: address,
  to: tokenAddress,
  value: web3.utils.toWei(data.value.toString()),
  data: getCode
}

web3.eth.estimateGas(transactionObject)

The response:

Unhandled rejection Error: Returned error: Transaction execution error. at Object.ErrorResponse (/Users/rstorm/repos/audity/checkBalances/node_modules/web3/packages/web3-core-helpers/src/errors.js:29:16) at /Users/rstorm/repos/audity/checkBalances/node_modules/web3/packages/web3-core-requestmanager/src/index.js:137:36 at XMLHttpRequest.request.onreadystatechange (/Users/rstorm/repos/audity/checkBalances/node_modules/web3/packages/web3-providers-http/src/index.js:64:13) at XMLHttpRequestEventTarget.dispatchEvent (/Users/rstorm/repos/audity/checkBalances/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:64:18) at XMLHttpRequest._setReadyState (/Users/rstorm/repos/audity/checkBalances/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:354:12) at XMLHttpRequest._onHttpResponseEnd (/Users/rstorm/repos/audity/checkBalances/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:509:12) at IncomingMessage.<anonymous> (/Users/rstorm/repos/audity/checkBalances/node_modules/web3/packages/web3-providers-http/node_modules/xhr2/lib/xhr2.js:469:24) at emitNone (events.js:110:20) at IncomingMessage.emit (events.js:207:7) at endReadableNT (_stream_readable.js:1059:12) at _combinedTickCallback (internal/process/next_tick.js:138:11) at process._tickDomainCallback (internal/process/next_tick.js:218:9)

@nisdas
Copy link
Contributor

nisdas commented Dec 17, 2017

I think the error might have more to do with your transaction object specifically the
value: web3.utils.toWei(data.value.toString())
the toWei function is to convert any number in ether to wei. But the data.value.toString() returns a string type which will cause an error in your transaction object , try to return a number instead of a string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants