[react-moralis] Set transaction value with useWeb3ExecuteFunction [SOLVED]

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"}

Thanks for your attention!

1 Like

What version of Moralis SDK you used?

In my package.json I have:

"moralis": "^0.0.124",
"react-moralis": "^0.2.8"

Hi @juanilarregui

Please share an example of how did you provide a msgValue :raised_hands:

I found the error, I wrongly assumed that I could set the msgValue parameter directly as an int in wei.

It works now with:

msgValue: Moralis.Units.ETH(0.5)

Thanks for triggering the solution!


Nice job! Happy BUIDLing

1 Like