Skip to content
This repository has been archived by the owner on Feb 9, 2024. It is now read-only.

Add ContractProvider to maintain a single instance of each ContractPromise #31

Open
DoubleOTheven opened this issue Mar 30, 2023 · 0 comments

Comments

@DoubleOTheven
Copy link
Contributor

DoubleOTheven commented Mar 30, 2023

Feature Request

Create a state management system to allow a user to easily instantiate a ContractPromise with an ABI and address (like with the existing useContract() hook) and save that in state to be accessed in other views. Currently users must create a custom Context for each contract like this. It would be nice if useink would do this for them.

Suggestion

  • Add a ContractRegistryContext that has a Record<T, contract>.
  • Change the existing hook useContract(abi, address) to useNewContract(abi, address)
  • Create a setter function in ContractRegistryContext to allow a user to store the contract in state via a name of type T
  • Add a hook to access contracts useContract(name: T) that returns the contract or undefined

Motivation

Users must create their own Provider to share contract client instances across files. This is time consuming and extra code we can avoid...

Use Cases

Setting up multiple contractPromise instances and using them on multiple pages by sharing them via state in the Provider

@DoubleOTheven DoubleOTheven changed the title Add ContractRegistry Context that maintains state for all contract client instances Add ContractProvider to maintain a single instance of each ContractPromise Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant