0

web3.utils.fromWei(web3.eth.getBalance(web3.eth.coinbase), 'ether').toNumber()

gives this error:

> /usr/local/lib/node_modules/truffle/build/cli.bundled.js:369506
>     throw new Error('Provided address "'+ address +'" is invalid, the capitalization checksum test failed, or its an indrect IBAN address
> which can\'t be converted.');
>     ^
> 
> Error: Provided address "undefined" is invalid, the capitalization
> checksum test failed, or its an indrect IBAN address which can't be
> converted.
>     at Method.inputAddressFormatter (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-helpers/src/formatters.js:409:1)
>     at /usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-method/src/index.js:144:1
>     at Array.map (<anonymous>)
>     at Method.formatInput (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-method/src/index.js:142:1)
>     at Method.toPayload (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-method/src/index.js:177:1)
>     at Eth.send [as getBalance] (/usr/local/lib/node_modules/truffle/build/webpack:/~/web3-eth/~/web3-core-method/src/index.js:467:1)
>     at evalmachine.<anonymous>:0:29
>     at Script.runInContext (vm.js:134:20)
>     at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/console.js:199:1)
>     at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/console.js:213:1)
>     at ReplManager.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-core/lib/repl.js:118:1)
>     at bound (domain.js:395:14)
>     at REPLServer.runBound [as eval] (domain.js:408:12)
>     at REPLServer.onLine (repl.js:639:10)
>     at REPLServer.emit (events.js:188:13)
>     at REPLServer.EventEmitter.emit (domain.js:441:20)
>     at REPLServer.Interface._onLine (readline.js:308:10)
>     at REPLServer.Interface._line (readline.js:654:8)
>     at REPLServer.Interface._ttyWrite (readline.js:933:14)
>     at REPLServer.self._ttyWrite (repl.js:712:7)
>     at ReadStream.onkeypress (readline.js:184:10)
>     at ReadStream.emit (events.js:188:13)

truffle version:

Truffle v5.0.1 (core: 5.0.1)
Solidity v0.5.0 (solc-js)
Node v11.6.0

I'm trying to set up a test environment, ganache-cli (Ganache CLI v6.2.5 (ganache-core: 2.3.3)) is running in another terminal window.

  • What does web3.eth.coinbase returns? From the message it seems to returns undefined which is an invalid address – Ismael Jan 11 at 21:14
  • yes, it returns undefiined it seems like 'eth' doesn't have membe 'coinbase', because pressing TAB is not finishing the sentence web3.eth.accounts exists, but web3.eth.accounts[0] returns undefined as well. – imestin Jan 12 at 12:31
1

I've tried this script with your exact same versions and it works truffle exec balance.js

module.exports = async () => {
  const coinbase = await web3.eth.getCoinbase();
  const balance = await web3.eth.getBalance(coinbase);
  console.log(web3.utils.fromWei(balance, "ether"));
  console.log("------------------");
  console.log(web3.utils.fromWei(await web3.eth.getBalance(await web3.eth.getCoinbase()), "ether"));
}
  • yes! It works. Thank you really much for your help! Using network 'development'. 100 ------------------ 100 – imestin Jan 13 at 10:01
1

I suspect it is because you arent calling coinbase properly. It eth.getbalance function requires an address type.

Change this to:

web3.utils.fromWei(web3.eth.getBalance(web3.eth.getCoinbase()), 'ether').toNumber()
  • it's still not working, I get the same error /usr/local/lib/node_modules/truffle/build/cli.bundled.js:369506 throw new Error('Provided address "'+ address +'" is invalid, the capitalization checksum test failed, or its an indrect IBAN address which can\'t be converted.'); – imestin Jan 12 at 12:26
  • Try it without the promise i.e web3.eth.getCoinbase – Samuel Dare Jan 12 at 12:34
  • that works and web3.eth.getCoinbase() also works. it gives an address: '0x1c48f9c54db0c9c27a28b9f78d528b31abba978f' – imestin Jan 12 at 12:51
  • If it works accept the answer .. what changes did you make? – Samuel Dare Jan 12 at 12:55
  • 1
    @imestin With truffle v5 you are using web3 v1 so functions return promises to use them you need to await for their result. Like this web3.utils.fromWei(await web3.eth.getBalance(await web3.eth.getCoinbase()), 'ether'), also .fromWei returns a string and you cannot call .toNumber(). Look at the documentation web3js.readthedocs.io/en/1.0/web3-eth.html for the return types. – Ismael Jan 12 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.