Web3.js: myContract.methods.myMethod().call() Error Handling

Created on 13 Sep 2017  路  8Comments  路  Source: ChainSafe/web3.js

If myContract.methods.myMethod().call() returns 0x and address is expected an error is thrown
"Error: Given address "0x" is not a valid Ethereum address."

I'd like to handle this error like a promise rejection:

myContract.methods.myMethod().call().then( //no error ).catch( //error 0x ...)

But this doesn't work.

bug

Most helpful comment

This error is still coming up in web3 1.0.0-beta.35
I tried to execute a smart contract method which has nothing to do with Ethereum Address and this error cropped up, even though the transaction was executed successfully. A small stub of errortrace is as below:

index.js:1437 Error: Given address "0x00000000" is not a valid Ethereum address.
    at Object.toChecksumAddress (index.js:248)
    at SolidityTypeAddress.formatOutputAddress [as _outputFormatter] (formatters.js:284)
    at SolidityTypeAddress.push../node_modules/web3-eth-abi/src/type.js.SolidityType.decode (type.js:264)
    at type.js:226
    at SolidityTypeAddress.push../node_modules/web3-eth-abi/src/type.js.SolidityType.decode (type.js:230)
    at index.js:330
    at Array.forEach (<anonymous>)
    at ABICoder.push../node_modules/web3-eth-abi/src/index.js.ABICoder.decodeParameters (index.js:329)
    at Contract.push../node_modules/web3-eth-contract/src/index.js.Contract._decodeMethodReturn (index.js:419)
    at Method.outputFormatter (index.js:743)
    at Method.push../node_modules/web3-core-method/src/index.js.Method.formatOutput (index.js:167)
    at sendTxCallback (index.js:449)
    at index.js:132
    at inpage.js:1
    at inpage.js:1
    at o (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at a (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at a (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at inpage.js:1
    at We (inpage.js:1)
    at Object.<anonymous> (inpage.js:1)
    at e.value (inpage.js:1)
    at inpage.js:1
    at n (inpage.js:1)
    at o (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at n (inpage.js:1)
    at o (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at a (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
console.<computed> @ index.js:1437
callCallContractFn$ @ drizzle.js:17918
tryCatch @ drizzle.js:13931
invoke @ drizzle.js:14158
prototype.<computed> @ drizzle.js:13984
next @ proc.js:333

All 8 comments

I have the exact same error.

Hi Team,
Any update on the above issue.

Same problem here. Some more information:

Stacktrace:

main.js:17669 Given address "0x" is not a valid Ethereum address.
Error: Given address "0x" is not a valid Ethereum address.
    at Object.toChecksumAddress (http://localhost:3000/_next/1518876622171/page/:22959:15)
    at SolidityTypeAddress.formatOutputAddress [as _outputFormatter] (http://localhost:3000/_next/1518876622171/page/:23306:18)
    at SolidityTypeAddress.module.exports.SolidityType.decode (http://localhost:3000/_next/1518876622171/page/:24950:17)
    at http://localhost:3000/_next/1518876622171/page/:48934:49
    at Array.forEach (<anonymous>)
    at ABICoder.module.exports.ABICoder.decodeParameters (http://localhost:3000/_next/1518876622171/page/:48933:13)
    at Contract.module.exports.Contract._decodeMethodReturn (http://localhost:3000/_next/1518876622171/page/:91202:22)
    at Method.outputFormatter (http://localhost:3000/_next/1518876622171/page/:91549:46)
    at Method.module.exports.Method.formatOutput (http://localhost:3000/_next/1518876622171/page/:24265:54)
    at sendTxCallback (http://localhost:3000/_next/1518876622171/page/:24556:33)
    at http://localhost:3000/_next/1518876622171/page/:72141:9
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:9935:9
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:735:16
    at next (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:5577:29)
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1220:16
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:735:16
    at replenish (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1255:25)
    at iterateeCallback (chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1245:17)
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:1220:16
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:9870:7
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:10030:16
    at chrome-extension://nkbihfbeogaeaoehlefnkodbefgpgknn/scripts/inpage.js:3358:16
From previous event:
    at Promise.longStackTracesCaptureStackTrace [as _captureStackTrace] (http://localhost:3000/_next/1518876622171/page/:85400:19)
    at Promise._resolveFromExecutor (http://localhost:3000/_next/1518876622171/page/:87438:10)
    at new Promise (http://localhost:3000/_next/1518876622171/page/:87050:14)
    at PromiEvent (http://localhost:3000/_next/1518876622171/page/:48141:24)
    at send (http://localhost:3000/_next/1518876622171/page/:24549:21)
    at Object._executeMethod (http://localhost:3000/_next/1518876622171/page/:91557:24)
    at Function._callee$ (http://localhost:3000/_next/1518876622171/page/campaigns/show:53978:54)

Last line is a call without parameters:
return campaign.methods.getSummary().call();

From this project: https://github.com/StephenGrider/EthereumCasts/tree/master/kickstart

Thus it's not an adress which we pass, but something implicitely taken from MetaMask via web3.

The cause in my case was very stupid: Serverside pre-rendering was using Rinkeby, but I had MetaMask on Ropsten. Problem solved for me. But still a very stange error message for this kind of problem.

@Boehrner Could you please provide more informations? Your contract code and the JS script for example :)

This got fixed with the latest version of Web3.js. It will now return null.

This error is still coming up in web3 1.0.0-beta.35
I tried to execute a smart contract method which has nothing to do with Ethereum Address and this error cropped up, even though the transaction was executed successfully. A small stub of errortrace is as below:

index.js:1437 Error: Given address "0x00000000" is not a valid Ethereum address.
    at Object.toChecksumAddress (index.js:248)
    at SolidityTypeAddress.formatOutputAddress [as _outputFormatter] (formatters.js:284)
    at SolidityTypeAddress.push../node_modules/web3-eth-abi/src/type.js.SolidityType.decode (type.js:264)
    at type.js:226
    at SolidityTypeAddress.push../node_modules/web3-eth-abi/src/type.js.SolidityType.decode (type.js:230)
    at index.js:330
    at Array.forEach (<anonymous>)
    at ABICoder.push../node_modules/web3-eth-abi/src/index.js.ABICoder.decodeParameters (index.js:329)
    at Contract.push../node_modules/web3-eth-contract/src/index.js.Contract._decodeMethodReturn (index.js:419)
    at Method.outputFormatter (index.js:743)
    at Method.push../node_modules/web3-core-method/src/index.js.Method.formatOutput (index.js:167)
    at sendTxCallback (index.js:449)
    at index.js:132
    at inpage.js:1
    at inpage.js:1
    at o (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at a (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at a (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at inpage.js:1
    at We (inpage.js:1)
    at Object.<anonymous> (inpage.js:1)
    at e.value (inpage.js:1)
    at inpage.js:1
    at n (inpage.js:1)
    at o (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at n (inpage.js:1)
    at o (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at inpage.js:1
    at u (inpage.js:1)
    at a (inpage.js:1)
    at inpage.js:1
    at inpage.js:1
console.<computed> @ index.js:1437
callCallContractFn$ @ drizzle.js:17918
tryCatch @ drizzle.js:13931
invoke @ drizzle.js:14158
prototype.<computed> @ drizzle.js:13984
next @ proc.js:333
Was this page helpful?
0 / 5 - 0 ratings

Related issues

xpepermint picture xpepermint  路  3Comments

nivida picture nivida  路  3Comments

FradSer picture FradSer  路  3Comments

SCBuergel picture SCBuergel  路  3Comments

baxy picture baxy  路  3Comments