Title: Error Solving “ERC721: APPOR TO CALLER” with Metamask: ERC721 Open Zeppelin (Buy NFT) at the Polygone
Introduction:
Welcome! I am happy to help you solve the usual Manny Web3 developers, a particle of those Polygon Blockchain. In this article we will investigate
Realize the problem:
Erc721: APPOR Caller “is a common problem in the web3 that can be caused by cerveal factors. In this case, it is related to the Wey OpenZeppelin ERC721 Contraact acts according to some for some NFTS WTH metamask. In particular, it appears on contraction, processing the approval of token.
ERC721 and approval:
If you will implement the ERC721 contraction on the blockchain platform of the polygon, inherits the built -in functionality for all consumers. How, this function relies on Teero’s metamask to request transactions to specification of tokens before.
Metamascus problem:
Wen Buy (_tokenid)
The function on your ERC721 contract, it calls in **) for the transfer of the aforementioned token. Howver, where you adhere to some NFT wth wth, the metamic water, it fails, the function approval 'is called any April.
Solution:
To resolve this question and successfully buy it (_tokenid)function on your ERC721 Counterct with metamask, Folling of the Steps:
- Install Thezeppelin ERC721 Contraction
: Make you have an Openzeppplin installed
- Set your wallet Metamascus : Make sure you set up and if you can Metamas Network Blockchain, which is hunted
- Use
Buy (_tokenid)
whichapprove '
: When you call function Buy (_tokenid), pass the address
`_owner
and props. However, include aapproved call (_owner) _amouUnt
before buying NFT.
Here’s an updated version of your code:
`Javascript
Const {eters} = demand ('web3');
// Suppose you have created Hasa a
Async function Buynft (_tokenid, _owner, _amount) {
Triy {
+
Const Erc721 = to wait for ether.getcontracorfactory ('Openzepelinerc721');
// introduction and initiation
Const tokeninstance = wait Erc721.Deploy ();
to wait for tokeninstance.Deployed ();
// Call functionbuyon a contract
Const Real = Wait tokeninstance.buy (_tokenid, _owner, _amount);
The result of a return;
} capture (error) {
Console.error ('Error Buying NFT:', Error);
cast a mistake; // re -throw the mistake to propagate it
Iche
Iche
// Example of use:
Const polygonaddress = ' // plant WTH your polygon blockchain eddress
Const tokenid = '0x ...'; // crew with the desired ERC721 IMO ID
Const '0x ...'; // Plant with Borlet Metamask
Const quantity = '1,000 ether'; // plant with the amount you want some
buy (tokenid, amount)
.Theen (result) => {
Console.log (result);
I)
.Catch ((error) => {
Console.error ('Error Buying NFT:', Error);
});
Conclusion:
Follow and update your code usingapprovalapproval
Talk about NFT WTH, you have a metamathic Polygon Network. Remember to replace the holders of the place (eg, https: // Polygon.io/
, `_ToKenid
) with its real values.