fgfgil520 发表于 2012-6-10 11:14:30

手把手教你发行自己的以太坊ERC20 Token

一、安装环境1、在chrome浏览器安装MetaMask插件安装完成后,你会看到chrome右上角有一个新的图标。https://upload-images.jianshu.io/upload_images/5392502-e38be445248b2a01.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

安装MetaMask插件

2、新建钱包输入密码,保存助记词3、使用测试网络由于使用以太坊主网络发布智能合约需要真正的ETH,在这里我使用的是测试网络(如果要在主网络发布一个Token,只需要选择主网络)切换到测试网络https://upload-images.jianshu.io/upload_images/5392502-f134007decb86f25.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/362



4、领取测试用的ETH点击“Buy”https://upload-images.jianshu.io/upload_images/5392502-11c758cea7e5cd78.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/360

MetaMask插件

点击"ROPSTEN TEST FAUCET"https://upload-images.jianshu.io/upload_images/5392502-7cfec2f68dc360ad.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/358

MetaMask插件

点击绿色的按钮“request 1 ether from faucet”,就可以领取1ETHhttps://upload-images.jianshu.io/upload_images/5392502-8d91aff64a584416.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

MetaMask Ether Faucet

或者在这个网址领取3个测试用的ETHhttps://upload-images.jianshu.io/upload_images/5392502-210af9c14853fe98.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

Ethereum Ropsten Faucet

如果两个都领取的话,那么此时你总共就有4个ETH了https://upload-images.jianshu.io/upload_images/5392502-30e821392a4ee157.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/363

MetaMask插件


二、编辑代码由于以太坊智能合约使用的是Solidity语言,所以需要使用Solidity开发。在这里我使用的是Remix,这是一个在线的Solidity编译器。https://upload-images.jianshu.io/upload_images/5392502-861d239a421d2b2b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

Remix是一个在线的Solidity编译器

1、拷贝代码代码可以从这个网址拷,然后粘贴到Remix左边的代码编辑区就可以了https://upload-images.jianshu.io/upload_images/5392502-a11213e813e502a6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

智能合约代码

2、设置参数:大家注意在网页右边的"Run"中的“Environment”设置为“Injected Web3”,如果遇到无法选择“Injected Web3”的情况,请刷新一下。“Create”中填入创建的Token参数,第一个参数是Token的数量;第二个参数是Token的全称;第三个参数是Token的精度,即Token最小为小数点后几位;第四个参数是Token的符号;例如:100000000,"zhongxh's test token",8,"ZTT"上述例子代表创建的Token的全称是"zhongxh's test token",符号是“ZTT”, ZTT的最大精度为小数点后8位,即最小是0.000000001ZTT,总共有1亿份,那么总共有100000000 * 10^(-8)ZTT,即1ZTT点击“Create”按钮https://upload-images.jianshu.io/upload_images/5392502-1b87aea56c395047.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

以太坊智能合约的编辑、编译和创建

3、提交智能合约点击“Create”后,就可以看到MetaMask弹出的“CONFIRM TRANSACTION”的页面,这个页面是用来确认发送的,点击“SUBMIT”提交。https://upload-images.jianshu.io/upload_images/5392502-1b87aea56c395047.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700



以太坊智能合约的编辑、编译和创建https://upload-images.jianshu.io/upload_images/5392502-dfb9b812641142a7.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/350

提交智能合约


点击“SENT”,可以看到刚刚创建的合约。点击该智能合约https://upload-images.jianshu.io/upload_images/5392502-3400a34d3c256683.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/361

红色框里面是刚刚创建的智能合约


点击刚刚发布的智能合约地址,就会调转到Etherscan(以太坊的区块浏览器),耐性等待智能合约的创建。
https://upload-images.jianshu.io/upload_images/5392502-b23a207ae7c79b00.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700以太坊的区块浏览器

4、发布智能合约Contract address为上面创建的合约地址;Contract name为在Remix中选择创建的合约名称HumanStandardToken;Compiler版本需选择在Remix进行合约创建时选择的编译器版本一致;是否优化Optimization也需要与Remix发布合约时保持一致;在“Enter the Solidity Contract Code below”中填入之前在Remix中的solidity合约代码;在“Constructor Arguments ABI-encoded”中填入构造函数参数(100000000,"zhongxh's test token",8,"ZTT")的ABI编码,这个编码可以在创建合约的transaction的Input data中找出,如下图蓝色选中的部分即是构造函数参数的ABI编码(b0029之后所有的数据)。请注意:以上都要和Remix发布合约时保持一致,否则没办法生成一个有效的ERC20 Token。https://upload-images.jianshu.io/upload_images/5392502-c11c68979476ea65.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700




https://upload-images.jianshu.io/upload_images/5392502-6f792d76e539d2fd.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

点击Verify and Publish,如果验证通过了就会出现如下页面:https://upload-images.jianshu.io/upload_images/5392502-40efafffc95d9b6f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700



刷新一下页面,点击Contract Source标签,就能看到上传的合约源代码了:
https://upload-images.jianshu.io/upload_images/5392502-441475bfcbee39bb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700



三、验证因为Metamask不支持toekn的发送,我们切换到MyEtherWallet钱包。需要注意的是,MyEtherWallet也需要切换到Rostpen网络https://upload-images.jianshu.io/upload_images/5392502-634b65df3cf4b5bb.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

切换到Rostpen网络

接下来切换到“发送以太币/发送代币”https://upload-images.jianshu.io/upload_images/5392502-8a7e7cb589009201.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

解锁以太坊钱包

在这里我选择用私钥的方式解锁钱包,私钥可以从Metamask获得点击Metamask右上角的“...”,然后点击"Export Private Key ",输入密码,即可获得私钥https://upload-images.jianshu.io/upload_images/5392502-cfebc926e0ab04ff.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/364

导出私钥

将私钥拷到MyEtherWallet,就可以解锁你的钱包了。点击右下角的“Load Token Balance”https://upload-images.jianshu.io/upload_images/5392502-1436fb02b9e71ae3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

钱包已解锁


右下角显示的正是刚刚创建的Token,也就是ZTT,余额为1,这表明我的ERC20 Token发布成功了!https://upload-images.jianshu.io/upload_images/5392502-7389d75126b71895.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/700

ERC20 Token发布成功了


四、后话没想到发布一个以太坊的ERC20 token这么简单,这么方便,这也是为什么那么多个区块链项目利用以太坊进行爱西欧的原因。但也正是因为简单,才招惹了很多传销组织和骗子,打着区块链的旗号骗人骗钱,因为这几乎是没有成本的买卖,希望大家在接下来的日子擦亮自己的眼睛,为自己的投资负责。我希望通过这篇文章,让读者知道如何发布一个以太坊的ERC20 token, 成为读者入门以太坊智能合约的“最小必要知识”。作者:钟晓宏链接:https://www.jianshu.com/p/e6ca8122a3a3來源:简书著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。http://you.d1v1.com/data/attachment/forum/201811/29/070613elz59p8uq80uq1tb.jpg
http://you.d1v1.com/data/attachment/forum/201811/19/021949pp04ek5vitm4j5iq.jpg
页: [1]
查看完整版本: 手把手教你发行自己的以太坊ERC20 Token