Unable to create a type safe abstraction that runs simulation and exposes a write function #4181
Unanswered
DorianWilhelm
asked this question in
Q&A
Replies: 1 comment
-
Note my code.
I think that my code is compelte soultion according to your quiz, but possible help to your quiz. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Check existing issues
Describe the bug
Hi,
Goal:
Create a typesafe abstracted hook that combines
useSimulateContract
anduseWriteContract
.Description:
Hook takes the same input as
useSimulateContract
, runs the simulation and modifies thewriteContract
function fromuseWriteContract
so that it uses the returnedrequest
from the simulation.Problem:
The type for
data.request
and the input forwriteContract
do not match.I have a created a stripped down version of the hook that just demonstrates the type mismatch.
I have seen a couple of these abstractions around and it seems that nobody is able to actually solve the type mismatch. Every example I have seen so far is using an
as any
assertion here. (e.g. see this one here from a mod of the wevm discord https://stackblitz.com/edit/wagmi-use-write-hook-wrapper?file=src/hooks/helpers/use-write-contract-callbacks.ts,src/hooks/helpers/use-write-hook-with-receipt-callback.ts )Would love to hear if I'm making a mistake here somewhere or if this is currently just not possible.
Thank you so much 🙏
Link to Minimal Reproducible Example
https://stackblitz.com/edit/vitejs-vite-cflpir?file=src%2FuseTypedTransaction.ts
Steps To Reproduce
What Wagmi package(s) are you using?
wagmi
Wagmi Package(s) Version(s)
wagmi@^2.12.1
Viem Version
viem@^2.18.5
TypeScript Version
typescript@^5.5.3
Anything else?
No response
Beta Was this translation helpful? Give feedback.
All reactions