求以太坊智能合约编写发布插件使用教程


#1

据了解,HPB采用的是ETH的虚拟机,ETH上的智能合约可以很平滑的过渡到HPB主网。
求那位大虾提供下以太坊智能合约编写和调试工具。


#2

可使用以太坊在线编译工具和metaMask钱包,完成发布token和交易

附:solidity常见问题查询:https://solidity-cn.readthedocs.io/zh/develop/frequently-asked-questions.html

环境准备:到官网下载metaMask https://metamask.io/ -------> 点击GET CHROME EXTENSION

0、打开metaMask 选择测试链,申请ETH测试币
1、打开:solidity在线编译工具:http://remix.ethereum.org

选择对应版本进行编译,编译成功如下图:

1552828884655

2、发布Token

1552829934539
点击 确认,查看钱包状态 如下:

1552829998303
image

合约地址如下:
1552830120869

3、使用token交易

添加代币
1552830231150
添加成功,发送交易
1552830280674
1552830385090
1552830419532

查看主账户下token数量:

1552830543596

结束:::发布token成功,交易成功

示例:DemoToken.sol

pragma solidity ^0.4.16;
contract Token{
    uint256 public totalSupply;

    function balanceOf(address _owner) public constant returns (uint256 balance);
    function transfer(address _to, uint256 _value) public returns (bool success);
    function transferFrom(address _from, address _to, uint256 _value) public returns
    (bool success);

    function approve(address _spender, uint256 _value) public returns (bool success);

    function allowance(address _owner, address _spender) public constant returns
    (uint256 remaining);

    event Transfer(address indexed _from, address indexed _to, uint256 _value);
    event Approval(address indexed _owner, address indexed _spender, uint256
    _value);
}

contract DemoToken is Token {

    string public name;                   //名称,例如"My test token"
    uint8 public decimals;               //返回token使用的小数点后几位。比如如果设置为3,就是支持0.001表示.
    string public symbol;               //token简称,like MTT

    function DemoToken(uint256 _initialAmount, string _tokenName, uint8 _decimalUnits, string _tokenSymbol) public {
        totalSupply = _initialAmount * 10 ** uint256(_decimalUnits);         // 设置初始总量
        balances[msg.sender] = totalSupply; // 初始token数量给予消息发送者,因为是构造函数,所以这里也是合约的创建者

        name = _tokenName;
        decimals = _decimalUnits;
        symbol = _tokenSymbol;
    }

    function transfer(address _to, uint256 _value) public returns (bool success) {
        //默认totalSupply 不会超过最大值 (2^256 - 1).
        //如果随着时间的推移将会有新的token生成,则可以用下面这句避免溢出的异常
        require(balances[msg.sender] >= _value && balances[_to] + _value > balances[_to]);
        require(_to != 0x0);
        balances[msg.sender] -= _value;//从消息发送者账户中减去token数量_value
        balances[_to] += _value;//往接收账户增加token数量_value
        Transfer(msg.sender, _to, _value);//触发转币交易事件
        return true;
    }


    function transferFrom(address _from, address _to, uint256 _value) public returns
    (bool success) {
        require(balances[_from] >= _value && allowed[_from][msg.sender] >= _value);
        balances[_to] += _value;//接收账户增加token数量_value
        balances[_from] -= _value; //支出账户_from减去token数量_value
        allowed[_from][msg.sender] -= _value;//消息发送者可以从账户_from中转出的数量减少_value
        Transfer(_from, _to, _value);//触发转币交易事件
        return true;
    }
    function balanceOf(address _owner) public constant returns (uint256 balance) {
        return balances[_owner];
    }


    function approve(address _spender, uint256 _value) public returns (bool success)
    {
        allowed[msg.sender][_spender] = _value;
        Approval(msg.sender, _spender, _value);
        return true;
    }

    function allowance(address _owner, address _spender) public constant returns (uint256 remaining) {
        return allowed[_owner][_spender];//允许_spender从_owner中转出的token数
    }
    mapping (address => uint256) balances;
    mapping (address => mapping (address => uint256)) allowed;
}