I am working on the my contracts testing scripts. But I want to run tests not on the local TestRPC or Ganache but in the Ropsten testnet. How can I predefine a list of accounts (private keys and addresses)?
-
What node are you connecting to Ropsten with?– goodvibrationMar 9, 2020 at 9:42
-
@goodvibration basically I am working with Shasta and TRON now. There no such big community for TRON, so I asked here and want to port solution to the Tronbox+tronweb+Shasta stack.– Dmytro ZarezenkoMar 9, 2020 at 10:50
2 Answers
You can use truffle-hdwallet-provider
and provide it with mnemonic which has addresses funded with Ropsten Ethers.
var HDWalletProvider = require("truffle-hdwallet-provider");
var mnemonic = "mountains supernatural bird ...";
module.exports = {
networks: {
development: {
host: "localhost",
port: 8545,
network_id: "*" // Match any network id
},
ropsten: {
// must be a thunk, otherwise truffle commands may hang in CI
provider: () =>
new HDWalletProvider(mnemonic, "https://ropsten.infura.io/"),
network_id: '3',
}
}
};
-
Here is a real life example github.com/miohtama/viral-aave-save-game/blob/master/… Mar 9, 2020 at 10:25
You can use HDWalletProvider to connect to a provider (infura or your local node) using a mnemonic phrase. In case you are using truffle, you can do it by seting you config to something like this:
...
networks: {
kovan: {
provider: () => new HDWalletProvider(mnemonic, `https://kovan.infura.io/v3/${infuraKey}`),
network_id: 3, // Ropsten id
...
}
}
...
Attention that HDWalletProvider is deprecated. But I, personally, still use it often for testing environments.
-
It is not deprecated, it was renamed/moved to truffle's monorepo. The current package is at npmjs.com/package/@truffle/hdwallet-provider.– Ismael ♦Mar 9, 2020 at 13:54
-
1I know you are right .. it has been renamed. But this specific repo(github.com/trufflesuite/truffle-hdwallet-provider) is, citing, "deprecated". Mar 9, 2020 at 14:04
-
1The message says the "repo" is deprecated, that repo doesn't have the most recent version. It was moved inside truffle's monorepo github.com/trufflesuite/truffle/tree/develop/packages/…. If you follow npm instructions you should get the most recent version
npm install @truffle/hdwallet-provider
.– Ismael ♦Mar 9, 2020 at 14:08