中国广东省深圳市龙华新区民治街道溪山美地 518131 +86 13113668890 <netkiller@msn.com>
文档始创于2018-02-10
版权 © 2018 Netkiller(Neo Chan). All rights reserved.
版权声明
转载请与作者联系,转载时请务必标明文章原始出处和作者信息及本声明。
微信订阅号 netkiller-ebook (微信扫描二维码) |
---|
QQ:13721218 请注明“读者” |
QQ群:128659835 请注明“读者” |
网站:http://www.netkiller.cn |
最近以太坊创建代币合约政策有些变化,部署合约后需要 "verify and publish " 这个步骤必须穿墙,否则直接 error 500 错误
另外 Solidity 0.4.23 也有许多变化
1. 构造方法
function Token(uint256 initialSupply, string tokenName, string tokenSymbol, uint decimalUnits
)
这样的构造方法改为
constructor(uint256 initialSupply, string tokenName, string tokenSymbol, uint decimalUnits)public{
2. 事件调用,需要 emit 关键字
emit Transfer(msg.sender, _to, _value);
pragma solidity ^0.4.23;
contract NetkillerToken {
string public name;
string public symbol;
uint8 public decimals;
event Transfer(address indexed from, address indexed to, uint256 value);
/* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
constructor(uint256 initialSupply, string tokenName, string tokenSymbol, uint decimalUnits) public {
balanceOf[msg.sender] = initialSupply;
name = tokenName;
symbol = tokenSymbol;
decimals = decimalUnits;
}
/* Send coins */
function transfer(address _to, uint256 _value) public {
/* Check if the sender has balance and for overflows */
require(balanceOf[msg.sender] >= _value && balanceOf[_to] + _value >= balanceOf[_to]);
/* Add and subtract new balances */
balanceOf[msg.sender] -= _value;
balanceOf[_to] += _value;
/* Notify anyone listening that this transfer took place */
emit Transfer(msg.sender, _to, _value);
}
}
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。