前言


  目前区块链是互联网中最最火的风口,没有之一。我周围的很多朋友也加入了“炒币”行列,但很不幸,几乎都被“割韭菜”了。而经过我的几天研究,发现,如果自己要发行一种空气币,简直太简单了。只需要下面几个步骤:

1.使用MetaMask

2.找Solidity代码模板

3.部署智能合约

4.空气币转账测试

一、MetaMask


在Chrome浏览器的网上应用店搜索MetaMask,如下图所示,如果搜到小狐狸logo的插件就对了,这就是以太坊浏览器(如果有无法打开Chrome网上应用店的朋友,就去搜索怎样科学上网的教程)。

把它添加到你的Chrome中。

打开浏览器的右上角的图标快捷菜单中,打开这个插件。如下图,选择Ropsten测试网络,并输入密码登录。第一次登陆需要设置密码。

默认会帮你创建一个账号,如果需要再创建账号,如下图所示,点击Crreate Account。

默认账号里是没有以太币的,如果选择的是主网(Main Ethereum Network),则需要从别的账号里转一些以太币过来。而这里,我用的是测试网络,如下图所示,点击“BUY”按钮,去免费零一些以太币来。

再点击“ROPSTEN TEST FAUCET”

如下图使用,打开了一个网页

狂点“request 1 ether from faucet”按钮,每次点击,就会获得免费的1个以太币。大概等5分钟左右时间,测试用的币就会到帐了。再检查你的账户余额,就不是零了。

 二、找代码模板


如下图所示,打开火币Pro网站:https://www.huobipro.com/zh-cn/btc_usdt/exchange/

在其创新区里,几乎有90%的币都是基于ERC20智能合约发行的空气币。这里插一句题外话,如果有炒币的朋友,就要小心这些空气币。

我们拿前段时间炒的最火的币——EDU为例,来讲一下怎么发币。

如下图所示,我们找到区块查询的网址,这个网址就是以太坊ERC20这个智能合约发型Token的交易查询地址。

上面的币种类简介和白皮书不要看,都是忽悠人的。大家记号了,这些都是空气币,不需要“挖”就能有币。而谁发行的币,币就归谁所有。空气币通常会打着教育和医疗的幌子来圈钱。

如下图所示,我们打开这个网站:https://etherscan.io/address/0xf263292e14d9d8ecd55b58dad1f1df825a874b7

Token名是EduCion,我们点进去看,如下图示所,进去这个网页:https://etherscan.io/token/0xf263292e14d9d8ecd55b58dad1f1df825a874b7c

它的创建者一次性收到了"15,000,000,000"的代币,然后就以“8xx,xxx,xxx”的数量转给了其他账号。看到这,我想,大家应该都懂了吧。

好,我们回到刚才的页面,点击“Code”标签页。

复制里面的代码,作为我们发行空气币的代码模板。

三、部署智能合约


如下图所示,我们打开网址:http://remix.ethereum.org

这个地址是以太坊Solidity智能合约语言的在线编辑器。并把刚才复制的代码粘贴进去,并修改以下几处地方:

分别修改:合约名称,代币名称,代币符号,小数位数,发行总量,构造函数名称。好了就这么简单,以下就是我修改后的代码:

其中,name是代码名称,symbol是代币符号,decimals是小数位数,INITIAL_SUPPLY是发型总量。

我分别修改为:LiuDong币,LDC,18位,12,000,000,000量。

