1

I have a payable write function which accepts arguments and some ETH to perform the work.

However, when calling the write function, the call is just transferring eth to the contract address without running the write function.

Docs for react hook I am using to interact with the contract: https://wagmi.sh/docs/hooks/useContractWrite

Docs for Override from ethers: https://docs.ethers.io/v5/api/contract/contract/#Contract-functionsCall

My Function:

const [{ data: writeData, error: writeError }, write] = useContractWrite(
    {
      addressOrName: 'Address',
      contractInterface: interface,
    },
    'entry',
    {
      args: [firstHashRef.current, secondHashRef.current],
      overrides: { 
        value: ethers.utils.parseEther("0.01") 
      }
    }
  )

I had everything working with just args - then I uploaded a new contract that made the entry function payable and added the override to pass the eth with the call, and now its not working.

1 Answer 1

3

The way I've used it is to pass overrides to the write function:

const [{ data: writeData, error: writeError }, write] = useContractWrite(
    {
      addressOrName: 'Address',
      contractInterface: interface,
    },
    'entry',
    {
      args: [firstHashRef.current, secondHashRef.current],
      // commenting out your usage 
      // overrides: { 
      //  value: ethers.utils.parseEther("0.01") 
      // }
    }
  );

// pass overrides into the write function
write({overrides: {value: ethers.utils.parseEther("0.01")} });

You could also pass in args the same way if you wanted:

write({
  args: [firstHashRef.current, secondHashRef.current],
  overrides: {value: ethers.utils.parseEther("0.01")},
});

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.