I am building a guided web3 project to access the smart contract functions; the guide sometimes uses web3modal and wallet. The below code uses the web3modal to call the function that mints ERC721 tokens.
const web3modal = new Web3Modal(); const connection = await web3modal.connect(); const provider = new ethers.providers.Web3Provider(connection); const signer = provider.getSigner(); const mintNftcontract = new ethers.Contract(hhMintNftContract, MintNFTABI, signer); let mintNfttransaction = await mintNftcontract.mintNftToSell(url);
However, the below code uses the wallet to call the function of the same smart contract to fetch the minted ERC721 tokens.
const provider = new ethers.providers.JsonRpcProvider(hhRpc); const wallet = new ethers.Wallet(hhPriKey, provider); const ImagicaMarketContract = new ethers.Contract(hhImagicaMarketContract, ImagicaMarketABI, wallet); const mintNFTContract = new ethers.Contract(hhMintNftContract, MintNFTABI, wallet); const listedNFTData = await ImagicaMarketContract.getAvailableNFT();
So, is there any specific reason this is being done in this project? One pattern I can find is that the functions that write data on Blockchain are using the web3modal, and when it comes to reading the data from the Blockchain, the wallet is used. But this is just my guess.
So if anyone could help me understand why and when we should use web3modal or wallet to access smart contract functions, it'd be a great help. Please :)