[ethers-v5] Add events support - #321
Conversation
|
- addListener function was removed since it does not exist in v5 - listeners and off was added
|
Hi @krzkaczor, there is the following error when running the |
quezak
left a comment
There was a problem hiding this comment.
Some initial comments before I try this out on my contracts.
Random thought: is it a good idea to skip the whole typed listeners section if a contract has no defined events?
| listeners(eventName?: string): Array<Listener>; | ||
| off(eventName: string, listener: Listener): this; | ||
| on(eventName: string, listener: Listener): this; | ||
| once(eventName: string, listener: Listener): this; | ||
| removeListener(eventName: string, listener: Listener): this; | ||
| removeAllListeners(eventName?: string): this; | ||
|
|
||
| listeners<T, G>(eventFilter?: TypedEventFilter<T, G>): Array<TypedListener<T, G>>; | ||
| off<T, G>(eventFilter: TypedEventFilter<T, G>, listener: TypedListener<T, G>): this; | ||
| on<T, G>(eventFilter: TypedEventFilter<T, G>, listener: TypedListener<T, G>): this; | ||
| once<T, G>(eventFilter: TypedEventFilter<T, G>, listener: TypedListener<T, G>): this; | ||
| removeListener<T, G>(eventFilter: TypedEventFilter<T, G>, listener: TypedListener<T, G>): this; | ||
| removeAllListeners<T, G>(eventFilter: TypedEventFilter<T, G>): this; |
There was a problem hiding this comment.
I think the more specific overloads should be first, since TS checks them top-to-bottom IIRC
There was a problem hiding this comment.
is it a good idea to skip the whole typed listeners section if a contract has no defined events?
It's a definitely great idea. Since even if these typed listener section lies there useless for contracts without events, I don't think it would affect normal functionality (lmk if it does). Would it be fine if we do that in a separate PR? If not I can do that here.
| import { EventFilter, Event } from 'ethers' | ||
| import { Result } from '@ethersproject/abi' | ||
|
|
||
| export interface TypedEventFilter<T, G> extends EventFilter {} |
There was a problem hiding this comment.
why are the T & G args here if they're not used?
There was a problem hiding this comment.
Actually the T & G contain type info utilised by queryFilter and other methods for output
|
@zemse as for this TS error, it seems that it works only in TS 4.0+ (https://stackoverflow.com/questions/53356652/typescript-generic-tuples-error-rest-element) You should get the same error if you use Soo, could you:
I will deploy it as major version of ethers-v5 to avoid breaking something. Thanks! |
|
@zemse can we add a test (can be the same thing as you put in this PR description) proofing that this works (and continue to work in future ;) )? |
|
I've added some tests pls review |
|
@zemse thanks for this! Released in: https://github.com/ethereum-ts/TypeChain/releases/tag/%40typechain%2Fethers-v5%406.0.0 |
|
@zemse how is this supposed to work? Maybe I'm missing something but the first line in your example Transfer(
from: string | null,
to: string | null,
value: null
): TypedEventFilter<
[string, string, BigNumber],
{ from: string; to: string; value: BigNumber }
>;Which means those 3 arguments are required. |
|
Oh right, you need to do the following, will update the description too. contract.filters.Transfer(null, null, null)As a side note: Actually ethers.js on it's core is fine without passing any args, so the args should be made optional in the target too. Will make a PR soon. |
|
@zemse sounds good, thanks! |
This PR adds the missing events support to the ethers v5 target and intends to close #303 and close #249. Thanks @quezak for #303 (comment)
Usage
To test this in your project
git clone -b 303-ethers-v5-add-event-support https://github.com/zemse/TypeChain.gitcd TypeChainyarn(you need yarn installed if you don't)yarn build(this generates dist dir which is imp)typechain --target ../TypeChain/packages/target-ethers-v5/(Docs)Just in case if that sounds too much, I have temporarily published it to npm for testing:
npm install typechain-target-ethers-v5 --save-dev(later you can just replace the package with official one)typechain --target ethers-v5(Docs)