0

Error message is:

  1. Unit tests Governor mint first nft: Error: VM Exception while processing transaction: reverted with reason string 'Not enough ether to purchase NFTs.' at MyNftToken.approve (@openzeppelin/contracts/token/ERC721/ERC721.sol:114) at MyNftToken.safeMint (contracts/MyNftToken.sol:54) at async HardhatNode._mineBlockWithPendingTxs (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:1773:23) at async HardhatNode.mineBlock (node_modules/hardhat/src/internal/hardhat-network/provider/node.ts:466:16) at async EthModule._sendTransactionAndReturnHash (node_modules/hardhat/src/internal/hardhat-network/provider/modules/eth.ts:1504:18) at async HardhatNetworkProvider.request (node_modules/hardhat/src/internal/hardhat-network/provider/provider.ts:118:18) at async EthersProviderWrapper.send (node_modules/@nomiclabs/hardhat-ethers/src/internal/ethers-provider-wrapper.ts:13:20)

Prior to running my test I set the ether balance to 10 ether:

await this.token.deployed();
      await hre.network.provider.request({ method: 'hardhat_setBalance', params: [this.signers.admin.address, ethers.utils.parseEther('10').toHexString()] });

I mint setting a a gas limit so I don't get the Unable to estimate gas error:

const myFirstMint = await this.token.safeMint(this.signers.admin.address, {
      gasLimit: 250000,
    });
    await myFirstMint.wait();

Anyone knows what more I can do?

Julia
  • 981
  • 1
  • 8
  • 16

1 Answers1

0

Smart contracts are for security reasons not able to just pull ETH from a wallet - you need to explicitly state how much you want to send while creating the transaction.

ethersjs use the overrides parameter where you can also specify the amount of wei sent along with the transaction. Example below shows sending 1 ETH (which is 1e18 wei).

const myFirstMint = await this.token.safeMint(this.signers.admin.address, {
    gasLimit: 250000,
    value: ethers.utils.parseEther("1.0"),
});
await myFirstMint.wait();
Petr Hejda
  • 40,554
  • 8
  • 72
  • 100