0

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
  • You can specify the from in the truffle.js configuration file, or in each function call. How do you connect to rinkeby?
    – Ismael
    Commented Dec 22, 2018 at 5:41
  • I did like this. 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
    – Jung Chun
    Commented Dec 22, 2018 at 7:27

2 Answers 2

1

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
2
  • 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?
    – Jung Chun
    Commented Dec 22, 2018 at 15:51
  • 1
    Truffle 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
0

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");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.