NFT Frontend Minting and Integration 2 — Questions and Answers
Question 1: In a React dApp, which library function is most commonly used to connect a browser wallet via injected providers like MetaMask?
- window.ethereum.request({ method: 'eth_requestAccounts' }) (Correct answer)
- fetch('/connect')
- localStorage.getItem('wallet')
- navigator.connectWallet()
Correct answer: window.ethereum.request({ method: 'eth_requestAccounts' })
EIP-1193 providers expose window.ethereum, and eth_requestAccounts prompts the user to connect their accounts.
Question 2: When minting an NFT from the frontend, why should the total mint cost (price × quantity) be sent in the transaction's 'value' field?
- The contract's payable mint function requires ETH to cover the price (Correct answer)
- It sets the gas limit
- It encrypts the transaction
- It registers the user's email
Correct answer: The contract's payable mint function requires ETH to cover the price
A payable mint function expects msg.value to equal the required payment, so the value field must carry the ETH.
Question 3: What is the purpose of listening to a contract's 'Transfer' event after a mint transaction confirms on the frontend?
- To detect the newly minted tokenId and update the UI (Correct answer)
- To pay gas fees
- To deploy the contract
- To compile Solidity
Correct answer: To detect the newly minted tokenId and update the UI
The Transfer event from the zero address signals a mint and exposes the new tokenId for UI updates.
Question 4: Which approach prevents a user from being charged for a failed mint when the sale is paused on-chain?
- Call a read-only view (e.g., saleActive) before sending the transaction (Correct answer)
- Increase the gas limit
- Send the transaction twice
- Disable JavaScript
Correct answer: Call a read-only view (e.g., saleActive) before sending the transaction
Reading the sale state first lets the UI block transactions that would revert, saving the user gas.
Question 5: In ethers.js v6, what does a 'Contract' instance need to send a state-changing mint transaction rather than just read data?
- A signer connected to the contract (Correct answer)
- Only a JSON-RPC provider
- A private key hardcoded in the frontend
- An Infura API key in the HTML
Correct answer: A signer connected to the contract
Read calls work with a provider, but write transactions require a signer that can authorize and submit them.
Question 6: Why is it risky to display 'mint successful' immediately after calling the contract method without awaiting the receipt?
- The transaction may still revert or be dropped before confirmation (Correct answer)
- It uses too much memory
- It violates CORS
- It changes the chainId
Correct answer: The transaction may still revert or be dropped before confirmation
A submitted transaction can still fail or be dropped, so success should only show after the receipt confirms.
Question 7: What does the EIP-1193 'chainChanged' event allow a dApp frontend to do?
- Detect when the user switches networks and refresh or reload state (Correct answer)
- Mint tokens automatically
- Sign the user out of MetaMask
- Lower gas prices
Correct answer: Detect when the user switches networks and refresh or reload state
Listening for chainChanged lets the dApp react to network switches, often by reloading to avoid stale state.
In a React dApp, which library function is most commonly used to connect a browser wallet via injected providers like MetaMask?