Alias the default Truffle or Ganache accounts with relatable names.
Truffle Personalities will alias n accounts, where n is the lesser of the number of accounts provided and the number of names available. The default list of names, in order of assignment, is as follows:
ALICEBOBCAROLDAVIDEVEFRANKGRACEHEIDIIVANJUDYKATHERINELIAMMICHAELNIAJOLIVIAPEGGYQUENTINRICHARDSYBILTRENTULYSSESVICTORWENDYXIMENAYAAKOVZARA
npm install --save truffle-personalitiesPass the accounts array provided to Truffle's contract function to Truffle Personalities.
const trufflePersonalities = require('truffle-personalities');
contract('TestContract', function (accounts) {
trufflePersonalities(accounts);
accounts.ALICE === accounts[0];
// => true
accounts.BOB === accounts[1];
// => true
});An options object may be passed as the second argument.
| Option | Description | Default |
|---|---|---|
context |
the object to which aliases are assigned | accounts |
names |
array of names to assign before using the default names | [] |
toLowerCase |
boolean describing whether to convert names to lower case rather than to upper case | false |
Pass a list of custom names to override the defaults. This example proposes the use of NOLAN as "nobody", or an uninvolved third party, and OWEN as a contract's owner.
trufflePersonalities(accounts, { names: ['NOLAN', 'owen'], toLowerCase: true});
accounts.NOLAN === undefined;
// => true
accounts.nolan === accounts[0];
// => true
accounts.owen === accounts[1];
// => true
accounts.alice === accounts[2];
// => truePass the global object as the context option in order to access the aliased addresses as standalone variables.
trufflePersonalities(accounts, { context: global });
accounts.ALICE === undefined;
// => true
ALICE === accounts[0];
// => true