Search code examples
solidityethers.jshardhat

Solidity, Visualizing [object object] when checking wallet address with hardhat, ethers.js


I'm having this issue when testing this lines of code:

it("Subscribes multiple deployers", async function () {
              const additionalEntrances = 3
              const startingIndex = 0
              const accounts = await ethers.getSigners()
              for (let i = startingIndex; i < startingIndex + additionalEntrances; i++) {
                MarketOrder = MarketOrder.connect(accounts[i])
                await MarketOrder.Deposit(ArraySL[i], { value: ArrayValue[i] })
                console.log(`Account: ${accounts[i].toString()}  Value: ${ArrayValue[i]} SL: ${ArraySL[i]}`)
              }
            }) 

And this is how it shows in the console

Account: [object Object]  Value: 5000000000000000000 SL: 1200
Account: [object Object]  Value: 10000000000000000000 SL: 1502
Account: [object Object]  Value: 20000000000000000000 SL: 1960

How can I visualize wallet address properly?


Solution

  • const accounts = await ethers.getSigners()
    

    Each element of the accounts array is an instance of the ethers.js Wallet object.

    And Javascript casts any object (that doesn't override the toString() method) to string as [object Object].

    If you want to print an address of the wallet, you can use its address property:

    console.log(`Account: ${accounts[i].address}`)