Using Truffle
Truffle is a development environment, testing framework and asset pipeline for Ethereum, aiming to make life as an Ethereum developer easier.

Adding Truffle to your project

You'll need Node.js v8+ installed before we get started. And you can choose a preferred package management tool to begin with:
npm
Yarn
1
# To use truffle locally in your project, you must init a package.json file
2
$ npm init
3
4
# Install truffle and wallet-provider to your project
5
$ npm i -D truffle @truffle/hdwallet-provider
6
7
# Generate truffle configuation file and default folders
8
$ npm exec -- truffle init
Copied!
1
# To use truffle locally in your project, you must init a package.json file
2
$ yarn init
3
4
# Install truffle and wallet-provider to your project
5
$ yarn add --dev truffle @truffle/hdwallet-provider
6
7
# Generate truffle configuation file and default folders
8
$ yarn truffle init
Copied!
You can install global Truffle to your environment:
1
$ npm i -g truffle
Copied!
Then, you can ignore npm exec -- or yarn commands before truffle

Setup Truffle config file

We are going to edit truffle-config.js. First, we uncomment this line to import @truffle/hdwallet-provider:
truffle-config.js
1
- // const HDWalletProvider = require('@truffle/hdwallet-provider');
2
+ const HDWalletProvider = require('@truffle/hdwallet-provider');
Copied!
Then, we add ThunderCore network settings into your project.
truffle-config.js
1
networks: {
2
+ "thunder-mainnet": {
3
+ provider: () => new HDWalletProvider([process.env.KEY], "https://mainnet-rpc.thundercore.com"),
4
+ network_id: "108",
5
+ gas: 90000000,
6
+ gasPrice: 1e9
7
+ },
8
+ "thunder-testnet": {
9
+ provider: () => new HDWalletProvider([process.env.KEY], "https://testnet-rpc.thundercore.com"),
10
+ network_id: "18",
11
+ gas: 90000000,
12
+ gasPrice: 1e9
13
+ }
14
}
Copied!
Never store your private key directly in truffle-config.js

Deploy a Contract

You'll need gas tokens to deploy contracts. To test on ThunderCore testnet, you can get testnet tokens from ThunderCore testnet Faucet
Now, we can deploy the Migrator contract in the template to ThunderCore testnet.
Unix-like system
Windows CMD
Windows Powershell
1
# Using NPM
2
KEY=0xPrivateKey npm exec -- truffle migrate --network thunder-testnet --reset
3
# or using Yarn
4
KEY=0xPrivateKey yarn truffle migrate --network thunder-testnet --reset
Copied!
1
# Using NPM
2
set KEY=0xPrivateKey & npm exec -- truffle migrate --network thunder-testnet --reset
3
# or using Yarn
4
set KEY=0xPrivateKey & yarn truffle migrate --network thunder-testnet --reset
Copied!
1
# Using NPM
2
$env:KEY='0xPrivateKey';npm exec -- truffle migrate --network thunder-testnet --reset
3
# or using Yarn
4
$env:KEY='0xPrivateKey';yarn truffle migrate --network thunder-testnet --reset
Copied!
When it's done, should show messages like this:
1
Starting migrations...
2
======================
3
> Network name: 'thunder-testnet'
4
> Network id: 18
5
> Block gas limit: 100000000 (0x5f5e100)
6
7
8
1_initial_migration.js
9
======================
10
11
Deploying 'Migrations'
12
----------------------
13
14
...
15
...
16
...
17
18
> Saving migration to chain.
19
> Saving artifacts
20
-------------------------------------
21
> Total cost: 0.000266154 ETH
22
23
24
Summary
25
=======
26
> Total deployments: 1
27
> Final cost: 0.000266154 ETH
Copied!
Congratulations! You have successfully deployed a smart contract onto the ThunderCore network.
You can check the deployment status at:
Copy link
Contents