Mid and Final term discussion

Get account addresses when testing/migrating with truffle

Get account addresses when testing/migrating with truffle

by ANDREA BONGIORNO -
Number of replies: 1

Hi,

I am new to javascript and I hope this question is not too much stupid...

I am trying to test my contract with truffle+ganache and I am having a little problem: I don't know how to get the addresses of the accounts in Ganache.

In my migration script at some point I have:

...

var _seller = ... ;

deployer.deploy(VickreyAuction, _seller, ...other parameters...);

...

Now, I want to assign a particular address to _sender, chosen among the 10 default of Ganache. How can I get, let's say, the address of the second account?

In reply to ANDREA BONGIORNO

Re: Get account addresses when testing/migrating with truffle

by ANDREA LISI -

Do not worry, is not easy the first time to manage tools like truffle. It's a bit confusing:


Here, https://www.trufflesuite.com/docs/truffle/getting-started/running-migrations#available-accounts, you can find how to get the account list from your provider (Ganache in the example).

The exported function (module.exports, a NodeJs thingy) can accept up to three aruguments: deployer, network (the current target network) and accounts.
accounts is what you need, and it should be the array of addresses provided by Ganache (try to print it out) and you can access to the acocunt you wish with accounts[i].