-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ethers-v6: wrong type generated for listening to contract events #867
Comments
Yes, I can confirm that the types are incorrect. The |
@kliyer-ai Why are the types incorrect though? Is it a bug in typechain? Or did I make some sort of mistake in using it? |
I think this is a bug in typechain. When i was constructing my listeners without typechain using const VAULT_EVENTS = [
'event Deposit(address account, uint256 amount, uint256 amountStaked)',
'event Withdraw(address account, uint256 amount)',
];
console.log(`Setting up ${name}: ${address} listener`);
const contract = new Contract(address, VAULT_EVENTS, provider);
contract.on(
'Deposit',
async (
account: string,
amount: number,
amountStaked: number,
event: ContractEventPayload
) => {
const template = `**${name}**: \`Deposit\` ${formatUnits(
amount,
18
)} $FOO into \`${account}\` for (${formatUnits(
amountStaked,
18
)} total`;
await notify({
text: template,
txid: event.log.transactionHash,
});
}
); The listener last arg is When using generated
Not sure how exactly to fix, but imho the generated export type TypedListener<TCEvent extends TypedContractEvent> = (
...listenerArg: [
...__TypechainAOutputTuple<TCEvent>,
TypedEventLog<TCEvent>
...undefined[]
]
) => void; should just type the last arg as import { ContractEventPayload } from 'ethers';
export type TypedListener<TCEvent extends TypedContractEvent> = (
...listenerArg: [
...__TypechainAOutputTuple<TCEvent>,
ContractEventPayload, // this
...undefined[]
]
) => void; |
this is still not fixed, right? |
Please, can the PR that fix this issue be merged? |
I've generated the types for an ERC20 contract with ethers-v6. I would like to listen to the transfer events, to that end I call
The generated types claim lastArg to be of type:
However, the console.log gives me the following output:
The
TypedEventLog<...
object is actually found underlastArg.log
instead oflastArg
itself being of typeTypedEventLog<...
Checking the ethers documentation under "Listening to Events" it says that
Which seems to line up with the behaviour I am observing
The text was updated successfully, but these errors were encountered: