|
|
耍酷的手术刀 · 用Emacs写Verilog | ...· 4 月前 · |
|
|
旅行中的包子 · 武汉金控集团并购九州证券,地方金控平台加速拿 ...· 6 月前 · |
|
|
傲视众生的开水瓶 · 中华人民共和国合同法 - 中国国际私法学会· 7 月前 · |
|
|
安静的热水瓶 · 京TRAIN雅洛|阪急京都線的觀光列車|阪急電鐵· 7 月前 · |
|
|
欢快的花生 · 梵高的最爱:黄色油画颜料解析_颜色· 1 年前 · |
今天调试一个以太坊的合约:
pragma solidity ^0.4.18;
contract MyToken {
address creator;
uint256 public balanceOf = 0;
// Initializes contract with initial supply tokens to the creator of the
//contract
constructor () public {
// Give the creator all initial tokens
creator = msg.sender;
}
// Send coins
function transfer(address _to) public payable {
require(msg.sender == creator);
// Check if the sender has enough
require(balanceOf >= msg.value);
// Subtract from the sender
balanceOf -= msg.value;
// Add the same to the recipient
_to.transfer(msg.value);
}
// fallback function
function pay() public payable {
balanceOf += msg.value;
}
}
在http://remix.ethereum.org上是正确的,但是在https://ethfiddle.com/出现两个错误,一个是
:10:16: ParserError: Expected identifier, got 'LParen'
constructor () public {
我在constructor函数前面增加function ,看起来解决了
调用transfer,又出现一个调用错误,
VM Exception while processing transaction: invalid opcode
后来各种百度,google发现问题是编译器版本的问题,因此在https://ethfiddle.com/里面选择版本0.4.24,问题全部解决,并且不需要在constructor函数前面增加function
后来使用truffle的时候,truffle compile也出现上面两个错误,检查版本信息:
truffle version
Truffle v4.1.0 (core: 4.1.0)
Solidity v0.4.19 (solc-js)
原来也是Solidity版本问题,卸载truffle重新安装
sudo npm uninstall -g truffle
sudo npm install -g truffle
这次查看版本
truffle version
Truffle v4.1.12 (core: 4.1.12)
Solidity v0.4.24 (solc-js)
重新truffle compile就没有问题了
虽然我们可以安装指定版本的truffle,但是考虑到新版本功能更多,也就算了
npm install -g truffle@X
For example, to get solc 0.4.11 support, install truffle 3.2.2 or above.
npm install -g truffle@3.2.2
or
npm update -g truffle@3.2.2
|
|
傲视众生的开水瓶 · 中华人民共和国合同法 - 中国国际私法学会 7 月前 |
|
|
安静的热水瓶 · 京TRAIN雅洛|阪急京都線的觀光列車|阪急電鐵 7 月前 |
|
|
欢快的花生 · 梵高的最爱:黄色油画颜料解析_颜色 1 年前 |