-
Notifications
You must be signed in to change notification settings - Fork 364
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
fix(ethers-v6): TypedContractEvent should extend EventLog #811
base: master
Are you sure you want to change the base?
Conversation
|
There is a However, I don't think extending EventLog here would not be appropriate, are you facing any type issues? Types in ethers v6 without typechain: contract.filters.Transfer // ContractEvent
contract.getEvent('Transfer') // ContractEvent
contract.filters.Transfer('0x123') // DeferredTopicFilter
contract.queryFilter(contract.filters.Transfer) // EventLog with typechain: import {ERC20} from '../typechain'
contract.filters.Transfer // ERC20.TransferEvent.Event
contract.getEvent('Transfer') // ERC20.TransferEvent.Event
contract.filters.Transfer('0x123') // TypedDeferredTopicFilter<ERC20.TransferEvent.Event>;
contract.queryFilter(contract.filters.Transfer) // TypedEventLog<ERC20.TransferEvent.Event> |
How do I type the event log? In v5, I type them like this: import type { MintEvent } from '../Abi'
const targetTopicHash = keccak256(toUtf8Bytes('Mint(uint256,uint256,uint256)')
// txReceipt.logs
const _logs = logs.filter((log) => log.topics[0] === targetTopicHash)
if (_logs.length === 0) {
throw new Error(`Log with topic ${filterTopic} not found`)
}
const log = _logs[0]
return this.contract.interface.parseLog(log) as unknown as MintEvent In v6, the export namespace MintEvent {
export type InputTuple = [
to: BigNumberish,
tokenId: BigNumberish,
tokenNumber: BigNumberish
];
export type OutputTuple = [to: bigint, tokenId: bigint, tokenNumber: bigint];
export interface OutputObject {
to: bigint;
tokenId: bigint;
tokenNumber: bigint;
}
export type Event = TypedContractEvent<InputTuple, OutputTuple, OutputObject>;
export type Filter = TypedDeferredTopicFilter<Event>;
} But the I tried using
Do you have any suggestions? thanks. Edit: I should state the overall request: to type the logs of tx receipt. More specifically, const tx = await abi.mint({ ... })
const receipt = await tx.wait()
const parsedLog = parseLog(receipt.logs, 'Mint(uint256,uint256,uint256)')
console.log(parsedLog.args.tokenId.toNumber()) I wrote the |
Yea,
Do you mean Transfer event works but Mint event gives type errors? Can you try this once? const parsedLog = parseLog(receipt.logs, 'Mint(uint256,uint256,uint256)') as unknown as TypedEventLog<MintEvent.Event>[] You should be able to access |
Yes. I pasted the error in the above comment. I paste here again: The export namespace MintEvent {
export type InputTuple = [
to: BigNumberish,
tokenId: BigNumberish,
tokenNumber: BigNumberish
];
export type OutputTuple = [to: bigint, tokenId: bigint, tokenNumber: bigint];
export interface OutputObject {
to: bigint;
tokenId: bigint;
tokenNumber: bigint;
}
export type Event = TypedContractEvent<InputTuple, OutputTuple, OutputObject>;
export type Filter = TypedDeferredTopicFilter<Event>;
} The error for
|
This is to align with v5:
so that we can type the event log with it.