基于ETH创建自己的代币

发行ETH代币

首先参考该文章 https://ethfans.org/topics/118, 且根据实际操作分享一下
当然首先要同步完区块,然后准备一点ETH(我是准备了0.02个,创建代币手续费+测试转账)。
文章中的:
基于ETH创建自己的代币_第1张图片
这个部分所提供的代码已经不再试用,经过调整最后的代码为:

/*
This creates a public tradeable fungible token in the Ethereum Blockchain.
https://github.com/ethereum/wiki/wiki/Standardized_Contract_APIs

Unmodified this will create a cryptoasset with a fixed market cap
wholly owned by the contract creator. You can create any function
to change this contract, like allowing specific rules for the issuance,
destruction and freezing of any assets. This contract is intended for
educational purposes, you are fully responsible for compliance with
present or future regulations of finance, communications and the
universal rights of digital beings.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to 

*/
pragma solidity ^0.4.21;
contract MyToken {
    
    /* Public variables of the token */
    string public name;
    string public symbol;
    uint8 public decimals;

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

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

    /* Initializes contract with initial supply tokens to the creator of the contract */
    function MyToken(uint256 _supply, string _name, string _symbol, uint8 _decimals) public{
        /* if supply not given then generate 1 million of the smallest unit of the token */
        if (_supply == 0) _supply = 1000000;

        /* Unless you add other functions these variables will never change */
        balanceOf[msg.sender] = _supply;
        name = _name;
        symbol = _symbol;

        /* If you want a divisible token then add the amount of decimals the base unit has  */
        decimals = _decimals;
    }

    /* Send coins */
    function transfer(address _to, uint256 _value) public{
        /* if the sender doenst have enough balance then stop */
        if (balanceOf[msg.sender] < _value) require(balanceOf[msg.sender] < _value);
        if (balanceOf[_to] + _value < balanceOf[_to]) require(balanceOf[msg.sender] < _value);

        /* Add and subtract new balances */
        balanceOf[msg.sender] -= _value;
        balanceOf[_to] += _value;

        /* Notifiy anyone listening that this transfer took place */
        emit Transfer(msg.sender, _to, _value);
    }
}

然后这个位置:
基于ETH创建自己的代币_第2张图片
不知道是不是币名相同的原因(没有测试),反正最好是一个没有出现过的代币名称否则会失败,已经有确认的但是查不到这个币,也没法转账,并且手续费建议控制在0.01左右个,不要太少了。
基于ETH创建自己的代币_第3张图片
这个输入的密码是你创建第一个地址(Main地址)的时候输入的密码
基于ETH创建自己的代币_第4张图片
下面的这个操作没有进行,自动就会生成出来,版本是0-10-0的Ethereum
基于ETH创建自己的代币_第5张图片
然后就是一个弥天大坑,就是说在输入精度的那个地方,如果你输入的是8,那么你要发的一个币就应该是1后面8个0,这样才是一个币,我就比较惨了以为填多少就是多少币结果就发0.1个币…,其实不是的根据你的精度要在实际发币的后面加上这个精度的数量,然后测试了发送之类的没有问题。
基于ETH创建自己的代币_第6张图片
基于ETH创建自己的代币_第7张图片
然后我用了在上一篇博客中写的方法去扫代币 https://blog.csdn.net/Day_Day_No_Bug/article/details/90698141
也没有任何问题,成功的扫到了自己发行的代币
在这里插入图片描述
但是不要忘记了改扫块的合约地址,在上面博客中有提到如何改,本篇结束。

你可能感兴趣的:(区块链,ETH,代币)