4. Use Truffle to Deploy Smart Contract
Truffle is available for conflux eSpace, please note!
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.
Starting from ChainIDE 2.1 version, the Terminal function is supported. You can use the test compilation and deployment functions of the truffle framework. At the same time, it provides ganache-cli as a virtual environment to start.
The purpose of this tutorial is to teach how to use truffle in chainIDE. As for a detailed tutorial, please read truffle documentation
Click "Logger" in the lower right corner, then click the "Terminal" in the middle, nice, you can see Terminal now!

8. Open the Terminal
To use most Truffle commands, you need to run them against an existing Truffle project. So the first step is to create a Truffle project.
You can create a bare project template, but for those just getting started, you can use Truffle Boxes, which are example applications and project templates. We'll use the MetaCoin box, which creates a token that can be transferred between accounts:
- 1.Create a new directory for your Truffle project:mkdir MetaCoincd MetaCoin
- 2.Download ("unbox") the MetaCoin box:truffle unbox metacoinNote: You can use the
truffle unbox <box-name>
command to download any of the other Truffle Boxes.Note: To create a bare Truffle project with no smart contracts included, usetruffle init
.
Once this operation is completed, you'll now have a project structure with the following items:
contracts/
: Directory for Solidity contractsmigrations/
: Directory for scriptable deployment filestest/
: Directory for test files for testing your application and contracts- truffle-config.js: Truffle configuration file
- 1.On a terminal, run the Solidity test:truffle test ./test/TestMetaCoin.solYou will see the following outputTestMetacoin√ testInitialBalanceUsingDeployedContract (71ms)√ testInitialBalanceWithNewMetaCoin (59ms)2 passing (794ms)Note: If you're on Windows and encountering problems running this command, please see the documentation on resolving naming conflicts on Windows.These two tests were run against the contract, with descriptions displayed of what the tests are supposed to do.
- 2.Run the JavaScript test:truffle test ./test/metacoin.jsYou will see the following outputContract: 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)
- 1.Compile the smart contracts:truffle compileYou will see the following output:Compiling .\contracts\ConvertLib.sol...Compiling .\contracts\MetaCoin.sol...Compiling .\contracts\Migrations.sol...Writing artifacts to .\build\contracts
To deploy our smart contracts, we're going to need to connect to a blockchain. Truffle has a built-in personal blockchain that can be used for testing. This blockchain is local to your system and does not interact with the main Ethereum network.
- 1.Run Truffle Develop:truffle developThis shows ten accounts (and their private keys) that can be used when interacting with the blockchain.
- 2.On the Truffle Develop prompt, Truffle commands can be run by omitting the
truffle
prefix. For example, to runtruffle compile
on the prompt, typecompile
. The command to deploy your compiled contracts to the blockchain istruffle migrate
, so at the prompt, type:migrateYou will see the following output:This shows the transaction IDs and addresses of your deployed contracts. It also includes a cost summary and real-time status updates.Note: Your transaction hashes, contract addresses, and accounts will be different from the above.
Note: To see how to interact with the contract, please skip to the next section.
Last modified 1yr ago