Truffle
Truffle is a world class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier.
This guide describes how to configure Truffle when you want to deploy your smart contracts on the IoTeX Network.
Let's assume that you already created a Truffle project and you want now use the truffle migrate command to deploy it on IoTeX. We will use https://babel-api.testnet.iotex.io as the Babel endpoint for IoTeX Testnet.

1. Install the hdwallet-provider package

1
npm install @truffle/hdwallet-provider --save
Copied!

2. Configure Truffle

You can configure Truffle accounts by using a mnemonic phrase or private keys.

2.1. Using Mnemonic phrase

Modify truffle-config.js as below:
1
const { MNEMONIC } = process.env;
2
const HDWalletProvider = require('@truffle/hdwallet-provider');
3
4
module.exports = {
5
networks: {
6
dev: {
7
provider: () =>
8
new HDWalletProvider({
9
mnemonic: {
10
phrase: MNEMONIC,
11
},
12
providerOrUrl: "https://babel-api.testnet.iotex.io",
13
shareNonce: true
14
}),
15
network_id: 4690, // IOTEX mainnet chain id 4689, testnet is 4690
16
gas: 8500000,
17
gasPrice: 1000000000000,
18
skipDryRun: true
19
}
20
}
21
}
Copied!
and deploy with:
1
MNEMONIC=`Your mnemonic` truffle migrate --reset --network dev
Copied!

2.2. Using private keys

Modify truffle-config.js as below:
1
const HDWalletProvider = require('@truffle/hdwallet-provider');
2
3
const privateKeys = [
4
"3f841bf589fdf83a521e55d51afddc34fa65351161eead24f064855fc29c9580",
5
"9549f39decea7b7504e15572b2c6a72766df0281cea22bd1a3bc87166b1ca290",
6
];
7
8
module.exports = {
9
networks: {
10
dev: {
11
provider: () => new HDWalletProvider(privateKeys, "https://babel-api.testnet.iotex.io", 0, 2),
12
network_id: 4690, // IOTEX mainnet chain id 4689, testnet is 4690
13
gas: 8500000,
14
gasPrice: 1000000000000,
15
skipDryRun: true
16
}
17
}
18
}
Copied!

Deploy

Finally, deploy your contracts with:
1
truffle migrate --reset --network dev
Copied!
Last modified 5mo ago