Skip to main content

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

NameType
GContractNamesextends string
GBaseContractextends BaseContract<GBaseContract> & { contractName: GContractNames }

Parameters

NameType
contractNameGContractNames
typechainFactoryReadonly<{ connect: TContractConnectFunc<GBaseContract> ; abi: readonly Record<string, any>[] }>
deployedHardhatContractJsonRecord<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

NameType
GContractNamesextends string
GBaseContractextends BaseContract<GBaseContract> & { contractName: GContractNames }

Parameters

NameType
contractNameGContractNames
typechainFactoryReadonly<{ connect: TContractConnectFunc<GBaseContract> ; abi: readonly Record<string, any>[] }>
forgeBroadcastJsonTForgeDeploymentBroadcastCollection

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

NameType
GContractNamesextends string
GBaseContractextends BaseContract<GBaseContract> & { contractName: GContractNames }

Parameters

NameType
contractNameGContractNames
typechainFactoryReadonly<{ connect: TContractConnectFunc<GBaseContract> ; abi: readonly Record<string, any>[] }>
deployedContractJsonRecord<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

NameType
GContractNamesextends string
GBaseContractExtendedextends BaseContract<GBaseContractExtended> & { contractName: GContractNames } = TBaseContractExtended<GContractNames>

Parameters

NameTypeDefault value
contractNameGContractNamesundefined
configObjectundefined
abiRecord<string, any>[]undefined
connectFuncundefined | 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

NameType
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

NameTypeDescription
GContractNamesextends stringA 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.
GAppConnectorListextends 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

NameTypeDescription
loadAppContractConnectors() => GAppConnectorListA 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

NameType
useAppContracts<GContractName>(contractName: GContractName, chainId: undefined | number) => TTypedContract<GContractName, GAppConnectorList>
useLoadAppContracts() => void
useConnectAppContracts(adaptor: undefined | TEthersAdaptor) => void
useContractsAppStoreUseBoundStore<StoreApi<TContractsAppStore<GContractNames, GAppConnectorList, ReturnType<GAppConnectorList[Extract<GContractNames, string>][``"connect"``]>, TAppContractsContext<GContractNames, ReturnType<GAppConnectorList[Extract<GContractNames, string>][``"connect"``]>>>>>

Defined in

src/context/contracts-app/contractsContextFactory.tsx:71