-
I expected the import { Contract, JsonRpcProvider } from "ethers";
async function main(){
const provider = new JsonRpcProvider()
const c = new Contract('0xaddy', ['event Borrow()', 'event Repay()'], provider)
const topic = await c.filters.Borrow().getTopicFilter()
const topic2 = await c.filters.Repay().getTopicFilter()
{
// works
await provider.getLogs({
topics: topic
})
}
{
// does not work
await provider.getLogs({
topics: [topic, topic2]
})
// demo.ts 11 22 error 2322 Type 'TopicFilter' is not assignable to type 'string | string[] | null'.
// Type '(string | string[] | null)[]' is not assignable to type 'string[]'.
// Type 'string | string[] | null' is not assignable to type 'string'.
// Type 'null' is not assignable to type 'string'. (lsp)
// demo.ts 11 29 error 2322 Type 'TopicFilter' is not assignable to type 'string | string[] | null'. (lsp)
}
} but it does not seem to be working (see type error in the example). Is this a bug or am i misunderstanding the api? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
That should work. But keep in mind your filter you specified isn’t correct for filtering by two topic0. You would want Your filter is looking for logs with topic in the first position and topic2 in the second position. The filter I posted above looks for topic or topic2 in the first position. You are also passing in the entire filter as the positions, while what you mean to pass in is the topic0. Constructing a complex getLog query is more complex than I have figured out a simple API for because the filtering is an AND-ed set of positions with OR-ed sets. So you could do “any Transfer or Approve for account A or B” but you could not do “any Transfer for account A and any Approve for account B”. The nuance is very subtle in what can be merged. But the filter you seek is easy and doable. :) |
Beta Was this translation helpful? Give feedback.
That should work. But keep in mind your filter you specified isn’t correct for filtering by two topic0. You would want
{ topics: [ [ topic.topics[0], topic2.topics[0] ] ] }
.Your filter is looking for logs with topic in the first position and topic2 in the second position. The filter I posted above looks for topic or topic2 in the first position. You are also passing in the entire filter as the positions, while what you mean to pass in is the topic0.
Constructing a complex getLog query is more complex than I have figured out a simple API for because the filtering is an AND-ed set of positions with OR-ed sets. So you could do “any Transfer or Approve for account A or B” but you could not d…