solidity开发sendTransaction报错
问题描述
使用ganache 和 truffle开发,用到的了openzeppelin这个库,使用到了ERC20和Crowdsale这两个合约,测试的时候,调用下面语句报错,其中purchaser是ganache生成的账号数组。
MyCrowdsaleInstance.sendTransaction({ from: purchaser[1], value: web3.utils.toWei("0.5", "ether"), gas: "220000"})
报错信息如下
Error: Returned error: VM Exception while processing transaction: revert
at XMLHttpRequest._onHttpResponseEnd (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:318:1)
at XMLHttpRequest._setReadyState (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request.js:208:1)
at XMLHttpRequestEventTarget.dispatchEvent (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\xhr2-cookies\dist\xml-http-request-event-target.js:34:1)
at XMLHttpRequest.request.onreadystatechange (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\web3\~\web3-providers-http\src\index.js:96:1)
at C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\packages\truffle-provider\wrapper.js:112:1
at C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-requestmanager\src\index.js:140:1
at Object.ErrorResponse (C:\Users\zx\AppData\Roaming\nvm\v10.15.1\node_modules\truffle\build\webpack:\~\web3-eth\~\web3-core-helpers\src\errors.js:29:1)
版本信息:
openzeppelin-solidity: "^2.1.3"
Truffle v5.0.17 (core: 5.0.16)
Solidity v0.5.0 (solc-js)
Node v10.15.1
Web3.js v1.0.0-beta.37
相关代码
// MyToken.sol
pragma solidity ^0.5.0;
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20Detailed.sol";
contract MyToken is ERC20, ERC20Detailed {
uint public INITIAL_SUPPLY = 10000000000;
constructor(string memory _name, string memory _symbol, uint8 _decimals)
ERC20Detailed(_name, _symbol, _decimals)
public
{
_mint(msg.sender, INITIAL_SUPPLY);
}
}
// MyCrowdsale.sol
pragma solidity ^0.5.0;
import './MyToken.sol';
import "openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
contract MyCrowdsale is Crowdsale {
constructor(
uint256 rate, // rate in TKNbits
address payable wallet,
MyToken token
)
Crowdsale(rate, wallet, token)
public
{
}
}
// 2_deploy_token.js
const MyToken = artifacts.require("MyToken");
const MyCrowdsale = artifacts.require("MyCrowdsale");
module.exports = function(deployer, network, accounts) {
const _name = "My Token";
const _symbol = "MTK";
const _decimals = 2;
const rate = 1;
const wallet = accounts[0];
return deployer.then(() => {
return deployer.deploy(MyToken, _name, _symbol, _decimals);
}).then(() => {
return deployer.deploy(
MyCrowdsale,
rate,
wallet,
MyToken.address
);
})
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论