Swap (Uniswap V2) event signature and topic0
The topic0 of the Swap (Uniswap V2) event is 0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822, the keccak-256 hash of Swap(address,uint256,uint256,uint256,uint256,address); 2 of its 6 arguments are indexed. Swap on a Uniswap V2-style pool.
Topics
- topic00xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822keccak256("Swap(address,uint256,uint256,uint256,uint256,address)")
- topic1sender (address)indexed: filterable
- topic2to (address)indexed: filterable
Data
- dataamount0In (uint256), amount1In (uint256), amount0Out (uint256), amount1Out (uint256)ABI-encoded, decoded with the ABI
Arguments and where they sit in the log
Indexed arguments travel as topics and can be filtered cheaply; the others are ABI-encoded together in the data.
| Name | Type | In the log |
|---|---|---|
| sender | address | topic1 |
| amount0In | uint256 | data |
| amount1In | uint256 | data |
| amount0Out | uint256 | data |
| amount1Out | uint256 | data |
| to | address | topic2 |
Solidity declaration
event Swap(address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to);
Canonical signature
Swap(address,uint256,uint256,uint256,uint256,address)
topic0
0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822
Get an alert on Swap
Each rule opens with the contract and the conditions filled in. Sign in, pick your chat and click Create.
Contracts we list that emit Swap
Any other contract with the same signature emits a log with the same topic0.
Read Swap logs in code
The same filter in viem, ethers and plain JSON-RPC, and the Solidity that emits it. The address is Uniswap V2 USDC/WETH pair, a contract we list that emits it.
import { createPublicClient, http, parseAbiItem } from "viem"
import { mainnet } from "viem/chains"
const client = createPublicClient({ chain: mainnet, transport: http() })
const logs = await client.getLogs({
address: "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
event: parseAbiItem("event Swap(address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to)"),
fromBlock: "latest",
})
for (const log of logs) console.log(log.args) // { sender, amount0In, amount1In, amount0Out, amount1Out, to }import { Interface, JsonRpcProvider } from "ethers"
const provider = new JsonRpcProvider(process.env.RPC_URL)
const iface = new Interface(["event Swap(address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to)"])
const logs = await provider.getLogs({
address: "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
topics: [iface.getEvent("Swap")!.topicHash],
})
for (const log of logs) console.log(iface.parseLog(log)?.args){
"jsonrpc": "2.0",
"id": 1,
"method": "eth_getLogs",
"params": [
{
"address": "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc",
"topics": [
"0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822"
],
"fromBlock": "latest"
}
]
}event Swap(address indexed sender, uint256 amount0In, uint256 amount1In, uint256 amount0Out, uint256 amount1Out, address indexed to);
// inside a function:
emit Swap(sender, amount0In, amount1In, amount0Out, amount1Out, to);An example Swap log, encoded and decoded
Placeholder values, not a real transaction: how each argument is stored in the topics and the data, and what decoding gives back.
- topic0keccak256("Swap(address,uint256,uint256,uint256,uint256,address)")0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822
- topic1sender0x0000000000000000000000001111111111111111111111111111111111111111
- topic2to0x0000000000000000000000006666666666666666666666666666666666666666
- data0x00000000000000000000000000000000000000000000000000000000000007d00000000000000000000000000000000000000000000000000000000000000bb80000000000000000000000000000000000000000000000000000000000000fa00000000000000000000000000000000000000000000000000000000000001388
- senderaddress · indexed0x1111111111111111111111111111111111111111
- amount0Inuint2562000
- amount1Inuint2563000
- amount0Outuint2564000
- amount1Outuint2565000
- toaddress · indexed0x6666666666666666666666666666666666666666
Frequently asked questions
What is the topic0 of the Swap (Uniswap V2) event?
0xd78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822: the keccak-256 hash of Swap(address,uint256,uint256,uint256,uint256,address).
Which Swap (Uniswap V2) arguments are indexed?
sender, to are indexed and sit in the log's topics; amount0In, amount1In, amount0Out, amount1Out are in the data.
How do I get an alert when a contract emits Swap (Uniswap V2)?
Open one of the ready-made rules on this page, or add any contract and pick Swap (Uniswap V2) from the event list. Conditions can be set on indexed and non-indexed arguments, and each alert names the contract and links to the transaction.
More event signatures and tools
Know the moment a contract emits it
The Beta plan is free: one wallet and one contract, no credit card.