Julia
Julia

Reputation: 1136

Hardhat waffle local smart contracts testing: Not enough ether to mint NFT

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?

Upvotes: 0

Views: 432

Answers (1)

Petr Hejda
Petr Hejda

Reputation: 43591

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();

Upvotes: 0

Related Questions