5. Using Conflux-Truffle
Use Conflux-Truffle to quickly build a dApp on Conflux Core
This tutorial is suitable for Conflux Core.
1. Open Sandbox
Note: Sandbox functionality is only available after logging in to ChainIDE via GitHub.
Open Sandbox
2. Create a project
create project
create a empty project
create project from templates -- box
A cfxtruffle project will include these folders:
build
contract compiled stuff(json)contracts
solidity codemigrations
migration scriptstest
testing filetruffle-config.js
config file
create new contracts, tests, migrations
cfxtruffle create
Helper to create new contracts, migrations and tests
The create command will create files in contracts
, migrations
, test
folder. Notice the automated created migration file's name will include timestamp, you need manual change to the correct sequal number. For detail reason check here
3. Compile contract
All compiled stuff saved at build
folder.
4. Deploy to remote node
cfxtruffle now support deploy contract to a remote node, the only work to do is set the privateKeys
in truffle-config.
5. deploy contract
deploy
is a alias to migrate
, truffle use migration
command run contract deploy and migrate.
Every script in migration folder define a migrate task, if you add a new contract you should add a new migration scripts.
Every truffle project will have a contract called
Migration
which used to save the project's last migration number, this contract have two method:last_completed_migration()
,setCompleted(num)
When cfxtruffle deploy run it will get the last deployed number from chain, will only run new added migration tasks.
cfxtruffle deploy
also provide three paramter (--reset, --from, --to) which can control the migration running rule. For detail explanation check here
6. interact with contract
cfxtruffle also provide a command that enable us interact with a contract convenient.
For detail documentation check truffle console and interact with contract. And for the documentation of js-conflux-sdk
find it here
7. Contract testing
Truffle comes standard with an automated testing framework (built onto mocha and chai)
Unit test code examples
run tests
8. Truffle commands not supported now
develop
build
9. Conclude
This quickstart showed you the basics of the Truffle project lifecycle, but there is much more to learn. Please continue on with the rest of conflux-truffle github repo.
Last updated