Type error in wagmi's usePrepareContractWrite for value
Type error in wagmi's usePrepareContractWrite for value
Loading saved threads...
user122142 · External communityPost link
External question — Ethereum Stack Exchange
Author: user122142
Original post: https://ethereum.stackexchange.com/questions/151136
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I have next app with typescript and using wagmi (
https://www.npmjs.com/package/wagmi
) package to work with smart contracts. I am trying to prepare contract write using usePrepareContractWrite and need to send wei to the contract function. I included value (
https://wagmi.sh/react/prepare-hooks/usePrepareContractWrite#value-optional
) but getting a typescript error:
Type 'number' is not assignable to type 'undefined'.
Here's how I constructed the function:
const { config, error } = usePrepareContractWrite({
address: contractAddress,
abi,
functionName: "purchaseProduce",
args: [details?.farmer, details?.index],
value: details?.price * details?.quantity,
});
How can I fix this type error?
Quote
Report
VsevolodKurochka · External communityPost link
External answer — Ethereum Stack Exchange
Author: VsevolodKurochka
Original post: https://ethereum.stackexchange.com/a/152233
License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/
Adaptation: HTML converted to plain text; contact email addresses removed.
I think your problem has to do with you passing an undefined value in "value" field, or in "args", because you are using the "?" operator.
Run the code so that you are sure that you have these values.
Or using "enabled" mode in
https://wagmi.sh/react/prepare-hooks/usePrepareContractWrite
Quote
Report
Post Reply
Quoted from Forex.com.bd-Editorial External answer — Ethereum Stack Exchange Author: VsevolodKurochka Source score (net votes, not local likes): 0 Original post: https://ethereum.stackexchange.com/a/152233 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. I think your problem has to do with you passing an undefined value in "value" field, or in "args", because you are using the "?" operator. Run the code so that you are sure that you have these values. Or using "enabled" mode in https://wagmi.sh/react/prepare-hooks/usePrepareContractWrite
Checking account access…