I am trying to estimate gas for the mint function in a smart contract I created.
try {
const gas = await publicClient.estimateContractGas({
address: provider.token,
abi: fiatAbi,
functionName: 'mint',
account,
args: [
`0x${p.userId}`,
BigInt(p.settledAmount) * 10n ** BigInt(provider.decimals),
],
})
Here is the minimized token contract code
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.20;
import {Initializable} from "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import {ERC20Upgradeable} from "@openzeppelin/contracts-upgradeable/token/ERC20/ERC20Upgradeable.sol";
...
abstract contract PepperBaseTokenV1 is
Initializable,
ERC20Upgradeable,
...
{
...
function mint(address to, uint256 amount) public onlyOwner {
_mint(to, amount);
}
...
function _update(
address from,
address to,
uint256 value
) internal virtual override(ERC20Upgradeable, ERC20PausableUpgradeable) whenNotPaused {
require(!blockList[from], "Sender is blacklisted");
require(!blockList[to], "Recipient is blacklisted");
super._update(from, to, value);
}
}
But everytime I try to mint or estimate gas I get this error.
{
"details": "insufficient funds for transfer",
"metaMessages": [
"This error could arise when the account does not have enough funds to:",
" - pay for the total gas fee,",
" - pay for the value to send.",
" ",
"The cost of the transaction is calculated as `gas * gas fee + value`, where:",
" - `gas` is the amount of gas needed for transaction to execute,",
" - `gas fee` is the gas fee,",
" - `value` is the amount of ether to send to the recipient."
],
"shortMessage": "The total cost (gas * gas fee + value) of executing this transaction exceeds the balance of the account.",
"version": "2.21.3",
"name": "InsufficientFundsError"
}
I know my wallet has enough eth for gas fee. From the error it seems the code is trying to send ETH. I am not sure why that is as the mint function takes two argument, to and value.