Publish code snippet to lookup core contract address using Registry.sol #31
arthurgousset
started this conversation in
Ideas
Replies: 2 comments 1 reply
-
would be cool to add it to a viem extension https://viem.sh/docs/clients/custom.html |
Beta Was this translation helpful? Give feedback.
0 replies
-
also here is the snippet for the registry react hook we use in staked-celo import { useContractRead } from 'wagmi';
import { registryABI } from '@celo/abis';
const REGISTRY_CONTRACT_ADDRESS = '0x000000000000000000000000000000000000ce10';
export default function useCeloRegistryAddress(contractName: string) {
const { data: address } = useContractRead({
address: REGISTRY_CONTRACT_ADDRESS,
abi: registryABI,
functionName: 'getAddressForString',
args: [contractName],
});
if (address && parseInt(address, 16) === 0) {
return undefined;
}
return address;
} |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
@therealharpaljadeja shared a great insight.
He loves using
viem
+@celo/abis
, but when he wants to interact with core contracts, he ends up hard-coding the core contract address.That's not strictly necessary, because the address can be fetched from Registry.sol.
In ContractKit, this is abstracted from the developer, whereas with viem this has to be done manually.
There are various solutions and ideas to make this easier:
Here is a little code snippet I used in celo-org/epochs to lookup core contract addresses in various places:
Source: utils.ts
Source: carbonOffsetDistributions.ts
Beta Was this translation helpful? Give feedback.
All reactions