1

image

this is the mint function of my contract and I want to pass the quantity argument, please help me with that. my current code :- const { writeAsync: mint, error: mintError } = useContractWrite({ ...contractConfig, functionName: 'mint', });

and then Iam trying to add arguments this way :- const tx = await mint({args: [{_quantity: 1}]});

Thanks in advance!

1 Answer 1

1

tyou dont pass the args to the write function, you pass it in the useContractWrite hook like so

  const { write: mint } = useContractWrite({
    ...contractConfig,
    functionName: 'mint',
    args: [arg1,arg2,arg3],
  })

then call the mint function

also the functions you get back from the hook are { data, isLoading, isSuccess, write } = useContractWrite({...}) not error or writeAsync

3
  • Thank you! also I wanted to ask, how can I send the eth value ? Commented Aug 24, 2022 at 14:41
  • Never mind ... I got it .... thank you Commented Aug 24, 2022 at 14:50
  • To send eth value along with this you have to update the overrides property you pass into the config: overrides: { value: BigNumber.from('10000000000000000'), },
    – Stevers
    Commented Feb 20, 2023 at 18:21

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.