I have the following script:
var assert = require('assert');
const path = require("path");
const fs = require("fs");
module.exports = async function(callback)
{
try{
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) {
console.log(error)
}
callback();
}
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");
console.log(web3.eth.accounts)
but still, I am not getting the value of accounts[2]
Somebody, please guide me
Zulfi.