Allow contract address overriding in generated hooks dynamically #4241
Unanswered
Harman-singh-waraich
asked this question in
Ideas
Replies: 1 comment
-
Cross-posting workaround from Discord: In the meantime, you can build your own hooks with the proxy address using the import { createUseReadContract, createUseWriteContract } from 'wagmi/codegen'
import { yourContractAbi } from './generated' // @wagmi/cli output
const proxyAddress = '0x...'
export const useReadYourContract = createUseReadContract({ abi: yourContractAbi, address: proxyAddress })
export const useWriteYourContract = createUseWriteContract({ abi: yourContractAbi, address: proxyAddress })
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Currently, there is no option to config the address in the generated hooks dynamically, we can only configure them in wagmi.config.ts .
Rationale
There are instances where an app might have a Factory contract that deploy other contracts (Factory contracts have an implementation contract to deploy the new ones , by creating an instance of the implementation contract ).
The hooks for the implementation contract only has the address of the implementation contract, but we need to interact with the other deployed contracts.
Since we do not have the addresses of the deployed contracts before build we cannot configure them.
So it would be ideal to provide dynamic contract address ( or override) without having to use
createUseSimulateContract
orcreateUseWriteContract
in the app to create a hook separately for the dynamic address which would render the hooks generated throughgenerate
useless as we will be creating a new hook just to change the contract address.Example
if there is a generated hook like this :
we should be able to provide a different address for ChildContract like this :
The same goes for Read hooks too.
@tmm
Beta Was this translation helpful? Give feedback.
All reactions