前言
目前區塊鏈是互聯網中最最火的風口,沒有之一。我周圍的很多朋友也加入了“炒幣”行列,但很不幸,幾乎都被“割韭菜”了。而經過我的幾天研究,發現,如果自己要發行一種空氣幣,簡直太簡單了。只需要下面幾個步驟:
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輸入轉入賬號的地址,並調用這個函數。如下圖所示:

好了,以上發行空氣幣的整個過程就講完了,是不是覺得很簡單呢?

如果你覺得我的博客對你有幫助,可以給我點兒打賞,左側微信,右側支付寶。
有可能就是你的一點打賞會讓我的博客寫的更好:)
