Using Truffle
1. Install truffle (preferably v5.3.0+, sometimes with v5.1.33, @truffle/hdwallet-provider does not work)
1
npm install -g truffle
Copied!
2. Create a metacoin project, unbox metacoin truffle box, and install @truffle/hdwallet-provider
1
mkdir metacoin
2
truffle unbox metacoin
3
npm install --save-dev @truffle/hdwallet-provider
Copied!
3. Modify truffle-config.js to add Harmony networks. Make sure to add your mnemonic or private key.
1
const HDWalletProvider = require('@truffle/hdwallet-provider');
2
const mnemonic = '<ADD-YOUR-MNEMONIC-HERE>';
3
const privateKeyTest = '<ADD-YOUR-PRIVATE-KEY-HERE>';
4
5
module.exports = {
6
networks: {
7
testnet: {
8
provider: () => {
9
return new HDWalletProvider({
10
mnemonic,
11
providerOrUrl: 'https://api.s0.b.hmny.io', // https://api.s0.t.hmny.io for mainnet
12
derivationPath: `m/44'/1023'/0'/0/`
13
});
14
},
15
network_id: 1666700000, // 1666600000 for mainnet
16
},
17
testnetHar: {
18
provider: () => {
19
if (!privateKeyTest.trim()) {
20
throw new Error(
21
'Please enter a private key with funds, you can use the default one'
22
);
23
}
24
return new HDWalletProvider({
25
privateKeys: [privateKeyTest],
26
providerOrUrl: 'https://api.s0.b.hmny.io',
27
});
28
},
29
network_id: 1666700000,
30
},
31
},
32
};
Copied!
4. Compile and deploy
1
truffle compile
2
truffle deploy --network testnet
Copied!
Last modified 7mo ago
Export as PDF
Copy link