Remix 是一个开源的 Solidity 智能合约开发环境,提供基本的编译、部署至本地或测试网络、执行合约等功能。Solidity 是 以太坊Ethereum 官方设计和支持的开发语言,专门用于编写智能合约。
本文希望将一个很简单的代币合约(只能发行和转账),部署在本地和测试网络上,测试下它的功能。
详细描述使用 Remix 的步骤及使用上可能碰到的问题。
之前开发过以太坊Ethereum智能合约,但没有记录过开发的过程和碰到的问题,觉得挺可惜。这次重新开始,从最基础开始,一步步学习。
开发环境
不需要安裝,直接在任何浏览器启动 Remix。

取得代币合约
代币合约的范例很多,Ethereum 官网有提供一个最小可执行的代币合约(MINIMUM VIABLE TOKEN):
pragma solidity ^0.4.0; contract MyToken { /* This creates an array with all balances */ mapping (address => uint256) public balanceOf; /* Initializes contract with initial supply tokens to the creator of the contract */ function MyToken(uint256 initialSupply) public { balanceOf[msg.sender] = initialSupply; // Give the creator all initial tokens } /* Send coins */ function transfer(address _to, uint256 _value) public { require(balanceOf[msg.sender] >= _value); // Check if the sender has enough require(balanceOf[_to] + _value >= balanceOf[_to]); // Check for overflows balanceOf[msg.sender] -= _value; // Subtract fr