1

I have a contract that tries to execute a swap which of course fails if the wanted pair doesn't exist. I though about writing a function that first checks if the swap is possible and only then executes it.

Is this a way to possibly save gas on failed attempts?

1 Answer 1

0

You can use Uniswap factory's getPair to check if the pair exists.

You will have to measure whether it is more gas efficient than a failed swap transaction.

Alternatively, if you're creating some kind of a bot, you can save all the pairs beforehand and then grab the pair from the list.

(You can even listen to events/mempool to make sure you are up to date).

Be careful of swapping tokens you know nothing about; some of them mighe be honeypots that won't allow you to sell them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.