How to Quickly Deploy a CRC20 Token
Conflux provides a compatible EVM virtual machine so that the Ethereum contracts can be quickly deployed on the Conflux network. The Conflux's token standard CRC20 and CRC721 are also compatible with Ethereum's, meaning that an ERC20 contract that can be used directly to create a CRC20 Token on the Conflux network. This article will demonstrate how to quickly deploy a CRC20 contract on the Conflux testnet using conflux-truffle.
conflux-truffle is a contract development tool written in Node.js. We need to first install the Node.js environment on our computer: you can download and install it directly from the official website or use the Node version management tool nvm to install it.
Once Node.js is installed, you can install conflux-truffle using npm and run the cfxtruffle command in the terminal:
#Account Private Key
Since we are demonstrating the deployment of Token contracts on the test-net, we need to have an account private key with CFX in it. You can use Faucet to get the test CFX and export the private key.
#Creating a project
First, we need to create an empty project with cfxtruffle
Three folders and one file are created after the project is initialized:
contracts: Solidity contract folder
migrations: Contract deployment scripts folder
test: Test scripts folder
truffle-config.js: Project configuration file
The initial project comes with a
Migrations.sol contract and a deployment script
1_initial_migration.js for that contract, which is used to record the progress of the project's contract deployment.
#Configuring the project
truffle-config.js is the configuration file of the truffle project. You can use this to configure the project's network, solidity compiler, etc. In this case we will set the following configuration：
Note: users should fill their own private key in
#Adding a contract
Next, we need to add a contract file using cfxtruffle's create command.
After the command is executed, a Solidity contract file CDTE.sol will be created in the contracts directory. We can add the following contract code to the file：
The contract code can not be directly used for deployment and needs to be compiled into bytecode and abi using solc. cfxtruffle integrates with Solidity's compilation features:
After compilation, a new directory build will be created, which contains several json files, one for each contract. The json files contain various meta-information regarding the contract: name, abi, bytecode, compiler, etc.
In cfxtruffle, migration is used to manage the deployment of the contract. Each contract requires a migration script to be deployed. We cn also use create commend and create a migration:
Note: The migration script name created by the create command is prefixed with a time stamp such as 1620979361c_d_t_e.js, we need to manually change the prefix serial number of the script name. For example, change 1620979361_c_d_t_e.js to 2_CDTE migration.js. This is because the order of deployment is consistent with the prefix number of the migration script file name.
You can code the logic of contract's deployment in the Migration script usually by using artifacts to import the contract objects and deployit by using _deployer's deploy. If the contract constructor has parameters, they can also be set via the deploy method. In our example, for the token constructor we deployed, we need to set the parameter
Once the Migration script is written, you can run the
deploy command to deploy the contract.
The first deployment will deploy the
Migrations contract first, which is used to record the deployment progress of the project contract. We will deploy our written CRC20 contract
CDTE in the second step. The terminal will print out information about the deployment process, including：
- transaction hash: deployed transaction hash
- contract address:
- account: deployed account
- balance: deployed account balance
- cost(gas used, gas price, storage collateralized): Deployment cost of gas and storage collateral
The contract address output from the terminal is the contract address of the token.
#Interacting with the Wallet
Interacting with the Fluent Wallet
Note: before adding, you need to switch the network of the Fluent to