I want to create a NFT Marketplace website where people can list and buy NFTs. It will be multi-chain supporting both Polygon and Ethereum chains. It will accept both ERC721 & ERC1155 tokens.
I want to know how can I list those tokens in my website if I don't know there contract abi?
Is there any way by which I can get the contract's abi from the contract's address so that I can call the methods of the NFT contracts?
This is my code where I tried to do the above:-
async function getAllNFTs() {
const key = simpleCrypto.decrypt(cipherEth);
const provider = new ethers.providers.JsonRpcProvider(mainnet);
const wallet = new ethers.Wallet(key, provider);
const signer = wallet.provider.getSigner(wallet.address);
const contract = new ethers.Contract(EMNMarketAddress, EMNMarket, signer);
const data = await contract.getAvailableNft();
const items = await data.map(async i => {
const tokenContract = i.nftContract.toString();
console.log(tokenContract);
const tokenUri = await tokenContract.tokenURI(i.tokenId)
const meta = await axios.get(tokenUri)
let price = ethers.utils.formatUnits(i.price.toString(), 'ether')
let item = {
price,
tokenId: i.tokenId.toNumber(),
seller: i.seller,
owner: i.owner,
image: meta.data.image,
name: meta.data.name,
description: meta.data.description,
}
return item
})
setNfts(items);
setLoadingState('loaded');
}
It is giving me the following error:-
Uncaught (in promise) TypeError: tokenContract.tokenURI is not a function
Can anyone tell me where am I doing wrong?