Setup

Pre-Requisites

The following tools need to be installed:

Globally Truffle Installation

1
npm install -g truffle
Copied!
You might be require to provide super user privileges to install it.

Project Setup

Navigate to the directory where you want to setup you project. For this guide we will be using "demo" as the project name.
1
truffle init demo
2
cd demo
Copied!

Installing Dependencies

1
npm install --save @harmony-js/core
2
npm install --save @harmony-js/utils
3
npm install --save tslib
4
npm install --save dotenv
Copied!
(Optional) Install Additional Dependencies if required. We wont be using this for this demo.
1
npm install openzeppelin-solidity -s
Copied!
Create a .env file in the project root directory and put your mnemonic code, private key, and rpc url in it. We will be using the following structure for our demo.
1
//LOCAL
2
LOCAL_PRIVATE_KEY=<YOUR_PRIVATE_KEY>
3
LOCAL_MNEMONIC=<YOUR_MNEMONIC_CODE>
4
LOCAL_0_URL='http://localhost:9500'
5
​
6
//TESTNET
7
TESTNET_PRIVATE_KEY=<YOUR_PRIVATE_KEY>
8
TESTNET_MNEMONIC=<YOUR_MNEMONIC_CODE>
9
TESTNET_0_URL='https://api.s0.b.hmny.io'
10
TESTNET_1_URL='https://api.s1.b.hmny.io'
11
​
12
//MAINNET
13
MAINNET_PRIVATE_KEY=<YOUR_PRIVATE_KEY>
14
MAINNET_MNEMONIC=<YOUR_MNEMONIC_CODE>
15
MAINNET_0_URL='https://api.s0.t.hmny.io'
16
​
17
GAS_LIMIT=3321900
18
GAS_PRICE=1000000000
Copied!

Configuring Truffle

In the project root directory, there is a file truffle-config.js and copy paste the following configuration.
1
require("dotenv").config();
2
const { TruffleProvider } = require("@harmony-js/core");
3
​
4
//Local
5
const local_mnemonic = process.env.LOCAL_MNEMONIC;
6
const local_private_key = process.env.LOCAL_PRIVATE_KEY;
7
const local_url = process.env.LOCAL_0_URL;
8
​
9
//Testnet
10
const testnet_mnemonic = process.env.TESTNET_MNEMONIC;
11
const testnet_private_key = process.env.TESTNET_PRIVATE_KEY;
12
const testnet_url = process.env.TESTNET_0_URL;
13
​
14
//Mainnet
15
const mainnet_mnemonic = process.env.MAINNET_MNEMONIC;
16
const mainnet_private_key = process.env.MAINNET_PRIVATE_KEY;
17
const mainnet_url = process.env.MAINNET_0_URL;
18
​
19
//GAS - Currently using same GAS accross all environments
20
gasLimit = process.env.GAS_LIMIT;
21
gasPrice = process.env.GAS_PRICE;
22
​
23
module.exports = {
24
networks: {
25
local: {
26
network_id: "2", // Any network (default: none)
27
provider: () => {
28
const truffleProvider = new TruffleProvider(
29
local_url,
30
{ memonic: local_mnemonic },
31
{ shardID: 0, chainId: 2 },
32
{ gasLimit: gasLimit, gasPrice: gasPrice }
33
);
34
const newAcc = truffleProvider.addByPrivateKey(local_private_key);
35
truffleProvider.setSigner(newAcc);
36
return truffleProvider;
37
},
38
},
39
testnet: {
40
network_id: "2", // Any network (default: none)
41
provider: () => {
42
const truffleProvider = new TruffleProvider(
43
testnet_url,
44
{ memonic: testnet_mnemonic },
45
{ shardID: 0, chainId: 2 },
46
{ gasLimit: gasLimit, gasPrice: gasPrice }
47
);
48
const newAcc = truffleProvider.addByPrivateKey(testnet_private_key);
49
truffleProvider.setSigner(newAcc);
50
return truffleProvider;
51
},
52
},
53
mainnet0: {
54
network_id: "1", // Any network (default: none)
55
provider: () => {
56
const truffleProvider = new TruffleProvider(
57
mainnet_url,
58
{ memonic: mainnet_mnemonic },
59
{ shardID: 0, chainId: 1 },
60
{ gasLimit: gasLimit, gasPrice: gasPrice }
61
);
62
const newAcc = truffleProvider.addByPrivateKey(mainnet_private_key);
63
truffleProvider.setSigner(newAcc);
64
return truffleProvider;
65
},
66
},
67
}
68
};
69
​
Copied!
Last modified 8mo ago