Explain how topics and such work
How to compute the topic...
Example hog logs are used.
Link to provider.getLogs and contract.on
Filter are used as a way to query ... efficient, explain bloom filters lightly
A filter may have up to 4 topic-sets, where each topic-set refers to a condition that must match the log topic in that position (i.e. each condition is AND
-ed together).
If a topic-set is null
, a log topic in that position is not filtered at all and any value matches.
If a topic-set is a single topic, a log topic in that position must match that topic.
If a topic-set is an array of topics, a log topic in that position must match any one of the topics (i.e. the topic in this position are OR
-ed).
Topic-Sets | Matching Logs | |
[ A ] | topic[0] = A | |
[ A, null ] | |
[ null, B ] | topic[1] = B | |
[ null, [ B ] ] | |
[ null, [ B ], null ] | |
[ A, B ] | (topic[0] = A) AND (topic[1] = B) | |
[ A, [ B ] ] | |
[ A, [ B ], null ] | |
[ [ A, B ] ] | (topic[0] = A) OR (topic[0] = B) | |
[ [ A, B ], null ] | |
[ [ A, B ], [ C, D ] ] | [ (topic[0] = A) OR (topic[0] = B) ] AND [ (topic[1] = C) OR (topic[1] = D) ] | |
Example Log Matching | |
ERC-20 Transfer Filter Examples
//
//
//
//
//
filter = {
address: tokenAddress,
topics: [
id("Transfer(address,address,uint256)"),
hexZeroPad(myAddress, 32)
]
}
filter = {
address: tokenAddress,
topics: [
id("Transfer(address,address,uint256)"),
null,
hexZeroPad(myAddress, 32)
]
}
filter = {
address: tokenAddress,
topics: [
id("Transfer(address,address,uint256)"),
null,
[
hexZeroPad(myAddress, 32),
hexZeroPad(myOtherAddress, 32),
]
]
}
To simplify life, ..., explain here, the contract API
ERC-20 Contract Filter Examples
const abi = [
"event Transfer(address indexed src, address indexed dst, uint val)"
];
const contract = new Contract(tokenAddress, abi, provider);
contract.filters.Transfer(myAddress)
// {
// address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
// topics: [
// '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
// '0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72'
// ]
// }
contract.filters.Transfer(null, myAddress)
// {
// address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
// topics: [
// '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
// null,
// '0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72'
// ]
// }
contract.filters.Transfer(myAddress, otherAddress)
// {
// address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
// topics: [
// '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
// '0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72',
// '0x000000000000000000000000ea517d5a070e6705cc5467858681ed953d285eb9'
// ]
// }
contract.filters.Transfer(null, [ myAddress, otherAddress ])
// {
// address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
// topics: [
// '0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef',
// null,
// [
// '0x0000000000000000000000008ba1f109551bd432803012645ac136ddd64dba72',
// '0x000000000000000000000000ea517d5a070e6705cc5467858681ed953d285eb9'
// ]
// ]
// }
Explain what happens to strings and bytes, how to filter and retain the value