Uniswap/Pancakeswap Get received tokens from a transaction receipt #1604
Unanswered
benwilliamson86
asked this question in
Q&A
Replies: 3 comments 9 replies
-
@benwilliamson86 You can get the information from const swapEventTopic = ethers.utils.id('Swap(address,uint256,uint256,uint256,uint256,address)')
// discard all other logs
const swapLogs = receipt.logs.filter(log => log.topics[0] === swapEventTopic);
// take the last swap event
const lastSwapEvent = swapLogs.slice(-1)[0]
// decode the data
const swapInterface = new ethers.utils.Interface(['event Swap (address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to)'])
const parsed = swapInterface.parseLog(lastSwapEvent);
// use the non zero value
const receivedTokens = parsed.args.amount0Out.isZero() ? parsed.args.amount1Out : parsed.args.amount0Out;
|
Beta Was this translation helpful? Give feedback.
9 replies
-
Bonsoir comment vous allez vraiment j'ai besoin d'aide si vous plaît |
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.
-
Uniswap/Pancakeswap docs say that swapexacttokensfortokens() function will return The input token amount and all subsequent output token amounts.
How can i access this value so that i can use it to swap the exact tokens i receive back? I see from the transaction receipt there is a tx.data that may hold this information but i don't know how to make it readable/usable so i can insert it back into the function.
Many Thanks.
Beta Was this translation helpful? Give feedback.
All reactions