solidity开发sendTransaction报错

发布于 2022-09-11 19:55:00 字数 3081 浏览 27 评论 0

问题描述

使用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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文