完整代码如下:

  1. pragma solidity ^0.4.18;
  2.  
  3. /**
  4. * @title ERC20Basic
  5. * @dev Simpler version of ERC20 interface
  6. * @dev see https://github.com/ethereum/EIPs/issues/179
  7. */
  8. contract ERC20Basic {
  9. function totalSupply() public view returns (uint256);
  10. function balanceOf(address who) public view returns (uint256);
  11. function transfer(address to, uint256 value) public returns (bool);
  12. event Transfer(address indexed from, address indexed to, uint256 value);
  13. }
  14.  
  15. /**
  16. * @title SafeMath
  17. * @dev Math operations with safety checks that throw on error
  18. */
  19. library SafeMath {
  20.  
  21. /**
  22. * @dev Multiplies two numbers, throws on overflow.
  23. */
  24. function mul(uint256 a, uint256 b) internal pure returns (uint256) {
  25. if (a == 0) {
  26. return 0;
  27. }
  28. uint256 c = a * b;
  29. assert(c / a == b);
  30. return c;
  31. }
  32.  
  33. /**
  34. * @dev Integer division of two numbers, truncating the quotient.
  35. */
  36. function div(uint256 a, uint256 b) internal pure returns (uint256) {
  37. // assert(b > 0); // Solidity automatically throws when dividing by 0
  38. uint256 c = a / b;
  39. // assert(a == b * c + a % b); // There is no case in which this doesn't hold
  40. return c;
  41. }
  42.  
  43. /**
  44. * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
  45. */
  46. function sub(uint256 a, uint256 b) internal pure returns (uint256) {
  47. assert(b <= a);
  48. return a - b;
  49. }
  50.  
  51. /**
  52. * @dev Adds two numbers, throws on overflow.
  53. */
  54. function add(uint256 a, uint256 b) internal pure returns (uint256) {
  55. uint256 c = a + b;
  56. assert(c >= a);
  57. return c;
  58. }
  59. }
  60.  
  61. /**
  62. * @title ERC20 interface
  63. * @dev see https://github.com/ethereum/EIPs/issues/20
  64. */
  65. contract ERC20 is ERC20Basic {
  66. function allowance(address owner, address spender) public view returns (uint256);
  67. function transferFrom(address from, address to, uint256 value) public returns (bool);
  68. function approve(address spender, uint256 value) public returns (bool);
  69. event Approval(address indexed owner, address indexed spender, uint256 value);
  70. }
  71.  
  72. /**
  73. * @title Basic token
  74. * @dev Basic version of StandardToken, with no allowances.
  75. */
  76. contract BasicToken is ERC20Basic {
  77. using SafeMath for uint256;
  78.  
  79. mapping(address => uint256) balances;
  80.  
  81. uint256 totalSupply_;
  82.  
  83. /**
  84. * @dev total number of tokens in existence
  85. */
  86. function totalSupply() public view returns (uint256) {
  87. return totalSupply_;
  88. }
  89.  
  90. /**
  91. * @dev transfer token for a specified address
  92. * @param _to The address to transfer to.
  93. * @param _value The amount to be transferred.
  94. */
  95. function transfer(address _to, uint256 _value) public returns (bool) {
  96. require(_to != address(0));
  97. require(_value <= balances[msg.sender]);
  98.  
  99. // SafeMath.sub will throw if there is not enough balance.
  100. balances[msg.sender] = balances[msg.sender].sub(_value);
  101. balances[_to] = balances[_to].add(_value);
  102. Transfer(msg.sender, _to, _value);
  103. return true;
  104. }
  105.  
  106. /**
  107. * @dev Gets the balance of the specified address.
  108. * @param _owner The address to query the the balance of.
  109. * @return An uint256 representing the amount owned by the passed address.
  110. */
  111. function balanceOf(address _owner) public view returns (uint256 balance) {
  112. return balances[_owner];
  113. }
  114.  
  115. }
  116.  
  117. /**
  118. * @title Standard ERC20 token
  119. *
  120. * @dev Implementation of the basic standard token.
  121. * @dev https://github.com/ethereum/EIPs/issues/20
  122. * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
  123. */
  124. contract StandardToken is ERC20, BasicToken {
  125.  
  126. mapping (address => mapping (address => uint256)) internal allowed;
  127.  
  128. /**
  129. * @dev Transfer tokens from one address to another
  130. * @param _from address The address which you want to send tokens from
  131. * @param _to address The address which you want to transfer to
  132. * @param _value uint256 the amount of tokens to be transferred
  133. */
  134. function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
  135. require(_to != address(0));
  136. require(_value <= balances[_from]);
  137. require(_value <= allowed[_from][msg.sender]);
  138.  
  139. balances[_from] = balances[_from].sub(_value);
  140. balances[_to] = balances[_to].add(_value);
  141. allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
  142. Transfer(_from, _to, _value);
  143. return true;
  144. }
  145.  
  146. /**
  147. * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
  148. *
  149. * Beware that changing an allowance with this method brings the risk that someone may use both the old
  150. * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
  151. * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
  152. * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
  153. * @param _spender The address which will spend the funds.
  154. * @param _value The amount of tokens to be spent.
  155. */
  156. function approve(address _spender, uint256 _value) public returns (bool) {
  157. allowed[msg.sender][_spender] = _value;
  158. Approval(msg.sender, _spender, _value);
  159. return true;
  160. }
  161.  
  162. /**
  163. * @dev Function to check the amount of tokens that an owner allowed to a spender.
  164. * @param _owner address The address which owns the funds.
  165. * @param _spender address The address which will spend the funds.
  166. * @return A uint256 specifying the amount of tokens still available for the spender.
  167. */
  168. function allowance(address _owner, address _spender) public view returns (uint256) {
  169. return allowed[_owner][_spender];
  170. }
  171.  
  172. /**
  173. * @dev Increase the amount of tokens that an owner allowed to a spender.
  174. *
  175. * approve should be called when allowed[_spender] == 0. To increment
  176. * allowed value is better to use this function to avoid 2 calls (and wait until
  177. * the first transaction is mined)
  178. * From MonolithDAO Token.sol
  179. * @param _spender The address which will spend the funds.
  180. * @param _addedValue The amount of tokens to increase the allowance by.
  181. */
  182. function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
  183. allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
  184. Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
  185. return true;
  186. }
  187.  
  188. /**
  189. * @dev Decrease the amount of tokens that an owner allowed to a spender.
  190. *
  191. * approve should be called when allowed[_spender] == 0. To decrement
  192. * allowed value is better to use this function to avoid 2 calls (and wait until
  193. * the first transaction is mined)
  194. * From MonolithDAO Token.sol
  195. * @param _spender The address which will spend the funds.
  196. * @param _subtractedValue The amount of tokens to decrease the allowance by.
  197. */
  198. function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
  199. uint oldValue = allowed[msg.sender][_spender];
  200. if (_subtractedValue > oldValue) {
  201. allowed[msg.sender][_spender] = 0;
  202. } else {
  203. allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
  204. }
  205. Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
  206. return true;
  207. }
  208.  
  209. }
  210.  
  211. /**
  212. * @title SimpleToken
  213. * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
  214. * Note they can later distribute these tokens as they wish using `transfer` and other
  215. * `StandardToken` functions.
  216. */
  217. contract LiudongCoin is StandardToken {
  218.  
  219. string public constant name = "LiudongCoin"; // solium-disable-line uppercase
  220. string public constant symbol = "LDC"; // solium-disable-line uppercase
  221. uint8 public constant decimals = 18; // solium-disable-line uppercase
  222.  
  223. uint256 public constant INITIAL_SUPPLY = 12 * (10 ** 9) * (10 ** uint256(decimals));
  224.  
  225. /**
  226. * @dev Constructor that gives msg.sender all of existing tokens.
  227. */
  228. function LiudongCoin() public {
  229. totalSupply_ = INITIAL_SUPPLY;
  230. balances[msg.sender] = INITIAL_SUPPLY;
  231. Transfer(0x0, msg.sender, INITIAL_SUPPLY);
  232. }
  233.  
  234. }

