Smart Contract Deployment on CSC Using Truffle
Have you ever tried to deploy your smart contracts on coinex smart chain using truffle? in this tutorial we want to install and configure truffle and deploy a smart contract on coinex smart chain testnet using truffle.
Truffle
A world class development environment, testing framework and asset pipeline for blockchains using the Ethereum Virtual Machine (EVM), aiming to make life as a developer easier. With Truffle, you get:
- Built-in smart contract compilation, linking, deployment and binary management.
- Automated contract testing for rapid development.
- Scriptable, extensible deployment & migrations framework.
- Network management for deploying to any number of public & private networks.
- Package management with EthPM & NPM, using the ERC190 standard.
- Interactive console for direct contract communication.
- Configurable build pipeline with support for tight integration.
- External script runner that executes scripts within a Truffle environment.
Installing Truffle
Before you can use Truffle, you will have to install it using npm. Open a terminal and use the following to install it globally.
npm install -g truffle
requirements
- node
latest
version - npm
latest
version
Project Setup
we can create a bare project template, but in this example we will use the MetaCoin box.
first of all we create a directory for our project. in terminal type:
mkdir coin
cd coin
- Download (“unbox”) the MetaCoin box:
truffle unbox metacoin
Note: You can use the truffle unbox <box-name>
command to download any of the other Truffle Boxes.
our truffle project structure is like this:
contracts/
: Directory for Solidity contractsmigrations/
: Directory for scriptable deployment filestest/
: Directory for test files for testing your application and contractstruffle.js
: Truffle configuration file
Note: you can check Truffle documentation for more details.
Testing
In a terminal, run the Solidity test:
truffle test ./test/TestMetaCoin.sol
You will see the following output:
TestMetacoin
√ testInitialBalanceUsingDeployedContract (71ms)
√ testInitialBalanceWithNewMetaCoin (59ms) 2 passing (794ms)
Run the JavaScript test:
truffle test ./test/metacoin.js
You will see the following output:
Contract: MetaCoin
√ should put 10000 MetaCoin in the first account
√ should call a function that depends on a linked library (40ms)
√ should send coin correctly (129ms) 3 passing (255ms)
Compiling
Compile the smart contracts:
truffle compile
You will see the following output:
Compiling .\contracts\ConvertLib.sol...
Compiling .\contracts\MetaCoin.sol...
Compiling .\contracts\Migrations.sol...Writing artifacts to .\build\contracts
Configuring Truffle
The default Truffle configuration without any bells and whistles looks like this:
module.exports = {
rpc: {
host: "127.0.0.1",
port: 8545
}
};
This tells Truffle that by default it should connect to a network client at host 127.0.0.1
and port 8545
To ensure Truffle knows the network you want to deploy to, we can add a specific configuration for the live network:
module.exports = {
networks: {
"csc": {
network_id: 53,
host: "https://testnet-rpc.coinex.net",
port: 8546
}
},
rpc: {
host: "127.0.0.1",
port: 8545
}
};
Deploying to CSC
not its time to deploy on csc network.To do so, we can deploy with the following command:
$ truffle migrate --network csc
Notice that we asked for the "csc"
network, which is the name we defined in the configuration
Congratulation 🥳
now we can deploy our smart contracts on csc easily!
New to trading? Try crypto trading bots or copy trading