Replies: 1 comment 2 replies
-
This may be something you could use the forking features of hardhat to accomplish, but I haven't done any of that myself. Perhaps someone with more experience in this area can help? You might also consider trying out https://tenderly.co, as I think they also support this sort of thing? |
Beta Was this translation helpful? Give feedback.
2 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.
-
Issue
With
ethers
you can simulate a call to a smart contracts write function usingcallStatic
:I want to do this so I don't need to spend gas fees on a transaction that will fail anyway and also to save some time (simulation is much faster than waiting for a failing transaction).
In my case I need to send two transactions, where the latter transaction is depended on the other:
So if
erc20Contract.approve
would fail, alsorouterContract.swapExactTokensForTokens
would fail 100%.The issue now is that
erc20Contract.approve
almost never fails whilerouterContract.swapExactTokensForTokens
fails very often. But sinceerc20Contract.approve
is a "pre-condition" forrouterContract.swapExactTokensForTokens
I currently always need to executeerc20Contract.approve
(withoutcallStatic
) and then simulaterouterContract.callStaticSwapExactTokensForTokens
. This is unnecessary (in manner of gas fees and time) because I wouldn't need to executeerc20Contract.approve
if I would just know thatrouterContract.callStatic.swapExactTokensForTokens
will fail anyway.Question
Is it possible to simulate multiple state-changing contract calls which are dependent on each other?
Following is an example of what could be a solution in my head, but is obviously not part of the current API of
ethers
:Are there maybe alternative approaches?
Any help is greatly appreciated.
Beta Was this translation helpful? Give feedback.
All reactions