赞
踩
该教程可以更好的让你体验以太坊网络
提示:
1、安装Metamsk插件(申请账号,在测试网中获取一些免费的以太)
2、 写一个实现ERC20协议代币合约的智能合约
3、 将合约编译部署到以太坊的网络上(这里部署到Ropsten测试网,有钱的小伙伴可以尝试主网)
4、将你发布的代币导入钱包中
这里省略Metamask的安装和获取免费以太的方法,百度一下就有教程了哦
pagma solidity ^0.4.16; contract TokenERC20 { string public name; string public symbol; uint8 public decimals = 18; // 18 是建议的默认值 uint256 public totalSupply; mapping (address => uint256) public balanceOf; // mapping (address => mapping (address => uint256)) public allowance; event Transfer(address indexed from, address indexed to, uint256 value); event Burn(address indexed from, uint256 value); function TokenERC20(uint256 initialSupply, string tokenName, string tokenSymbol) public { totalSupply = initialSupply * 10 ** uint256(decimals); balanceOf[msg.sender] = totalSupply; name = tokenName; symbol = tokenSymbol; } function _transfer(address _from, address _to, uint _value) internal { require(_to != 0x0); require(balanceOf[_from] >= _value); require(balanceOf[_to] + _value > balanceOf[_to]); uint previousBalances = balanceOf[_from] + balanceOf[_to]; balanceOf[_from] -= _value; balanceOf[_to] += _value; Transfer(_from, _to, _value); assert(balanceOf[_from] + balanceOf[_to] == previousBalances); } function transfer(address _to, uint256 _value) public returns (bool) { _transfer(msg.sender, _to, _value); return true; } function transferFrom(address _from, address _to, uint256 _value) public returns (bool success) { require(_value <= allowance[_from][msg.sender]); // Check allowance allowance[_from][msg.sender] -= _value; _transfer(_from, _to, _value); return true; } function approve(address _spender, uint256 _value) public returns (bool success) { allowance[msg.sender][_spender] = _value; return true; } function burn(uint256 _value) public returns (bool success) { require(balanceOf[msg.sender] >= _value); balanceOf[msg.sender] -= _value; totalSupply -= _value; Burn(msg.sender, _value); return true; } function burnFrom(address _from, uint256 _value) public returns (bool success) { require(balanceOf[_from] >= _value); require(_value <= allowance[_from][msg.sender]); balanceOf[_from] -= _value; allowance[_from][msg.sender] -= _value; totalSupply -= _value; Burn(_from, _value); return true; } }
在remix上编译然后部署到以太坊的测试网络。(这个智能合约版本有点老了,新版本语法有差异,需要新版合约私聊我)
先编译然后部署,部署的时候要选择web3注入的对象
输入总量、代币名、代币符号点击部署,等待pendding。(需要metamask的交易确认)
等交易确认后,复制箭头指向的合约地址
打开metamask
添加代币
选择自定义代币,将合约地址输入,他会自动匹配其他信息,点击确认
确认以后就可以领取你发布的Token了
这一我就可以给别人转我的pig币了
快来试试吧 !!!!!想要学习更多区块链知识加我微信 :13721072141
一起学习一起进步
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。