在Solidity编辑器的右边,切换到Run标签页,选择到LiuDongCion合约,点击部署(Deploy)按钮。如下图示所,弹出MetaMask插件,点击SUBMIT按钮,支付“0.001362“的以太币就能完毕这个智能合约的部署。

看吧,才花这么点钱,这就发行了很多空气币。

等待片刻,Solidity编辑器的底部控制台处打印出网站:https://ropsten.etherscan.io/tx/0x2c78cab134e7ce18e12a39f9a4b3ea2687ff017da12e85b1ea2e7f47af63b7f8

这说明智能合约部署好了,也就是已经写入到区块链接中了。

我们打开这个页面,就发现,自己的代币已经部署成功了。

如下图所示,点击合约的地址:

LiuDong币已经部署上去了。

四、空气币转账测试


如下图所示,合约地址是:0xA06263304AbEBAcf4f885Faf9630ea697E6901a9

把这个地址复制到Solidity编辑器的At Address中,遍出现了该智能合约的函数。

在banlanceOf中输入合约创建者的地址:0x9dd6bd0d543ff85a1782d683d0c9a63964fc00dd

1200xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,这么多的币的余额就出来了。

那么,现在来往别的账号里转账试试。如下图所示,找到刚才创建的账号,点击复制账号地址菜单:

复制地址到转账(transfer)的输入框中,输入0x7DB59BE385dA0D6B5BB5B99626Cb1a11f5f5eCd6,12000000000000

代表的是转入的账号和转入的数量,如下图所示,点击transfer按钮,弹出MetaMask,点击提交按钮:

稍等片刻,查看交易情况。该交易就记录在区块链中了:

然后,我们查询一下刚才转入账号的余额。

有两种方式:

一种是输入网址:https://ropsten.etherscan.io/token/0xa06263304abebacf4f885faf9630ea697e6901a9?a=0x7db59be385da0d6b5bb5b99626cb1a11f5f5ecd6

网址的规则是:Token地址 + ?a=转入的地址,如下图所示。余额为:0.000012 个LDC。

另一种方式是在Soldity编辑器中的balanceOf输入转入账号的地址,并调用这个函数。如下图所示:

好了,以上发行空气币的整个过程就讲完了,是不是觉得很简单呢?

如果你觉得我的博客对你有帮助,可以给我点儿打赏,左侧微信,右侧支付宝。

有可能就是你的一点打赏会让我的博客写的更好:)

作者:刘冬.NET 博客地址:http://www.cnblogs.com/GoodHelper/ 欢迎转载,但须保留版权
 
 
 
 
 
 
 

