Skip to content
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

Add hasEvent and hasFunction methods to contract and interface #3901

Closed
wants to merge 1 commit into from
Closed

Add hasEvent and hasFunction methods to contract and interface #3901

wants to merge 1 commit into from

Conversation

farwayer
Copy link

Motivation:

Sometimes we need to check if the contract that was created in another part of the code contains the function or event we need. Now we have to call the getFunction/getEvent function and catch the exception.

This PR adds a simple check for the presence of functions and events in the interface. Note that these methods do not check that the contract actually supports them.

Handling of the has trap for the contract and filters has also been added. So the check can now be done, including using the in operator:

if ('transfer' in contract) {...}
if ('Transfer' in contract.filters) {...}

It is good behavior to override get and has proxy traps at the same time.

@ricmoo
Copy link
Member

ricmoo commented Mar 15, 2023

This is a great idea! I have a few other changes that are going out first, but will mark this for the next minor bump (after 6.2.0, which should go out later today).

@ricmoo ricmoo added enhancement New feature or improvement. on-deck This Enhancement or Bug is currently being worked on. v6 Issues regarding v6 labels Mar 20, 2023
@ricmoo
Copy link
Member

ricmoo commented Apr 6, 2023

Quick note; since the Contract is a meta-class, new methods cannot be added to it. But the rest looks good. I'm trying it out now. :)

@ricmoo
Copy link
Member

ricmoo commented Apr 7, 2023

Merged in v6.3.0.

Thanks for the suggestion! :)

@ricmoo ricmoo closed this Apr 7, 2023
@farwayer farwayer deleted the contract-has branch April 7, 2023 17:45
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this pull request Jan 14, 2024
Woodpile37 pushed a commit to Woodpile37/ethers.js that referenced this pull request Jan 14, 2024
@ricmoo ricmoo removed the on-deck This Enhancement or Bug is currently being worked on. label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or improvement. v6 Issues regarding v6
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants