-
Im hitting this "InvalidAddressError: Address "undefined" is invalid." error when trying to use the writeContract function, from the useWriteContract hook. I have a simmilar hook to approve erc721, that that works just fine. - i for some reason have issues with this hook, that interacting with my own contract - but i have no clue why. Ive tried troubleshooting this quite a bit, when just doing the writecontract i get no response at all, nothing happens - when i take the error value out from the useWriteContract hook, i get the above defined error. Im curretly using Below is a combi of all relevant code - if theres anything missing let me know. My write hook to my contract ...code... writeContract({ The sol contract function im trying to invoke: The abi for that function - this is stored in a seperate json file that is imported Anybody hitting similar issues? I find it very odd my approval hook works, yet this dosent. - When interacting with remix IDE directly, i can invoke the function with an identical arg list. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Are you using TypeScript? If not, would highly recommend using it so Based on the code you shared, import { useWriteContract } from 'wagmi'
const { writeContract } = useWriteContract()
const switchContractABI = [
{
inputs: [
{
components: [
{ internalType: 'address', name: 'nftContract', type: 'address' },
{ internalType: 'uint256', name: 'tokenId', type: 'uint256' },
{ internalType: 'uint256', name: 'donorFee', type: 'uint256' },
{ internalType: 'bool', name: 'isERC721', type: 'bool' },
],
internalType: 'struct Switch.DonationInput[]',
name: '_donations',
type: 'tuple[]',
},
],
name: 'donateBatchNFT',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
] as const
writeContract({
abi: switchContractABI,
address: '0x8a901fb2dBfE727279C3738a4FF7Da61843d2853',
functionName: 'donateBatchNFT',
args: [
[
{
nftContract: '0x9982d1e50059bc44e92f7084f532081c12c0bf6a',
tokenId: 4n,
donorFee: 0n,
isERC721: true,
},
],
],
}) |
Beta Was this translation helpful? Give feedback.
Are you using TypeScript? If not, would highly recommend using it so
args
is automatically inferred.Based on the code you shared,
args
is incorrect. The following code should work.TypeScript Playground