Hi. I am working with this contract https://github.com/avolabs-io/nft-auction/blob/master/contracts/NFTAuction.sol . 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.
https://docs.moralis.io/moralis-dapp/web3/web3#example-of-calling-a-write-contract-method
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,
privateKey:
āprivate_keyā,
});
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
)
external
payable
auctionOngoing(_nftContractAddress, _tokenId)
onlyApplicableBuyer(_nftContractAddress, _tokenId)
{
_makeBid(_nftContractAddress, _tokenId, _erc20Token, _tokenAmount);
}
contarct git repo: https://github.com/avolabs-io/nft-auction/blob/master/contracts/NFTAuction.sol
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: https://testnet.bscscan.com/tx/0xc0c8016f6afd0494604ef3170f1688f1d9292c6360f062c84f8600ff3e6534e0
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.
Summary
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.
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.