零门槛,包教会。让你在5分钟内使用以太坊ERC20智能合约发行属于自己的空气币
前言
目前区块链是互联网中最最火的风口,没有之一。我周围的很多朋友也加入了“炒币”行列,但很不幸,几乎都被“割韭菜”了。而经过我的几天研究,发现,如果自己要发行一种空气币,简直太简单了。只需要下面几个步骤:
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量。
完整代码如下:
- pragma solidity ^0.4.18;
- /**
- * @title ERC20Basic
- * @dev Simpler version of ERC20 interface
- * @dev see https://github.com/ethereum/EIPs/issues/179
- */
- contract ERC20Basic {
- function totalSupply() public view returns (uint256);
- function balanceOf(address who) public view returns (uint256);
- function transfer(address to, uint256 value) public returns (bool);
- event Transfer(address indexed from, address indexed to, uint256 value);
- }
- /**
- * @title SafeMath
- * @dev Math operations with safety checks that throw on error
- */
- library SafeMath {
- /**
- * @dev Multiplies two numbers, throws on overflow.
- */
- function mul(uint256 a, uint256 b) internal pure returns (uint256) {
- if (a == 0) {
- return 0;
- }
- uint256 c = a * b;
- assert(c / a == b);
- return c;
- }
- /**
- * @dev Integer division of two numbers, truncating the quotient.
- */
- function div(uint256 a, uint256 b) internal pure returns (uint256) {
- // assert(b > 0); // Solidity automatically throws when dividing by 0
- uint256 c = a / b;
- // assert(a == b * c + a % b); // There is no case in which this doesn't hold
- return c;
- }
- /**
- * @dev Substracts two numbers, throws on overflow (i.e. if subtrahend is greater than minuend).
- */
- function sub(uint256 a, uint256 b) internal pure returns (uint256) {
- assert(b <= a);
- return a - b;
- }
- /**
- * @dev Adds two numbers, throws on overflow.
- */
- function add(uint256 a, uint256 b) internal pure returns (uint256) {
- uint256 c = a + b;
- assert(c >= a);
- return c;
- }
- }
- /**
- * @title ERC20 interface
- * @dev see https://github.com/ethereum/EIPs/issues/20
- */
- contract ERC20 is ERC20Basic {
- function allowance(address owner, address spender) public view returns (uint256);
- function transferFrom(address from, address to, uint256 value) public returns (bool);
- function approve(address spender, uint256 value) public returns (bool);
- event Approval(address indexed owner, address indexed spender, uint256 value);
- }
- /**
- * @title Basic token
- * @dev Basic version of StandardToken, with no allowances.
- */
- contract BasicToken is ERC20Basic {
- using SafeMath for uint256;
- mapping(address => uint256) balances;
- uint256 totalSupply_;
- /**
- * @dev total number of tokens in existence
- */
- function totalSupply() public view returns (uint256) {
- return totalSupply_;
- }
- /**
- * @dev transfer token for a specified address
- * @param _to The address to transfer to.
- * @param _value The amount to be transferred.
- */
- function transfer(address _to, uint256 _value) public returns (bool) {
- require(_to != address(0));
- require(_value <= balances[msg.sender]);
- // SafeMath.sub will throw if there is not enough balance.
- balances[msg.sender] = balances[msg.sender].sub(_value);
- balances[_to] = balances[_to].add(_value);
- Transfer(msg.sender, _to, _value);
- return true;
- }
- /**
- * @dev Gets the balance of the specified address.
- * @param _owner The address to query the the balance of.
- * @return An uint256 representing the amount owned by the passed address.
- */
- function balanceOf(address _owner) public view returns (uint256 balance) {
- return balances[_owner];
- }
- }
- /**
- * @title Standard ERC20 token
- *
- * @dev Implementation of the basic standard token.
- * @dev https://github.com/ethereum/EIPs/issues/20
- * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol
- */
- contract StandardToken is ERC20, BasicToken {
- mapping (address => mapping (address => uint256)) internal allowed;
- /**
- * @dev Transfer tokens from one address to another
- * @param _from address The address which you want to send tokens from
- * @param _to address The address which you want to transfer to
- * @param _value uint256 the amount of tokens to be transferred
- */
- function transferFrom(address _from, address _to, uint256 _value) public returns (bool) {
- require(_to != address(0));
- require(_value <= balances[_from]);
- require(_value <= allowed[_from][msg.sender]);
- balances[_from] = balances[_from].sub(_value);
- balances[_to] = balances[_to].add(_value);
- allowed[_from][msg.sender] = allowed[_from][msg.sender].sub(_value);
- Transfer(_from, _to, _value);
- return true;
- }
- /**
- * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender.
- *
- * Beware that changing an allowance with this method brings the risk that someone may use both the old
- * and the new allowance by unfortunate transaction ordering. One possible solution to mitigate this
- * race condition is to first reduce the spender's allowance to 0 and set the desired value afterwards:
- * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
- * @param _spender The address which will spend the funds.
- * @param _value The amount of tokens to be spent.
- */
- function approve(address _spender, uint256 _value) public returns (bool) {
- allowed[msg.sender][_spender] = _value;
- Approval(msg.sender, _spender, _value);
- return true;
- }
- /**
- * @dev Function to check the amount of tokens that an owner allowed to a spender.
- * @param _owner address The address which owns the funds.
- * @param _spender address The address which will spend the funds.
- * @return A uint256 specifying the amount of tokens still available for the spender.
- */
- function allowance(address _owner, address _spender) public view returns (uint256) {
- return allowed[_owner][_spender];
- }
- /**
- * @dev Increase the amount of tokens that an owner allowed to a spender.
- *
- * approve should be called when allowed[_spender] == 0. To increment
- * allowed value is better to use this function to avoid 2 calls (and wait until
- * the first transaction is mined)
- * From MonolithDAO Token.sol
- * @param _spender The address which will spend the funds.
- * @param _addedValue The amount of tokens to increase the allowance by.
- */
- function increaseApproval(address _spender, uint _addedValue) public returns (bool) {
- allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue);
- Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
- return true;
- }
- /**
- * @dev Decrease the amount of tokens that an owner allowed to a spender.
- *
- * approve should be called when allowed[_spender] == 0. To decrement
- * allowed value is better to use this function to avoid 2 calls (and wait until
- * the first transaction is mined)
- * From MonolithDAO Token.sol
- * @param _spender The address which will spend the funds.
- * @param _subtractedValue The amount of tokens to decrease the allowance by.
- */
- function decreaseApproval(address _spender, uint _subtractedValue) public returns (bool) {
- uint oldValue = allowed[msg.sender][_spender];
- if (_subtractedValue > oldValue) {
- allowed[msg.sender][_spender] = 0;
- } else {
- allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue);
- }
- Approval(msg.sender, _spender, allowed[msg.sender][_spender]);
- return true;
- }
- }
- /**
- * @title SimpleToken
- * @dev Very simple ERC20 Token example, where all tokens are pre-assigned to the creator.
- * Note they can later distribute these tokens as they wish using `transfer` and other
- * `StandardToken` functions.
- */
- contract LiudongCoin is StandardToken {
- string public constant name = "LiudongCoin"; // solium-disable-line uppercase
- string public constant symbol = "LDC"; // solium-disable-line uppercase
- uint8 public constant decimals = 18; // solium-disable-line uppercase
- uint256 public constant INITIAL_SUPPLY = 12 * (10 ** 9) * (10 ** uint256(decimals));
- /**
- * @dev Constructor that gives msg.sender all of existing tokens.
- */
- function LiudongCoin() public {
- totalSupply_ = INITIAL_SUPPLY;
- balances[msg.sender] = INITIAL_SUPPLY;
- Transfer(0x0, msg.sender, INITIAL_SUPPLY);
- }
- }
在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输入转入账号的地址,并调用这个函数。如下图所示:
好了,以上发行空气币的整个过程就讲完了,是不是觉得很简单呢?
如果你觉得我的博客对你有帮助,可以给我点儿打赏,左侧微信,右侧支付宝。
有可能就是你的一点打赏会让我的博客写的更好:)
零门槛,包教会。让你在5分钟内使用以太坊ERC20智能合约发行属于自己的空气币的更多相关文章
- ROS零门槛学渣教程系列前言
为什么选择ROS: 1.ROS是开放源码的,在该平台上可以找到非常很多免费开源的代码包,并且这些例程还带wiki说明文档: 2.机器人领域最新的算法直接支持ROS,简单几个步骤就能运行: 3.ROS工 ...
- 个人永久性免费-Excel催化剂功能第21波-Excel与Sqlserver零门槛交互-执行SQL语句篇
在前两波中,已完成了Excel与Sqlserver的查询和上传功能,但难免许多临时的或更深入地操作数据库需要用Sql语句来操作,对一般用户电脑里,不可能有条件轻易安装一个数据库客户端软件,就算安装了对 ...
- 个人永久性免费-Excel催化剂功能第20波-Excel与Sqlserver零门槛交互-数据上传篇
Excel作为众多数据存储的交换介质,在不同的系统内的数据很少可以很连贯地进行整合分析,一般的业务系统都会提供导出Excel作为标配功能供用户使用系统内生成的数据. 此时最大的问题是,Excel很维去 ...
- 阿里云https免费证书配置-包教会
阿里云https免费证书配置-包教会-有需要请联系小编! 小编个人站点:https://www.itdog.site/ 小编微信号:wvqusrtg
- Dizcuz站点部署-包教会
Dizcuz站点部署-包教会-有需要请联系小编! 小编微信号:wvqusrtg
- Android零基础入门第30节:两分钟掌握FrameLayout帧布局
原文:Android零基础入门第30节:两分钟掌握FrameLayout帧布局 前面学习了线性布局.相对布局.表格布局,那么本期来学习第四种布局--FrameLayout帧布局. 一.认识FrameL ...
- 从零构建以太坊(Ethereum)智能合约到项目实战——第23章 从零构建和部署去中心化投票App,decentralization Voting Dapp
P90 .1-从零构建和部署去中心化投票App-01 P91 .2-从零构建和部署去中心化投票App-02 P92 .3-从零构建和部署去中心化投票App-03 参考博文:http://liyuech ...
- 一小时包教会 —— webpack 入门指南
什么是 webpack? webpack是近期最火的一款模块加载器兼打包工具,它能把各种资源,例如JS(含JSX).coffee.样式(含less/sass).图片等都作为模块来使用和处理. 我们可以 ...
- IRIS数据集的分析-数据挖掘和python入门-零门槛
所有内容都在python源码和注释里,可运行! ########################### #说明: # 撰写本文的原因是,笔者在研究博文“http://python.jobbole.co ...
随机推荐
- [nodemon] clean exit - waiting for changes before restart
出现上述日志信息,程序就不能往下运行了. 原因:node程序在初始化的时候就报错了,仔细debug吧...
- Nested Dolls 贪心 + dp
G: Nested Dolls Time Limit: 1 Sec Memory Limit: 128 Mb Submitted: 99 Solved: 19 Descript ...
- PYQT窗口可视化编程
1.用PYQT的Qt设计师设计完程序UI后,将其转换为UI.py脚本. 转换步骤见帖:http://www.cnblogs.com/doudongchun/p/3694765.html 2.在同目录下 ...
- Java虚拟机-对象的创建和访问
一.对象的创建: 创建对象在java上面是很简单的,使用new关键字就可以了,但是其实在虚拟机中,java对象的创建是一个复杂的过程. 当java虚拟机遇到一个new的指令的时候,对象创建的程序正式启 ...
- win10安装ubuntu16.04双系统历程
目录 win10安装ubuntu16.04双系统 历程 安装时间 安装准备 安装过程 其他问题 win10安装ubuntu16.04双系统 历程 安装时间 2018.11.30 安装准备 u盘(格式化 ...
- 解析Json文件
一: /** * 把json文件读取到内存中 * * @throws IOException */ public String getFile(String filePath) throws IOEx ...
- 剑指offer——python【第38题】二叉树的深度
题目描述 输入一棵二叉树,求该树的深度.从根结点到叶结点依次经过的结点(含根.叶结点)形成树的一条路径,最长路径的长度为树的深度. 解题思路 想了很久..首先本渣渣就不太理解递归在python中的实现 ...
- WIN10远程计算机不支持所需的FIPS安全级别解决
win10系统的电脑在远程xp系统或者其他系统的电脑时,提示错误,远程计算机可能不支持所需的FIPS安全级别,如果出现一以下2种错误,可以解决! 1 第一步:打开win10下的,控制面板 2 第二 ...
- Android 一个日历控件的实现代码
转载 2017-05-19 作者:Othershe 我要评论 本篇文章主要介绍了Android 一个日历控件的实现代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看 ...
- [vue开发记录]vue仿ios原生datepicker实现
先上个效果图 现在只开发了年月,还在优化. 在网上看了一个纯原生js实现实现惯性滚动和回弹的文章 地址:https://www.cnblogs.com/ranyonsue/p/8119155.htm ...