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:
# To use truffle locally in your project, you must init a package.json file$npminit# Install truffle and wallet-provider to your project$npmi-Dtruffle@truffle/hdwallet-provider# Generate truffle configuation file and default folders$npmexec--truffleinit
# To use truffle locally in your project, you must init a package.json file$yarninit# Install truffle and wallet-provider to your project$yarnadd--devtruffle@truffle/hdwallet-provider# Generate truffle configuation file and default folders$yarntruffleinit
You can install global Truffle to your environment:
$npmi-gtruffle
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:
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.
# Using NPMKEY=0xPrivateKeynpmexec--trufflemigrate--networkthunder-testnet--reset# or using YarnKEY=0xPrivateKeyyarntrufflemigrate--networkthunder-testnet--reset
# Using NPMsetKEY=0xPrivateKey&npmexec--trufflemigrate--networkthunder-testnet--reset# or using YarnsetKEY=0xPrivateKey&yarntrufflemigrate--networkthunder-testnet--reset
# Using NPM$env:KEY='0xPrivateKey';npmexec--trufflemigrate--networkthunder-testnet--reset# or using Yarn$env:KEY='0xPrivateKey';yarntrufflemigrate--networkthunder-testnet--reset
When it's done, should show messages like this:
Starting migrations...
======================
> Network name: 'thunder-testnet'
> Network id: 18
> Block gas limit: 100000000 (0x5f5e100)
1_initial_migration.js
======================
Deploying 'Migrations'
----------------------
...
...
...
> Saving migration to chain.
> Saving artifacts
-------------------------------------
> Total cost: 0.000266154 ETH
Summary
=======
> Total deployments: 1
> Final cost: 0.000266154 ETH
Congratulations! You have successfully deployed a smart contract onto the ThunderCore network.