Introduction
Conflux Studio is an integrated development environment (IDE) designed to streamline Conflux smart contract development. This tutorial will guide you through building a simple token application called Coin on the Oceanus network using Conflux Studio.
You’ll learn:
- Writing and calling Conflux smart contracts
- Configuring sponsored transactions (gas fee delegation)
- Interacting with smart contracts via a web frontend
Prerequisites
1. Install the IDE
Download Conflux Studio from its GitHub releases page. Supported platforms:
- macOS
- Linux
After installation, follow the setup wizard to install:
- Docker
- Conflux Node
- Conflux Truffle
2. Create a Wallet
Generate three key pairs:
minter_key: For contract deployment and common operations.receiver_key: For receiving token transfers.sponsor_key: For sponsoring transaction fees.
👉 How to export private keys securely
3. Connect to Conflux Network
Switch to the Oceanus testnet via:
Network → Oceanus 4. Get Test CFX
Request 100 CFX per address via:
- Built-in faucet button in Conflux Studio
- Direct link:
wallet.confluxscan.io/faucet/dev/ask?address={address}
Balances after faucet use:
| Key Pair | Balance |
|---------------|---------|
| minter_key | 100 CFX |
| receiver_key| 0 CFX |
| sponsor_key | 100 CFX |
Smart Contract Development
1. Create a Project
- Click Project → New.
- Name:
Coin. - Template:
coin.
2. Contract Code (Coin.sol)
Key features:
mint: Issue new tokens.send: Transfer tokens (emits aSentevent).balanceOf: Check token balances.- Sponsorship: Whitelist management via
add_privilege/remove_privilege.
pragma solidity >=0.5.0 <0.7.0;
import "./SponsorWhitelistControl.sol";
contract Coin {
address public minter;
mapping (address => uint) private balances;
event Sent(address from, address to, uint amount);
constructor() public { minter = msg.sender; }
function mint(address receiver, uint amount) public {
require(msg.sender == minter);
balances[receiver] += amount;
}
function send(address receiver, uint amount) public {
require(amount <= balances[msg.sender], "Insufficient balance.");
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Sent(msg.sender, receiver, amount);
}
function balanceOf(address tokenOwner) public view returns(uint balance) {
return balances[tokenOwner];
}
function add_privilege(address account) public payable {
address[] memory a = new address[](1);
a[0] = account;
SPONSOR.add_privilege(a);
}
} 3. Compile and Deploy
- Build: Click the Build button.
- Deploy: Select
minter_keyas the deployer. - Contract Address: Save as
contract_addr.
Interacting with the Contract
1. Mint Tokens
- Method:
mint Params:
receiver:minter_keyaddressamount: 1000
- Signer:
minter_key
2. Check Balances
- Method:
balanceOf - Params:
tokenOwner:minter_keyorreceiver_key
3. Transfer Tokens
- Method:
send Params:
receiver:receiver_keyamount: 200
- Signer:
minter_key
Sponsored Transactions
1. Set Up Sponsorship
- Contract:
0x0888000000000000000000000000000000000001(system contract). Methods:
set_sponsor_for_collateral: Sponsors storage fees.set_sponsor_for_gas: Sponsors gas fees.
| Parameter | Value |
|--------------------|---------------------|
| contract_addr | Coin contract address |
| Value | 40 CFX |
| Signer | sponsor_key |
2. Whitelist an Address
- Method:
add_privilege - Params:
account:minter_key
Frontend Integration
1. Prerequisites
- Install Conflux Portal (browser extension).
Clone the frontend repo:
git clone github.com/ObsidianLabs/conflux-frontend-react
2. Configure Environment
Update .env:
REACT_APP_CONFLUX_COIN_ADDRESS=contract_addr 3. Run the Project
yarn start FAQs
Q1: How do I reset my wallet in Conflux Studio?
A1: Navigate to Key Manager → Delete Key Pair.
Q2: What if my transaction fails?
A2: Check:
- Sufficient CFX balance.
- Correct network (Oceanus).
- Valid contract address.
Q3: Can I sponsor transactions for any contract?
A3: Yes, via the system contract’s add_privilege method.
Conclusion
This tutorial covered:
- Smart contract deployment.
- Token minting/transfers.
- Sponsored transactions.
- Frontend integration.
For advanced tasks, explore Conflux Bounty.