ethereum wallet 通过合约发行代币试验

在上一篇文章里,我们已经完成了geth 私链的初始化,以及节点的对接同步。 

这一次,我们试验在Ethereum Wallet (Version 0.9.3) 里部署智能合约发行代币(Token) .



以下为代码,先复制到合约界面,Contracts  / Deploy New Contract ,   右边会提示让 输入代币的名称、符号、以及总数量, 我测试输入的内容为Vic Dollar , * , 8888888888. 大家随意

  

pragma solidity ^0.4.16;

interface tokenRecipient { function receiveApproval(address _from, uint256 _value, address _token, bytes _extraData) public; }

contract TokenERC20 {
    // Public variables of the token
    string public name;
    string public symbol;
    uint8 public decimals = 18;
    // 18 decimals is the strongly suggested default, avoid changing it
    uint256 public totalSupply;

    // This creates an array with all balances
    mapping (address => uint256) public balanceOf;
    mapping (address => mapping (address => uint256)) public allowance;

    // This generates a public event on the blockchain that will notify clients
    event Transfer(address indexed from, address indexed to, uint256 value);

    // This notifies clients about the amount burnt
    event Burn(address indexed from, uint256 value);

    /**
     * Constructor function
     *
     * Initializes contract with initial supply tokens to the creator of the contract
     */
    function TokenERC20(
        uint256 initialSupply,
        string tokenName,
        string tokenSymbol
    ) public {
        totalSupply = initialSupply * 10 ** uint256(decimals);  // Update total supply with the decimal amount
        balanceOf[msg.sender] = totalSupply;                // Give the creator all initial tokens
        name = tokenName;                                   // Set the name for display purposes
        symbol = tokenSymbol;                               // Set the symbol for display purposes
    }

    /**
     * Internal transfer, only can be called by this contract
     */
    function _transfer(address _from, address _to, uint _value) internal {
        // Prevent transfer to 0x0 address. Use burn() instead
        require(_to != 0x0);
        // Check if the sender has enough
        require(balanceOf[_from] >= _value);
        // Check for overflows
        require(balanceOf[_to] + _value > balanceOf[_to]);
        // Save this for an assertion in the future
        uint previousBalances = balanceOf[_from] + balanceOf[_to];
        // Subtract from the sender
        balanceOf[_from] -= _value;
        // Add the same to the recipient
        balanceOf[_to] += _value;
        Transfer(_from, _to, _value);
        // Asserts are used to use static analysis to find bugs in your code. They should never fail
        assert(balanceOf[_from] + balanceOf[_to] == previousBalances);
    }

    /**
     * Transfer tokens
     *
     * Send `_value` tokens to `_to` from your account
     *
     * @param _to The address of the recipient
     * @param _value the amount to send
     */
    function transfer(address _to, uint256 _value) public {
        _transfer(msg.sender, _to, _value);
    }

    /**
     * Transfer tokens from other address
     *
     * Send `_value` tokens to `_to` on behalf of `_from`
     *
     * @param _from The address of the sender
     * @param _to The address of the recipient
     * @param _value the amount to send
     */
    function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) {
        require(_value <= allowance[_from][msg.sender]);     // Check allowance
        allowance[_from][msg.sender] -= _value;
        _transfer(_from, _to, _value);
        return true;
    }

    /**
     * Set allowance for other address
     *
     * Allows `_spender` to spend no more than `_value` tokens on your behalf
     *
     * @param _spender The address authorized to spend
     * @param _value the max amount they can spend
     */
    function approve(address _spender, uint256 _value) public
        returns (bool success) {
        allowance[msg.sender][_spender] = _value;
        return true;
    }

    /**
     * Set allowance for other address and notify
     *
     * Allows `_spender` to spend no more than `_value` tokens on your behalf, and then ping the contract about it
     *
     * @param _spender The address authorized to spend
     * @param _value the max amount they can spend
     * @param _extraData some extra information to send to the approved contract
     */
    function approveAndCall(address _spender, uint256 _value, bytes _extraData)
        public
        returns (bool success) {
        tokenRecipient spender = tokenRecipient(_spender);
        if (approve(_spender, _value)) {
            spender.receiveApproval(msg.sender, _value, this, _extraData);
            return true;
        }
    }

    /**
     * Destroy tokens
     *
     * Remove `_value` tokens from the system irreversibly
     *
     * @param _value the amount of money to burn
     */
    function burn(uint256 _value) public returns (bool success) {
        require(balanceOf[msg.sender] >= _value);   // Check if the sender has enough
        balanceOf[msg.sender] -= _value;            // Subtract from the sender
        totalSupply -= _value;                      // Updates totalSupply
        Burn(msg.sender, _value);
        return true;
    }

    /**
     * Destroy tokens from other account
     *
     * Remove `_value` tokens from the system irreversibly on behalf of `_from`.
     *
     * @param _from the address of the sender
     * @param _value the amount of money to burn
     */
    function burnFrom(address _from, uint256 _value) public returns (bool success) {
        require(balanceOf[_from] >= _value);                // Check if the targeted balance is enough
        require(_value <= allowance[_from][msg.sender]);    // Check allowance
        balanceOf[_from] -= _value;                         // Subtract from the targeted balance
        allowance[_from][msg.sender] -= _value;             // Subtract from the sender's allowance
        totalSupply -= _value;                              // Update totalSupply
        Burn(_from, _value);
        return true;
    }
}

合约部署,需要矿工去完成确认工作,会消耗gas , 在测试系统里,我们可以把这个值设置到最大。

发送这个交易,是需要输入coinbase 对应帐户的密码。

之后就可以看到合约的执行情况。

合约执行完后,这些代币是属于创建人帐户的,我们可以任意转账给其它帐户。


这个确认工作会一直进行下去,矿工在干活。


这是交易的内容显示,  gas used 是发布者个交易的消耗。  BLOCK 是所在的区块。

点开这个合约,右边有4个操作选项, 分别是 转账,  复制地址, 显示二维码, 显示json接口定义。


这是转账的界面, to: 收款人的地址, 

Amount : 转账的金额 。

货币类型,选择我们刚定义的这个类型,(这里是Vic Dollar) .

Send everything 这个选项是会把余额全部都转给对方,一般我们不这样用。 (当然,如果是真爱,也可以的哈。)


当然,每次付款,都会提示要求输入coinbase对应密码的。

合约执行后,在链上任意一个节点都可以监听它, Watch Contract 


这里需要3个项目输入, 第一个是地址, 记得刚才查看合约时,第二个操作入口么? Copy Address

对,就是那个地址,把它通过QQ或者微信发给你的朋友,对方就可以监听这个合约了。

第二个参数是合约名称,这个可以自己随意定义,

第三个参数是合约的json接口定义,需要刚才查看界面的第四个入口获取,如下界面。


不出意外地话, 就可以在其它节点监听这个合约了。

在这个matrix里,可以做土豪,随意转给朋友你发行的货币了。

以太坊最大的魅力就在于此。  

坊间传言,因为DAPP在以太坊的部署效率太低,复杂的应用并不适合,但是发行代币还是很OK的。

也许EOS真能在TPS 这方面超越以太坊, 让我们拭目以待吧。 

再贴一遍我的测试节点服务器enode 

http://www.rmb1.net/host1.txt

上一篇部署测试链节点文章地址

https://mp.youkuaiyun.com/postedit/79619646

      我的微信 victorletian 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值