主页 > imtoken国内版下载 > 零门槛,包括教会。让你在5分钟内使用以太坊ERC20智能合约发行属于你自己的空气币
零门槛,包括教会。让你在5分钟内使用以太坊ERC20智能合约发行属于你自己的空气币
前言
目前,区块链是互联网最火的风口,没有之一。 身边不少朋友也加入了“炒币”的行列,可惜,几乎都是“割韭菜”。 经过几天的研究,我发现如果要发行一种空气币,简直太简单了。 只需几步:
1.使用MetaMask
2.找到Solidity代码模板
3.部署智能合约
4.空气币转账测试
1.MetaMask
在Chrome浏览器的web store中搜索MetaMask,如下图,如果找到小狐狸标志的插件就对了,这就是以太坊浏览器(如果有Chrome打不开的朋友网上商店,去搜索如何***教程)。
将其添加到您的 Chrome。
打开浏览器右上角的图标快捷菜单即可打开此插件。 如下图,选择Ropsten测试网,输入密码登录,首次登录需要密码。
默认情况下,将为您创建一个帐户。 如果需要重新创建账号,如下图,点击Create Account。
默认账户中没有以太币,如果选择主网(Main Ethereum Network),需要从其他账户转入一些以太币。 在这里,我使用的是测试网络,如下图所示,单击“购买”按钮以释放一些以太币。
然后单击“ROPSTEN 测试水龙头”
如下图,打开一个网页
疯狂点击“request 1 ether from faucet”按钮,每次点击都会免费获得1 ether。 等待5分钟左右,测试币会到账。 再次检查您的帐户余额,它不是零。
2.查找代码模板
打开火币Pro官网如下图:
在其创新区,几乎90%的币种都是基于ERC20智能合约发行的空气币。 这里说个题外话,有炒币的朋友要小心这些空气币。
下面就以前段时间炒得最火的币种——EDU为例,谈谈如何发币。
如下图,我们找到区块查询的URL,就是以太坊ERC20智能合约发行的Token的交易查询地址。
别看上面的币种和白皮书,都是骗人的。 大家标记一下,这些是空气币,不用“挖”也能有币。 谁发行货币,货币就属于谁。 空气币常被打着教育、医疗的幌子进行集资。
如下图所示,我们打开这个网站:
代币名称为EduCion,我们点击查看,如下图所示,进入该页面:
它的创建者一次性收到“15,000,000,000”个代币,然后以“8xx,xxx,xxx”的数量将它们转入其他账户。 看到这里,我想大家应该明白了吧。
好,我们回到上一页,点击“代码”选项卡。
复制里面的代码作为我们发行空气币的代码模板。
3.部署智能合约
如下图所示,我们打开网址:
这个地址是以太坊 Solidity 智能合约语言的在线编辑器。 并粘贴刚才复制的代码,修改以下地方:
分别修改:合约名称、代币名称、代币符号、小数位数、发行总量、构造函数名称。 嗯,就这么简单btc交易平台模板,下面是我修改后的代码:
其中,name为代号btc交易平台模板,symbol为代币符号,decimals为小数位数,INITIAL_SUPPLY为发型总量。
我修改为:刘东币,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 编辑器的右侧,切换到运行选项卡,选择 LiuDongCion 合约,然后单击部署按钮。 如下图,弹出MetaMask插件,点击SUBMIT按钮,支付“0.001362”以太币,完成本次智能合约的部署。
你看,就这么一点点钱,发行了很多空气币。
稍等片刻,Solidity 编辑器底部的控制台打印出了网站:
这表明智能合约已经部署完毕,也就是已经写入到区块链中。
当我们打开这个页面的时候,我们发现我们的代币已经部署成功了。
如下图,点击合约地址:
刘东币已部署。
4.空气币转账测试
如下图,合约地址为:0xA06263304AbEBAcf4f885Faf9630ea697E6901a9
将这个地址复制到Solidity编辑器的At Address中,智能合约的功能随处可见。
在banlanceOf中输入合约创建者的地址:0x9dd6bd0d543ff85a1782d683d0c9a63964fc00dd
1200xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx,这么多币的余额就出来了。
所以,现在尝试将资金转移到另一个帐户。 如下图,找到刚才创建的账号,点击复制账号地址菜单:
复制地址到转账输入框,输入0x7DB59BE385dA0D6B5BB5B99626Cb1a11f5f5eCd6,12000000000000
代表转账账户和转账数量,如下图,点击转账按钮,会弹出MetaMask,点击提交按钮:
稍等片刻,查看交易。 交易记录在区块链中:
然后,我们查看刚刚转账的账户余额。
有两种方式:
一种是输入网址:
URL的规则是:Token地址+?a=转入的地址,如下图。 余额为:0.000012 LDC。
另一种方式是在Soldity编辑器的balanceOf中输入转账账户地址,调用该函数。 如下所示:
好了,上面整个发行空气币的过程就结束了,是不是觉得很简单呢?
如果觉得我的博客对你有帮助,可以打赏我,左边微信,右边支付宝。
也许你的一点小窍门会让我的博客变得更好 :)