call to 2 write functions on a single button click #2830
Replies: 2 comments
-
|
hey @abbasibneakram that's possible, but requires you to await a Promise to resolve You can set up both functions using the wagmi contractWrite hook's, then create a separate async function that runs both functions. Just make sure you throw in a condition to await for the first function to resolve a Promise. That way the second function won't execute until the first resolves completely. Something similar to this: And then pass the async function into the |
Beta Was this translation helpful? Give feedback.
-
|
onClick={async () => { try { |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I want to call approve function and after the success of approve I want to call another write function say buyWithDai but on a single button click
For Example: In my contract there is a function to purchase tokens with DAI tokens, for that I have to first aprove the DAI tokens to the contract and then can transfer into the contract and I want this on a single button click.
I serached a lot but couldn't find a way to do this.
Flow: When Buy button will be clicked metamask should be popped up for the approve function of DAI contract after this approve transaction metamask should be popped up gaian for buyWithDai function, any help would be appreciated.
Beta Was this translation helpful? Give feedback.
All reactions