Ethereum and Solidity


web3j web3.js

Introduction to Smart Contracts

Solidity 是 Ethereum 上智能合约实现的主要语言之一。 运行在 EVM 上。

Blockchain Basics

Installing the Solidity Compiler

Solidity by Example

Solidity in Depth

Security Considerations

Using the compiler

Contract Metadata

Application Binary Interface Specification

Joyfully Universal Language for (Inline) Assembly

Style Guide

Common Patterns

List of Known Bugs


Frequently Asked Questions


Gloabal variable

Ether Units

Time Units


Error Handling

Mathematical and Cryptographic Functions

Doxity: Documentation Generator for Solidity.

All identifiers (contract names, function names and variable names) are restricted to the ASCII character set. It is possible to store UTF-8 encoded data in string variables.

How to develop and debug?



pragma solidity ^0.4.23;

interface ERC20 {
    function totalSupply() external view returns (uint supply);
    function balanceOf(address _owner) external view returns (uint balance);
    function transfer(address _to, uint _value) external returns (bool success);
    function transferFrom(address _from, address _to, uint _value) external returns (bool success);
    function approve(address _spender, uint _value) external returns (bool success);
    function allowance(address _owner, address _spender) external view returns (uint remaining);
    function decimals() external view returns(uint digits);
    event Approval(address indexed _owner, address indexed _spender, uint _value);
import java.util.HashMap;
import java.util.Map;

public class ERC20Coin {

    static class Address {
        private String val;
        private static final String PATTERN_ERC20_HASH = "0x[0-9A-Fa-f]{64}";

        public Address(String val) {
            assert (val.matches(PATTERN_ERC20_HASH));
            this.val = val;

        public String toString() {
            return this.val;

        public boolean equals(Object obj) {
            return (obj instanceof Address)
                    && ((Address) obj).val.equals(this.val);

    static class TransferEvent{
        public TransferEvent(Address _from, Address _to, Integer _value){


    Address sender;

    String name;
    String symbol;
    long totalSupply;
    Integer demicals;

    Map<Address, Integer> balances;
    Map<Address, Map<Address, Integer>> allowances;

    public ERC20Coin(String name, String symbol, long totalSupply, Integer demicals){
        balances = new HashMap<>();
        allowances = new HashMap<>(); = name;
        this.symbol = symbol;
        this.totalSupply = totalSupply;
        this.demicals = demicals;

    public Integer balanceOf(Address address) {
        return balances.get(address);

    public void transfer(Address from, Address to, Integer val) {
        Integer balanceFrom = balances.getOrDefault(from, 0);
        Integer balanceTo = balances.getOrDefault(to, 0);

        Map<Address, Integer> allowance;
            allowance = new HashMap<Address, Integer>();
            allowance = allowances.get(from);
        Integer allowed = allowance.get(sender);
        assert  (allowance.get(sender) >= val) &&
                (balanceFrom >= val);

        if(allowed < Integer.MAX_VALUE){
            allowance.put(sender, allowed - val);
            allowances.put(from, allowance);

        balances.put(from, balanceFrom - val);
        balances.put(to, balanceTo + val);

    public void approve(Address from, Address to, Integer val){
        Map<Address, Integer> allowance;
            allowance = new HashMap<Address, Integer>();
            allowance = allowances.get(from);

        allowance.put(to, val);
        allowances.put(from, allowance);


Airdrop 空投



空投之前需要找到你需要空投地址列表。 如何找到这些地址列表呢?

  1. 在 Slack 或者 telegram 等群里寻找鱼儿。
  2. 扫描 Ethereum 上 balance >0 的那些有效账号地址
parity export state --chain=ropsten -no-storage -no-code -min-balance=1000 -max-balance=500000 -at=2000000 balances.json

节省 gas 费用

如何一次向多个账号send token?