Environment
Truffle, VSC, Ganache, solidity ^0.5.8
Details
My metamask shows ALERT: Transaction Error. Exception thrown in contract code. When I am about to transfer using truffle, open zeppelin and ganache on localhost:7545
after confirming the transaction it shows
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]"}
I have tried reinstalling metamask and clearing cache, i have enabled ethereum.enable();, tried using truffle develop account, ganache CLI and GUI, changing gas limit and gas. How do i fix this?
Code to reproduce
My Crowdsale code
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);
}
And this is linked to a ERC20 token with an initial supply.