-
-
Notifications
You must be signed in to change notification settings - Fork 1
Helper utilities for Humanbound #27
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
base: dev
Are you sure you want to change the base?
Conversation
ra-phael
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really cool! ✨
|
|
||
| const provider = new providers.JsonRpcProvider( | ||
| `https://${AlchemyNetworkNames[chainId as Web3ChainReference]}.g.alchemy.com/v2/${ | ||
| alchemyConfig[chainId as Web3ChainReference] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite annoying to have to repeat "as Web3ChainReference" so many times 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh... I don't think it's much of an issue from a user perspective since it's abstracted away but in any case is there a better way to do this whilst keeping the type?
| const events = await humanboundContract.queryFilter(filter); | ||
|
|
||
| if (events.length == 0) return BigNumber.from(null); | ||
| return events[0].args[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know how this array of events is sorted?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's latest first from what I remember.
| // returns a boolean reporting if `address` owns a humanbound token | ||
| const hasHBT = useCallback( | ||
| async (address: string) => { | ||
| if (!humanboundContract) throw new Error("hasHBT: contract is null, check your usage of useHumanbound"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These checks seem unecessary given what this hook returns, the functions can't be called unless humanbounContract is defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, this was here before I changed the way the hook was returning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah so the compiler doesn't like this because from a type point of view the value of humanboundContract could be null
| * - getHBTIdOfOwner: @param `address` | ||
| * - getOwnerOf: @param `tokenId` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't apply for hasHBT as it's meant to be has HBT on any network but I wonder if for the 2 other functions we should give the option to pass in a specific network to check. Since HBTs are humanbound and not address-bound theoretically you could have different addresses for a same HBT ID on 2 different networks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouuh actually this is checking one network at a time for hasHBT 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeh it's checking one network at a time because we're assuming the same kind of stack of web3 providers, which are always one network at a time. It's the simplest IMO.
React hooks for Humanbound token helpers.
Use
useHumanboundproviding an Alchemy configuration with api keys to expose functions that return humanbound token data for supported networks:Usage:
Currently only supported networks are:
chainId: 1chainId: 10chainId: 420chainId: 42161chainId: 421613chainId: 137chainId: 80001Alchemy config must be provided with api keys corresponding to the networks above for any network that your dApp intends to support. Using
useHumanboundon networks that are not supported will throw an error.