0

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 :)

1 Answer 1

1

Web3Modal is a library that connects users with your Dapp and starts interacting with the blockchain, but for Creating Instances, you should pass the wallet as a signer Or Provider. I recommend reading here for web3model and creating an instance in ether.js here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.