2

我的元掩码显示 ALERT: Transaction Error。合约代码中抛出异常。当我要使用 truffle 传输时,在 localhost:7545 上打开 zeppelin 和 ganache

确认交易后显示

inpage.js:1 MetaMask - RPC Error: Error: [ethjs-rpc] rpc error with payload {"id":6736485951990,"jsonrpc":"2.0","params":["0xf86f048504a817c800836170d494ef9b511c0ddaea1f38ed82becb523a414dc6d7cc8806f05b59d3b2000080822d46a0fa7b64f06fe5520527e3ea35a445d3c461ca97ac25d73062caa9d64025fde7aaa02a5127f46ea982b6b71fd88ebe2a22679b45de0ebaef32137a65171f562caa03"],"method":"eth_sendRawTransaction"} [object Object] {code: -32603, message: "Error: [ethjs-rpc] rpc error with payload {"id":67…method":"eth_sendRawTransaction"} [object Object]", stack: "Error: Error: [ethjs-rpc] rpc error with payload {…method":"eth_sendRawTransaction"} [object Object]"}

我的众筹代码

pragma solidity ^0.5.8;
import "../node_modules/openzeppelin-solidity/contracts/crowdsale/Crowdsale.sol";
import "../node_modules/openzeppelin-solidity/contracts/crowdsale/validation/TimedCrowdsale.sol";
import "../node_modules/openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "../node_modules/openzeppelin-solidity/contracts/crowdsale/validation/CappedCrowdsale.sol";
import "../node_modules/openzeppelin-solidity/contracts/crowdsale/emission/AllowanceCrowdsale.sol";


contract MyCrowdsale is Crowdsale, TimedCrowdsale, CappedCrowdsale, AllowanceCrowdsale {
    constructor (
        uint256 _rate,
        address payable _wallet,
        ERC20 _token,
        uint256 _openingTime,
        uint256 _closingTime,
        uint256 _cap,
        address _tokenAdd
    ) 
    Crowdsale(_rate, _wallet, _token)
    TimedCrowdsale(_openingTime, _closingTime)
    CappedCrowdsale(_cap)
    AllowanceCrowdsale(_wallet)

    public
    {
    }
}

deploy_contract.js

module.exports = async function (deployer, network, accounts) {
    await deployer.deploy(A1Token, "A1Token", "A1T", 2,5000000);
    //deployer.deploy(AddNumbers);
    const deployedToken = await A1Token.deployed();
    console.log(deployedToken.address)
    const rate = 1000;
    const wallet = accounts[0];
    const timeNow = Math.floor(Date.now() / 1000);
    const openingTime = timeNow + duration.seconds(30);
    const closingTime = timeNow + duration.years(1);
    const cap = web3.utils.toWei("100");
    console.log(cap)
    await deployer.deploy(MyCrowdsale,
         rate, wallet, deployedToken.address, openingTime, closingTime, cap, wallet
         );
    const deployedCrowdsale = await MyCrowdsale.deployed();
    //await deployedToken.transfer(deployedCrowdsale.address, await deployedToken.totalSupply());
    deployedToken.approve(deployedCrowdsale.address, 20000);
    console.log(deployedCrowdsale.address);
}

这与具有初始供应的 ERC20 代币相关联。

我尝试重新安装元掩码并清除缓存,我启用了 ethereum.enable();,尝试使用 truffle 开发帐户、ganache CLI 和 GUI,更改气体限制和气体。我该如何解决?

4

0 回答 0