ChainIDE-English
  • 1. ChainIDE Introduction
  • 2. ChainIDE Modules
    • 2.1. File System
    • 2.2. Editor
    • 2.3. File Preview
    • 2.4. Logger
    • 2.5. Compile
    • 2.6. Deployment and Interaction
    • 2.7. Plug-in System Module
      • 2.7.1 ChainIDE Debugger
      • 2.7.2. ChainIDE Flattener Plugin
      • 2.7.3. ChainIDE Scan Verifier
    • 2.8. Functions at Bottom Part of ChainIDE
  • 3. ChainIDE - Loading Your Work
  • 4. ChainIDE - Saving Your Work
  • 5. ChainIDE - Port Forwarding
  • ChainIDE
    • 1. Ethereum IDE
      • 1. Ethereum IDE Environment Configuration
      • 2. How to Use Ethereum IDE?
      • 3. Using Hardhat
      • 4. Using Ganache v7
      • 5. Using Truffle
    • 2. BNB Chain IDE
      • 1. BNB Chain IDE Environment Configuration
      • 2. How to Use BNB Chain IDE
      • 3. Using Hardhat
      • 4. Using Ganache v7
      • 5. Using Truffle
    • 3. Conflux IDE
      • 1. Conflux IDE Environment Configuration
      • 2. How to Use Conflux IDE
      • 3. Using Hardhat
      • 4. Using Ganache v7
      • 5. Using Truffle
      • 5. Using Conflux-Truffle
    • 4. Internet Computer IDE
      • 1. How to Use Internet Computer IDE
    • 5. Nervos IDE
      • 1. Nervos IDE Environment Configuration
      • 2. How to use Nervos IDE
      • 3. Using Hardhat
      • 4. Using Ganache v7
    • 6. Polygon IDE
      • 1. Polygon IDE Environment Configuration
      • 2. How to use Polygon IDE
      • 3. Using Hardhat
      • 4. Using Ganache v7
      • 5. Using Truffle
    • 7. Flow IDE
      • Learn how to use Flow IDE to develop dApps
    • 8. FISCO BCOS IDE
      • 1. FISCO BCOS Environment Configuration
      • 2. How to use FISCO BCOS IDE
    • 9. Sui IDE
      • 1. Sui Environment Configuration
      • 2. How to use Sui IDE
    • 10. Aptos IDE
      • 1. Aptos IDE Usage Process
      • 2. How to use Aptos IDE
    • 11. XDC IDE
      • 1. XDC IDE Environment Configuration
      • 2. How to Use XDC IDE
      • 3. Using Hardhat
      • 4. Using Ganache v7
      • 5. Using Truffle
    • 12. Astar IDE
      • 1. Astar Environment Configuration
      • 2. How to Use Astar EVM IDE
      • 3. How to Use Astar WASM IDE
    • 13. IRISnet IDE
      • 1. IRISnet Environment Configuration
      • 2. How to Use IRISnet EVM IDE
      • 3. How to Use IRISnet Native IDE
    • 14. Arbitrum IDE
      • 1. Arbitrum IDE Environment Configuration
      • 2. How to Use Arbitrum IDE
      • 3. Using Hardhat
      • 4. Using Ganache v7
      • 5. Using Truffle
    • 15. Starknet IDE
      • 1. Starknet IDE Environment Configuration
      • 2. How to Use Starknet IDE
    • 16. Mina IDE
      • 1. Mina IDE Environment Configuration
      • 2. How to Use Mina IDE
Powered by GitBook
On this page
  • 1. Open Sandbox
  • 2. Create a project
  • 3. Compile contract
  • 4. Deploy to remote node
  • 5. deploy contract
  • 6. interact with contract
  • 7. Contract testing
  • 8. Truffle commands not supported now
  • 9. Conclude

Was this helpful?

  1. ChainIDE
  2. 3. Conflux IDE

5. Using Conflux-Truffle

Use Conflux-Truffle to quickly build a dApp on Conflux Core

Previous5. Using TruffleNext4. Internet Computer IDE

Last updated 1 year ago

Was this helpful?

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

$ cfxtruffle init 
$ mkdir MetaCoin
$ cd MetaCoin
$ cfxtruffle unbox metacoin

A cfxtruffle project will include these folders:

  • build contract compiled stuff(json)

  • contracts solidity code

  • migrations migration scripts

  • test testing file

  • truffle-config.js config file

create new contracts, tests, migrations

cfxtruffle create Helper to create new contracts, migrations and tests

$ cfxtruffle create contract MetaCoin
$ cfxtruffle create migration MetaCoin
$ cfxtruffle create test MetaCoin

3. Compile contract

$ cfxtruffle compile

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.

development: {
    host: "test.confluxrpc.com",
    port: 80,
    network_id: "*",
    type: "conflux",
    // the magic field
    privateKeys: ["keys1xxxxxx", "keys1xxxxxx"],   // you can also directly set one key here: privateKeys: "one key"
},

5. deploy contract

$ cfxtruffle deploy # or cfxtruffle migrate

deploy is a alias to migrate, truffle use migration command run contract deploy and migrate.

  1. Every script in migration folder define a migrate task, if you add a new contract you should add a new migration scripts.

  2. 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)

  3. When cfxtruffle deploy run it will get the last deployed number from chain, will only run new added migration tasks.

6. interact with contract

cfxtruffle also provide a command that enable us interact with a contract convenient.

$ cfxtruffle console  # run console in your project root, it will open a interactive console
# initiate a contract instanse
cfxtruffle(develop)> let instance = await MetaCoin.deployed()
cfxtruffle(develop)> instance
# invoke contract state query method
cfxtruffle(develop)> let balance = await instance.getBalance(accounts[0])
cfxtruffle(develop)> balance.toNumber()
# invoke contract state change method
cfxtruffle(develop)> let result = await instance.sendCoin(accounts[1], 10, {from: accounts[0]})
cfxtruffle(develop)> result
# most truffle commands also available here
cfxtruffle(develop)> compile
cfxtruffle(develop)> networks
# You can also access to `js-conflux-sdk`'s cfx, cfxutil
cfxtruffle(develop)> let balance = await cfx.getBalance("0x-one-address")
cfxtruffle(develop)> cfxutil.unit.fromCFXToDrip(123)

7. Contract testing

Truffle comes standard with an automated testing framework (built onto mocha and chai)

Unit test code examples

const MetaCoin = artifacts.require("MetaCoin");

contract('MetaCoin', (accounts) => {
  it('should put 10000 MetaCoin in the first account', async () => {
    const metaCoinInstance = await MetaCoin.deployed();
    const balance = await metaCoinInstance.getBalance.call(accounts[0]);

    assert.equal(balance.valueOf(), 10000, "10000 wasn't in the first account");
  });
}

run tests

$ cfxtruffle test

8. Truffle commands not supported now

  • develop

  • build

9. Conclude

create project from templates --

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

cfxtruffle deploy also provide three paramter (--reset, --from, --to) which can control the migration running rule. For detail explanation check

For detail documentation check truffle and . And for the documentation of js-conflux-sdk find it

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 .

box
here
here
console
interact with contract
here
conflux-truffle github repo