Smart Contract Development with Solidity: A Comprehensive Guide

·

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:

👉 Learn more about Solidity's architecture

4.1 Environment Setup

System Requirements

ChainMaker Preparation

Before development:

  1. Deploy ChainMaker network
  2. Install ChainMaker CMC tool for contract deployment

Required tutorials:

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

AspectChainMakerEthereum
Native token supportDisabledEnabled
Precompiled contractsLimited supportFull support
Built-in Interfaces
// ChainMaker specific implementations
block.coinbase // Returns validator address 
block.difficulty // Always returns 0
msg.value // Always returns 0
Precompiled Contracts
ContractAddressStatus
ecrecover0x01Unsupported
bn256Add0x06Unsupported
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] bash

Compilation Command

solc --abi --bin --hashes --overwrite -o . token.sol

Simulation 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.

👉 Explore advanced contract patterns