I have the following script:

var assert = require('assert');
const path = require("path");
     const fs = require("fs");

module.exports = async function(callback) 
     let accounts = web3.eth.getAccounts()

     const acc0 = accounts[0]
     const acc2 = accounts[2];
     acc2bal = await web3.eth.getBalance(acc2);
     web3.utils.fromWei(acc2bal, "ether");

catch (error) {

I am getting the error:

$ truffle exec mortal2.js
Using network 'development'.

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 (/home/zulfi/.nvm/versions/node/v10.23.3/lib/node_modules/truffle/build/webpack:/node_modules/web3-core-helpers/src/formatters.js:475:1)

I tried the following option:

//acc2bal = await web3.eth.getBalance(acc2);
//web3.utils.fromWei(acc2bal, "ether");

but still, I am not getting the value of accounts[2]

Somebody, please guide me


1 Answer 1


Try with await web3.eth.getAccounts().

As per the documentation, getAccounts returns a promise.


  • No error but no output; please guide me how to display the output acc2? Zulfi.
    – zak100
    Commented Mar 24, 2023 at 15:43
  • const acc0 = accounts[0]; const acc2 = accounts[2]; console.log(acc0, acc2)
    – Adam Boudj
    Commented Mar 24, 2023 at 15:58
  • Its printing the address, not the value: 0xfbC59408f55E073e83CfBa5844B99f8578284812 0x2FC196B995549AB023952E8A01b0218473126B94, Please guide me how to print the balance?Zulfi
    – zak100
    Commented Mar 24, 2023 at 16:21
  • You asked for the acc2. const acc2balance = await web3.eth.getBalance(acc2); const acc2balanceFromWei = web3.utils.fromWei(acc2bal, "ether"); console.log(acc2balance); console.log(acc2balanceFromWei);
    – Adam Boudj
    Commented Mar 24, 2023 at 16:40
  • I am getting an error:Error: Please pass numbers as strings or BN objects to avoid precision errors. Kindly run your code before posting.
    – zak100
    Commented Mar 24, 2023 at 17:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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