Hi! I’m trying to use the useWeb3ExecuteFunction
hook of React-Moralis in a Next.js application to call the Mint function of an ERC721 contract when the user clicks a button.
I’m not being able to set the transaction value that the contract requires to mint an NFT (for example, 0.5 ETH). I’ve tried with msgValue: <value in wei>
but it still prompts in MetaMask with a value equal to 0.
Here’s the code of the function component that renders the Connect/Mint button:
export default function MintButton() {
const { authenticate, isAuthenticated } = useMoralis()
const mintNFTABI = [{
"inputs": [
{
"internalType": "uint256",
"name": "numberOfTokens",
"type": "uint256"
}
],
"name": "mintNFT",
"outputs": [],
"stateMutability": "payable",
"type": "function"
}]
const { data, error, fetch, isFetching, isLoading } = useWeb3ExecuteFunction({
abi: mintNFTABI,
contractAddress: contractAddress,
functionName: "mintNFT",
params: {
numberOfTokens: 1
}
})
return (
<button onClick={isAuthenticated ? () => fetch() : () => authenticate()}>
{isAuthenticated ? "Click to Mint!" : "Click to Connect"}
</button>
)
}
Thanks for your attention!