零门槛,包教会。让你在5分钟内使用以太坊ERC20智能合约发行属于自己的空气币的更多相关文章

  1. ROS零门槛学渣教程系列前言

    为什么选择ROS: 1.ROS是开放源码的,在该平台上可以找到非常很多免费开源的代码包,并且这些例程还带wiki说明文档: 2.机器人领域最新的算法直接支持ROS,简单几个步骤就能运行: 3.ROS工 ...

  2. 个人永久性免费-Excel催化剂功能第21波-Excel与Sqlserver零门槛交互-执行SQL语句篇

    在前两波中,已完成了Excel与Sqlserver的查询和上传功能,但难免许多临时的或更深入地操作数据库需要用Sql语句来操作,对一般用户电脑里,不可能有条件轻易安装一个数据库客户端软件,就算安装了对 ...

  3. 个人永久性免费-Excel催化剂功能第20波-Excel与Sqlserver零门槛交互-数据上传篇

    Excel作为众多数据存储的交换介质,在不同的系统内的数据很少可以很连贯地进行整合分析,一般的业务系统都会提供导出Excel作为标配功能供用户使用系统内生成的数据. 此时最大的问题是,Excel很维去 ...

  4. 阿里云https免费证书配置-包教会

      阿里云https免费证书配置-包教会-有需要请联系小编! 小编个人站点:https://www.itdog.site/ 小编微信号:wvqusrtg  

  5. Dizcuz站点部署-包教会

      Dizcuz站点部署-包教会-有需要请联系小编! 小编微信号:wvqusrtg

  6. Android零基础入门第30节:两分钟掌握FrameLayout帧布局

    原文:Android零基础入门第30节:两分钟掌握FrameLayout帧布局 前面学习了线性布局.相对布局.表格布局,那么本期来学习第四种布局--FrameLayout帧布局. 一.认识FrameL ...

  7. 从零构建以太坊(Ethereum)智能合约到项目实战——第23章 从零构建和部署去中心化投票App,decentralization Voting Dapp

    P90 .1-从零构建和部署去中心化投票App-01 P91 .2-从零构建和部署去中心化投票App-02 P92 .3-从零构建和部署去中心化投票App-03 参考博文:http://liyuech ...

  8. 一小时包教会 —— webpack 入门指南

    什么是 webpack? webpack是近期最火的一款模块加载器兼打包工具,它能把各种资源,例如JS(含JSX).coffee.样式(含less/sass).图片等都作为模块来使用和处理. 我们可以 ...

  9. IRIS数据集的分析-数据挖掘和python入门-零门槛

    所有内容都在python源码和注释里,可运行! ########################### #说明: # 撰写本文的原因是,笔者在研究博文“http://python.jobbole.co ...

随机推荐

  1. [nodemon] clean exit - waiting for changes before restart

    出现上述日志信息,程序就不能往下运行了. 原因:node程序在初始化的时候就报错了,仔细debug吧...

  2. Nested Dolls 贪心 + dp

    G: Nested Dolls Time Limit: 1 Sec     Memory Limit: 128 Mb     Submitted: 99     Solved: 19 Descript ...

  3. PYQT窗口可视化编程

    1.用PYQT的Qt设计师设计完程序UI后,将其转换为UI.py脚本. 转换步骤见帖:http://www.cnblogs.com/doudongchun/p/3694765.html 2.在同目录下 ...

  4. Java虚拟机-对象的创建和访问

    一.对象的创建: 创建对象在java上面是很简单的,使用new关键字就可以了,但是其实在虚拟机中,java对象的创建是一个复杂的过程. 当java虚拟机遇到一个new的指令的时候,对象创建的程序正式启 ...

  5. win10安装ubuntu16.04双系统历程

    目录 win10安装ubuntu16.04双系统 历程 安装时间 安装准备 安装过程 其他问题 win10安装ubuntu16.04双系统 历程 安装时间 2018.11.30 安装准备 u盘(格式化 ...

  6. 解析Json文件

    一: /** * 把json文件读取到内存中 * * @throws IOException */ public String getFile(String filePath) throws IOEx ...

  7. 剑指offer——python【第38题】二叉树的深度

    题目描述 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. 解题思路 想了很久..首先本渣渣就不太理解递归在python中的实现 ...

  8. WIN10远程计算机不支持所需的FIPS安全级别解决

    win10系统的电脑在远程xp系统或者其他系统的电脑时,提示错误,远程计算机可能不支持所需的FIPS安全级别,如果出现一以下2种错误,可以解决!   1 第一步:打开win10下的,控制面板 2 第二 ...

  9. Android 一个日历控件的实现代码

    转载  2017-05-19   作者:Othershe   我要评论 本篇文章主要介绍了Android 一个日历控件的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看 ...

  10. [vue开发记录]vue仿ios原生datepicker实现

    先上个效果图 现在只开发了年月,还在优化. 在网上看了一个纯原生js实现实现惯性滚动和回弹的文章  地址:https://www.cnblogs.com/ranyonsue/p/8119155.htm ...