web3.js icon indicating copy to clipboard operation
web3.js copied to clipboard

myContract.methods.myMethod().call() Error Handling

Open Boehrner opened this issue 9 years ago • 8 comments

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.

Boehrner avatar Sep 13 '17 09:09 Boehrner

I have the exact same error.

ahmb84 avatar Nov 20 '17 21:11 ahmb84

Hi Team, Any update on the above issue.

ksbachu avatar Feb 14 '18 06:02 ksbachu

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.

mhoennig avatar Feb 17 '18 14:02 mhoennig

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.

mhoennig avatar Feb 17 '18 15:02 mhoennig

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

nivida avatar Aug 17 '18 11:08 nivida

Very similar https://github.com/ethereum/web3.js/issues/1954

k06a avatar Sep 18 '18 06:09 k06a

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

nivida avatar Apr 17 '19 12:04 nivida

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

kombos avatar May 07 '19 13:05 kombos