Module: ContractAppContext
A context for your react app with contractsContextFactory that provides you access to load, connect and use typed contracts throught your app.
See the ContractAppContext docs for detailed explanation and examples.
ContractAppContext
createConnectorForHardhatContract
▸ createConnectorForHardhatContract<GContractNames
, GBaseContract
>(contractName
, typechainFactory
, deployedHardhatContractJson
): Readonly
<{ contractName
: GContractNames
; config
: TBasicContractDeployment
} & Readonly
<{ connect
: TContractConnectFunc
<GBaseContract
> ; abi
: readonly Record
<string
, any
>[] }>>
Summary
Creates a connector for any of your hardhat contracts
Type parameters
Name | Type |
---|---|
GContractNames | extends string |
GBaseContract | extends BaseContract <GBaseContract > & { contractName : GContractNames } |
Parameters
Name | Type |
---|---|
contractName | GContractNames |
typechainFactory | Readonly <{ connect : TContractConnectFunc <GBaseContract > ; abi : readonly Record <string , any >[] }> |
deployedHardhatContractJson | Record <number , { name : string ; chainId : string ; contracts : Record <string , { abi?: any[] | undefined; address: string; }> }[]> |
Returns
Readonly
<{ contractName
: GContractNames
; config
: TBasicContractDeployment
} & Readonly
<{ connect
: TContractConnectFunc
<GBaseContract
> ; abi
: readonly Record
<string
, any
>[] }>>
Defined in
src/context/contracts-app/contractConnectors.ts:154
createConnectorForFoundryContract
▸ createConnectorForFoundryContract<GContractNames
, GBaseContract
>(contractName
, typechainFactory
, forgeBroadcastJson
): Readonly
<{ contractName
: GContractNames
; config
: TBasicContractDeployment
} & Readonly
<{ connect
: TContractConnectFunc
<GBaseContract
> ; abi
: readonly Record
<string
, any
>[] }>>
Summary
Creates a connector for any of your Foundry contracts, deployed forge scripts and forge broadcast output
Type parameters
Name | Type |
---|---|
GContractNames | extends string |
GBaseContract | extends BaseContract <GBaseContract > & { contractName : GContractNames } |
Parameters
Name | Type |
---|---|
contractName | GContractNames |
typechainFactory | Readonly <{ connect : TContractConnectFunc <GBaseContract > ; abi : readonly Record <string , any >[] }> |
forgeBroadcastJson | TForgeDeploymentBroadcastCollection |
Returns
Readonly
<{ contractName
: GContractNames
; config
: TBasicContractDeployment
} & Readonly
<{ connect
: TContractConnectFunc
<GBaseContract
> ; abi
: readonly Record
<string
, any
>[] }>>
Defined in
src/context/contracts-app/contractConnectors.ts:191
createConnectorForExternalContract
▸ createConnectorForExternalContract<GContractNames
, GBaseContract
>(contractName
, typechainFactory
, deployedContractJson
): Readonly
<{ contractName
: GContractNames
; config
: TBasicContractDeployment
} & Readonly
<{ connect
: TContractConnectFunc
<GBaseContract
> ; abi
: readonly Record
<string
, any
>[] }>>
Summary
Creates a contract connector for any external contract
✏️ Notes
- As an example you could use this for an external contract such as DAI
Type parameters
Name | Type |
---|---|
GContractNames | extends string |
GBaseContract | extends BaseContract <GBaseContract > & { contractName : GContractNames } |
Parameters
Name | Type |
---|---|
contractName | GContractNames |
typechainFactory | Readonly <{ connect : TContractConnectFunc <GBaseContract > ; abi : readonly Record <string , any >[] }> |
deployedContractJson | Record <number , Record <string , string >> |
Returns
Readonly
<{ contractName
: GContractNames
; config
: TBasicContractDeployment
} & Readonly
<{ connect
: TContractConnectFunc
<GBaseContract
> ; abi
: readonly Record
<string
, any
>[] }>>
Defined in
src/context/contracts-app/contractConnectors.ts:231
createConnectorForExternalAbi
▸ createConnectorForExternalAbi<GContractNames
, GBaseContractExtended
>(contractName
, config
, abi
, connectFunc?
): Readonly
<{ contractName
: GContractNames
; config
: TBasicContractDeployment
} & Readonly
<{ connect
: TContractConnectFunc
<GBaseContractExtended
> ; abi
: readonly Record
<string
, any
>[] }>>
Summary
Create a contract connector from a ABI.
✏️ Notes
- This can be used for unverified external contracts
Type parameters
Name | Type |
---|---|
GContractNames | extends string |
GBaseContractExtended | extends BaseContract <GBaseContractExtended > & { contractName : GContractNames } = TBaseContractExtended <GContractNames > |
Parameters
Name | Type | Default value |
---|---|---|
contractName | GContractNames | undefined |
config | Object | undefined |
abi | Record <string , any >[] | undefined |
connectFunc | undefined | TContractConnectFunc <GBaseContractExtended > | undefined |
Returns
Readonly
<{ contractName
: GContractNames
; config
: TBasicContractDeployment
} & Readonly
<{ connect
: TContractConnectFunc
<GBaseContractExtended
> ; abi
: readonly Record
<string
, any
>[] }>>
Defined in
src/context/contracts-app/contractConnectors.ts:272
TContractsContextProps
Ƭ TContractsContextProps: Object
Summary
Props for the ContractContext generated by the contractContextFactory
Type declaration
Name | Type |
---|---|
ethersContextKey? | string |
Defined in
src/context/contracts-app/contractsContextFactory.tsx:33
contractsContextFactory
▸ contractsContextFactory<GContractNames
, GAppConnectorList
>(loadAppContractConnectors
): Object
Summary
This is the factory function that creates the ContractContext and returns the hooks you can use to access typed contracts through out your app.
✏️ Notes
- you must define the generic GContractNames if you want type narrowing for the hooks: e.g.
contractsContextFactory<keyof TAppConnectorList, TAppConnectorList>(getAppContractsConfig);
, where getAppContractsConfig is a function that returns Record of contract names and connectors. - See this for an example for an example of how to use this.
Type parameters
Name | Type | Description |
---|---|---|
GContractNames | extends string | A type that represents the names of the contracts you want to access. Should be keyof ReturnType<loadAppContractConnectors> , where loadAppContractConnectors is the function that returns the contract connectors config. |
GAppConnectorList | extends TConnectorList <GContractNames , TBaseContractExtended <GContractNames >> | A type are the list of contracts and their connectors. Should be ReturnType<loadAppContractConnectors> , where loadAppContractConnectors is the function that returns the contract connectors config. |
Parameters
Name | Type | Description |
---|---|---|
loadAppContractConnectors | () => GAppConnectorList | A function that returns a list of app contract connectors. See this for an example |
Returns
Object
A context for contracts, hook to access contracts, hook to load contracts, hook to connect to contracts in a network
Name | Type |
---|---|
useAppContracts | <GContractName>(contractName : GContractName , chainId : undefined | number ) => TTypedContract <GContractName , GAppConnectorList > |
useLoadAppContracts | () => void |
useConnectAppContracts | (adaptor : undefined | TEthersAdaptor ) => void |
useContractsAppStore | UseBoundStore <StoreApi <TContractsAppStore <GContractNames , GAppConnectorList , ReturnType <GAppConnectorList [Extract <GContractNames , string >][``"connect"``]>, TAppContractsContext <GContractNames , ReturnType <GAppConnectorList [Extract <GContractNames , string >][``"connect"``]>>>>> |