如何在以太坊上面发行自己的代币

如何在以太坊上面发行自己的代币-区块链观察

2017年以太坊为何疯涨了100倍,一个很重要的因素就是ICO,而ICO重要的一环,发行自己的代币(Token),在以太坊上面发行,变的非常简单。

在2012年~2014年,很多山寨币,比如LTC,PPC,NMC,NVC这些,都是需要自己修改bitcoin的源码编译,改改参数和共识算法,另外最重要的是,还需要有很多矿工(Miner)在你这个链上面挖矿,

到了2016年~2017年,你发行山寨币,只需要在以太坊的钱包里面COPY & PASTE,就可以创造出你自己独一无二的币,而且,最最重要的是,不需要挖矿。2017年疯狂的ICO都是基于这个,据统计,在以太坊上面发行的代币已经有12000多种,其中99%都是垃圾,下面就给大家讲讲如何创造这个“垃圾”

一· 首先区以太坊的官方Github地址上面下载最新的钱包

https://github.com/ethereum

https://github.com/ethereum/mist/releases  钱包下载地址,目前最新版本是0.9.3,根据不同的操作系统下载不同文件,这里用mac版本作为实例

https://github.com/ethereum/mist/releases/download/v0.9.3/Ethereum-Wallet-macosx-0-9-3.dmg

二· 安装启动,首先需要创建账户,输入账户密码,接下来,选择测试网络(为什么用选测试网络,因为同步主网络需要很长的时间),同步完成后,将进入钱包主界面

三· 充ETH到账户

新用户看到的 应该是 0.00 ether,账户里面是没钱的,没钱是无法创建代币的,所以首先要充ETH,当然,我不是要大家去真的买ETH充进来

我们目前使用的是Rinkeby测试网络,具体查看自己使用的什么测试网络可以参考下图,以前版本测试网络是自己可以挖ETH币的,但是被某些人乱用,导致网络拥堵

现在的Rinkeby测试网络发布改成了申请获取

去申请地址  https://faucet.rinkeby.io/

按照上面的步骤,选择在Tweet,Google+,Faceboook发一条推文,内容写自己的账户地址,比如上面我的账户0xb3a8dA95ECb4f0EBb10989C3B72dd8f2b37Ef786

发完推文之后,将推文地址url 粘贴到申请地址的输入框,选择申请数目,稍等片刻,再刷新账户,就可以看到余额了

如果你是土豪完全可以用正式网络来测试,大概花500块,买0.1个ETH,就可以测试了:)

四· 创建合约(Contracts)

点击钱包右上角的CONTRACTS,然后点击 DEPLOY NEW CONTRACT

在输入框里面复制粘贴下面的代码, 参考 https://www.ethereum.org/token ,这里有完整创建代币的代码,90%的代币都是拿这个代码原封不动的粘贴

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
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);
    /**
     * Constrctor 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` in 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 in 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 in 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;
    }
}

输入完成后,接着,选择要发布的合约名称,输入Token名称,Token总量,Token符号简称(TokenERC20合约的构造函数的三个参数),这里我创建了一个叫 BTH Token的代币,总量是2100万,和比特币数目一样:)

符号是BTH,你可以按照自己喜好改成自己的名称和数量

接下来,选择费用,以太坊上面创建任何合约都是需要费用的,合约越大越复杂,需要的费用越高,这里我们选择0.007 ETH 的Fee

点击 发布(Deploy),输入自己的账户密码,然后等待10几秒,我们的代币就创建成功了

等待12个确认后,我们的BTH代币就正式创建成功了,接下来看看我的账户,2100万的BTH已经在我账户里面的,是不是有种发财的感觉:)

后记,作为混IT圈的程序员,如果你早点下载钱包,看到以太坊的程序做的如此漂亮,简洁,功能强大,就应该相信以太坊一定可以成功(创建代币只是智能合约的一小部分,后面有机会再研究写合约的其他功能)

就应该在ETH在2017年初只有50元的时候买进,说起来都是一把眼泪啊

发表评论

坐等沙发
相关文章
BEC代币被黑,黑客输入一串数字就套利千万,说好的安全呢?
BEC代币被黑,黑客输入一串数字就套利千…
区块链和代币入门:为什么要使用区块链而非数据库?
区块链和代币入门:为什么要使用区块链…
区块链海外”监管套利”观察:”无币化”和ICO乱象
区块链海外”监管套利”观察…
与以太坊概念相似的加密货币有哪些?
与以太坊概念相似的加密货币有哪些?
EOS与以太坊有什么不同?
EOS与以太坊有什么不同?
区块链创新平台:以太坊的直接竞争对手EOS
区块链创新平台:以太坊的直接竞争对手E…