Truffle
Last updated
Last updated
Overview
To help more developers deploy on Findora, this tutorial will guide you through the truffle box setting, and use Truffle to deploy contracts on independent Findora nodes.
This tutorial requires Node.js to be installed. You can download it through Node.js or run the following code to complete the installation. You can verify the correct installation by requesting the version of each installation package:
After you have fully installed Truffle, perform the following steps to create and run the Truffle project:
Create a new project folder and enter the project directory
2. Install truffle
and @truffle/hdwallet-provider
3. Create a new truffle project (to prevent the project from overwriting truffle, it is mandatory to use an empty folder)
It should generate the following directories and files:
4. Prepare .secret
with your mnemonic
or your private key
5. Uncomment the following lines in the begining of truffle-config.js
to enable the key
6.Configure Findora Anvil testnet under networks in truffle-config.js
:
Set solidity compilation version, optimization, plug-in and other information
7. Create contract
All your contracts should be located in the ./contracts
directory. By default, we provide a contract file and a library file, both ending with .sol
.
You can declare dependencies by using import. Truffle will compile contracts in the correct order and automatically associate libraries when needed.
8.Compile the contract
To compile your contract, use:
Truffle only compiles files that have been modified since the last compilation by default to reduce unnecessary compilation. If you want to compile all files, you can use the --compile-all
option.
The output of the compilation is located in the ./build/contracts
directory. If the directory does not exist, it will be created automatically. These compiled files are essential for the proper functioning of the Truffle framework. You should not manually modify these files outside of normal compilation or distribution. The file has the contract abi information you need. as the picture shows:
9. Create a deployment script file
Note that the file name starts with a number and ends with a descriptive suffix. The number prefix is required. The migrate command will be executed in ascending order according to the files beginning with the number in the migrate directory. The suffix is only to improve readability and facilitate understanding. as the picture shows:
10. Deploy the Contract
To perform deployment, use the following command:
This command will execute all migration scripts located in the migrations directory. If your previous migration was performed successfully, truffle migrate
will only perform newly created migrations. If there is no new migration script, this command does not perform any operation. You can use the option --reset
to execute the migration script from the beginning.
You can also use the following command to start execution from the file with the number prefix 2.
Congratulations, you have completed the basic truffle operation guide!
Here is an example: https://github.com/FindoraNetwork/frc20-demo