Introduction
This guide provides a detailed walkthrough for developers using Solidity to create smart contracts on ChainMaker. Solidity is an object-oriented, high-level programming language designed for implementing smart contracts that run on the Ethereum Virtual Machine (EVM).
Key features of Solidity include:
- Static typing
- Inheritance support
- Library integration
- Complex user-defined types
👉 Learn more about Solidity's architecture
4.1 Environment Setup
System Requirements
- Operating Systems: Compatible with Linux, macOS, and Windows
- Software Dependencies: None required
ChainMaker Preparation
Before development:
- Deploy ChainMaker network
- Install ChainMaker CMC tool for contract deployment
Required tutorials:
- [ChainMaker deployment guide]
- [CMC tool installation]
4.2 Solidity Smart Contract Development
4.2.1 Development Environment
Use Remix IDE for browser-based development. ChainMaker maintains full compatibility with Ethereum's Solidity implementation.
4.2.2 Coding Standards
Refer to official Solidity documentation for syntax and best practices.
Key Differences Between ChainMaker and Ethereum Solidity
| Aspect | ChainMaker | Ethereum |
|---|---|---|
| Native token support | Disabled | Enabled |
| Precompiled contracts | Limited support | Full support |
Built-in Interfaces
// ChainMaker specific implementations
block.coinbase // Returns validator address
block.difficulty // Always returns 0
msg.value // Always returns 0Precompiled Contracts
| Contract | Address | Status |
|---|---|---|
| ecrecover | 0x01 | Unsupported |
| bn256Add | 0x06 | Unsupported |
Cross-Contract Calls
ChainMaker supports additional virtual machine interoperability beyond standard EVM calls.
4.2.3 Example Contract: ERC20 Token
pragma solidity >0.5.11;
contract Token {
string public name = "token";
string public symbol = "TK";
uint256 public decimals = 6;
mapping (address => uint256) public balanceOf;
mapping (address => mapping (address => uint256)) public allowance;
constructor(address _addressFounder) {
// Initialization logic
}
function transfer(address _to, uint256 _value) public returns (bool) {
// Transfer implementation
}
}4.2.4 Contract Compilation
Using Docker
docker pull chainmakerofficial/chainmaker-solidity-contract:2.0.0
docker run -it -v $WORK_DIR:/home [IMAGE_ID] bashCompilation Command
solc --abi --bin --hashes --overwrite -o . token.solSimulation Testing
# Deployment simulation
evm Token.bin init_contract data [CONSTRUCTOR_ARGS]
# Method invocation
evm DeployedToken.bin [METHOD_SIGNATURE] data [CALLDATA]FAQ
Q: What Solidity versions are supported?
A: ChainMaker requires >=0.8.4 for optimal compatibility.
Q: Can I test contracts without deploying?
A: Yes, use the included EVM simulator for local testing.
Q: How are cross-contract calls different?
A: ChainMaker supports additional VM interoperability layers.