When I tested on ganache-cli at local, I could test on 'truffle console development' with some accounts which ganache-cli gave. But at rinkeby, I can't use function_name(argumets, {from: specific rinkeby account})
form. Is it possible to set the specific account on 'truffle console rinkeby(and mainnet also)'? (Something like using web3.eth.
thing) If it is, how can I set that?
2 Answers
Since you are using HDWalletProvider it will only support accounts derived from the mnemonic. It doesn't know the private key required to sign messages from other addresses.
As alternative you pass to HDWalletProvider an array of private keys.
var privateKeys = [
"3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
"9549f39decea7b7504e15572b2c6a72766df0281cea22bd1a3bc87166b1ca290",
];
var provider = new HDWalletProvider(privateKeys, "http://localhost:8545", 0, 2); //start at address_index 0 and load both addresses
-
Oh it's cool. By the way, I wanted to know the possibility(and if it's possible, plus the method to do that) to set the other account when using truffle console at rinkeby/mainnet. So are you saying this is not possible? Commented Dec 22, 2018 at 15:51
-
1Truffle console uses the provider from the configuration file. With HDWalletProvider then you are limited to those address derived from the mnemonic.– Ismael ♦Commented Dec 22, 2018 at 20:49
Using HDWalletProvider you can also pass a single private key of the specific account that you want to use, instead of the mnemonic. Example:
//load single private key as string
let provider = new HDWalletProvider("3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580", "http://localhost:8545");
rinkeby: { provider: function() { return new HDWalletProvider(mnemonic, "https://rinkeby.infura.io/<my_endpoint>", 0); }, network_id: 4 }
. I deployed with the 'mnemonic' here, and I wanted to test on 'truffle console rinkeby' with other specific account. Is it impossible to do what I want? @Ismael