How to execute the bidNFT function?

Hi. I am working with this contract . But I don’t know how to execute the makeBid function of this contract. Can anyone please let me know how to execute this function (makeBid) using moralis?

You can call the bidding smart contract function with Moralis.executeFunction.
You will need pass the ABI and required option to call the smart contract function.

Refer below docs for an example.

Yes. I have tried to execute it like this way. Here is my code:

await Moralis.start({ moralisSecret, serverUrl, appId });
await Moralis.enableWeb3({
chainId: 0x61,

const options = {
contractAddress: NFTAuctionAddess,
functionName: “makeBid”,
abi: ABI,
params: {
_nftContractAddress: ERC721Address,
_tokenId: params._tokenId,
_erc20Token: ERC20Address,
_tokenAmount: body._tokenAmount,
const transaction = await Moralis.executeFunction(options);
const result = await transaction.wait();

But only this function is not working. I have tried to run this function in remix IDE. But it is showing “ERC20: insufficient allowance”. Please help me with this.

Do you have enough erc20 token balance to execute the bid as per the smartcontract function?

Yes, I have enough balance and tokens too.

Here is the contract function:
function makeBid(
address _nftContractAddress,
uint256 _tokenId,
address _erc20Token,
uint128 _tokenAmount
auctionOngoing(_nftContractAddress, _tokenId)
onlyApplicableBuyer(_nftContractAddress, _tokenId)
_makeBid(_nftContractAddress, _tokenId, _erc20Token, _tokenAmount);

contarct git repo:

The erc20 contract which is imported into your contract has an allowance function. you can try to run this function to check if you have token allowances to execute the transfer.

function allowance(address owner, address spender) external view returns (uint256); 

Can you share the failed transaction address for more details?

Sorry for the very late reply. I am really sorry for the late reply. I couldn’t do any transaction for NFT bid. I can give you the contract addresses so that you can check and bid an NFT which are in auction by this contract address. Please let me know.

It is probably due to insufficient allowance. You can try to approve some erc20 to increase the allowance in the smart contract. I guess doing this should fix it.

Check this if this helps for better explanation

I guess allowance allow a user to spend some tokens of msg.sender. But when a single user want to spend some token to bid other user NFTs then that user should spend some token from his/her wallet. Isn’t it? I am still facing this problem.

can you share the contract address and deployed chain details?
and a failed tx address if available.

Yes. I can sharing it below.

NFT Auction Contract Address: 0xe25d3be5F5276A7E3E39E4aE0f060417d8A5b30D

ERC 721 Contract Address / NFT Contract Address: 0xD09c517b2b59A9bf1429a7e87d8c7CaA554Ac130

ERC 20 Contract Address: 0xb8EeF6eF1944676a2072104FCE746BF446794a6c

Deployed chain: bsc testnet.

I have just created an auction and the NFT token id is: 9932. Here is the transaction:

Here are some more information about that auction:
“_minPrice”: “10”,
“_buyNowPrice”: “100”,
“_auctionBidPeriod”: “3”,
“_bidIncreasePercentage”: “1000”

Can you remove the ABI or keep it with a drop-down like below, you can find it in this option. image


This text will be hidden

ABI is too big for the thread. Thank you

Can you tell me which contract function is throwing the insufficient allowance error?

I have removed the ABI. And ERC 20 Contract address (0xb8EeF6eF1944676a2072104FCE746BF446794a6c) is throwing error.

I am trying to do bid like this way:

const oprtions = {
contractAddress: “0xe25d3be5F5276A7E3E39E4aE0f060417d8A5b30D”,
functionName: “makeBid”,
abi: “ABI”,
params: {
_nftContractAddress: “0xD09c517b2b59A9bf1429a7e87d8c7CaA554Ac130”,
_tokenId: body._tokenId,
_erc20Token: “0xb8EeF6eF1944676a2072104FCE746BF446794a6c”,
_tokenAmount: body._tokenAmount,

And when I try to execute this function using moralis it shows this “Error: cannot estimate gas; transaction may fail or may require manual gas limit”. I am getting this error only from this function.

Is this the function that caused insufficient allowance error?

This probably has occurred due to the wrong network in metamask or maybe metamask is taking too long to verify the data from the contract function and cannot estimate gas.
also, check if all the parameters are correct.

Maybe, I am sure about it. I got the insufficient allowance error when I have tried to execute the function using Remix IDE. Can you try to bid that NFT from your side by using the contract addresses?

I would probably get the same error as i do not have the erc20 balance.

Okay then. Thank you so much for trying to helping me. Thanks a lot and please if you find any solution then please suggest me. It will be really helpful for me. Trying to build my first NFT marketplace using moralis.

1 Like

I got the insufficient allowance error

Which function call actually results in this error? You haven’t made that clear.

You need an allowance for the ERC20 token. So call the approve function on this token contract using the relevant address.

You can read about approve/allowance here.