1

I'm trying to send a transaction in order to call a minting function of a smart contract on the Rinkeby Testnet. The problem is that I get the following error:

Error: Transaction has been reverted by the EVM: { "blockHash": "0xba0fa95b2f4ef2b7ab7d499ed1de8b85a8b7147297bb013bf4b545879cd4700e", "blockNumber": 10480884, "contractAddress": null, "cumulativeGasUsed": 2868062, "effectiveGasPrice": 1000000025, "from": "0x1ff21cda9a88944fd78e9fdd9f75631ca05fefd9", "gasUsed": 28987, "logs": [], "logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000", "status": false, "to": "0x4cdfdf81f5f836cbd0f7c57f581ac5162387a97a", "transactionHash": "0x22fca33c21200660eae2995c22ea1be74a7a331e48c24797e767767899a57f3f", "transactionIndex": 28, "type": "0x0" }

If I check the transaction on the etherscan I see the following message: "Fail with error 'Not enough ether to purchase NFTs.'", but that has to be wrong since the address I use has > 0.6ETH and the transaction should just use 0.04ETH + gas. I have tried everything I found online but nothing has helped me...

Here is the code I use:

const web3 = new Web3(new Web3.providers.HttpProvider("-INFURA-"));
const abiContract = require('./contractABI.json')

const contractRinkeby = new web3.eth.Contract(abiContract, '0x---');

const privateKey = process.env.PRIVATE_KEY;

const account = web3.eth.accounts.privateKeyToAccount(privateKey).address;
web3.eth.getBalance(account).then(function (result) {
    console.log("Your account balance is " + web3.utils.fromWei(result, "ether") + " ETH");
});

const options = {
    from    : '0x---',
    to      : '0x---',
    data    : contractRinkeby.methods.mint(1).encodeABI(),
    gas     : 300000
};

const signed  = await web3.eth.accounts.signTransaction(options, process.env.PRIVATE_KEY);
const receipt = await web3.eth.sendSignedTransaction(signed.rawTransaction);

What am I doing wrong? It should be an easy call of the smart contract method, but somehow I'm blocked here since a couple of weeks...

I would be very thankful if you could help me or give me any tips.

Thanks!

2 Answers 2

0

I checked the smart contract and analyze the mint function.

In my opinion, to mint the NFT which means to call mint() function in smart contract, you should send ETH to the smart contract, but I can not see any code part to send ETH when call mint transaction.

So the transaction structure must be like this.

const options = {
    from    : '0x---',
    to      : '0x---',
    data    : contractRinkeby.methods.mint(1).encodeABI(),
    gas     : 300000,
    value   : ethers.utils.parseUnits("0.04", "ether") // or you can use web3 to set the correct value
};
-1

Try to increase gas price. In my application for ethereum blockchain I set gas price - 45 GWEI, and it works. Also there is problem that transaction fails even with correct gas price.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.