Integrating using ethers.js
How to integrate CROID domain using ethers.js?
If your product is currently using ether.js, you only need to create a new provider with network configuration and it will be able to retrieve the domain data from blockchain.
// For testnet, instantiate a provider for name resovling.
provider = new ethers.providers.JsonRpcProvider('https://cronos-testnet-3.crypto.org:8545/', {
chainId: 338,
name: 'cronos-testnet',
ensAddress: '0x16a23bFBcE9c53998c90201629E4cDB40B81B127'
})
// For mainnet, instantiate a provider for name resovling.
provider = new ethers.providers.JsonRpcProvider('https://evm.cronos.org', {
chainId: 25,
name: 'cronos-mainnet',
ensAddress: '0x7F4C61116729d5b27E5f180062Fdfbf32E9283E5'
})
// Resolve the name to account address
const account = await provider.resolveName("abcde5.cro")
// Perform a reverse lookup of the address, and will get the name if configured
const name = await provider.lookupAddress("YOUR ACCOUNT ADDRESS")
// Get the address of resolver contract and return a resolver instance.
const resolver = await provider.getResolver("abcde5.cro")Note:
To support resolving UTF-8 (including emoji) names, the version should be 5.7.0 at least.
More information can be found in the ethers.js docs.
Calling Contracts Programmatically
If your project does not use ethers.js lib, you can call contracts programmatically to resolve Cronos ID domains.
Two main contracts will be used to resolve names by calling functions on-chain. You can get their ABI and addresses in the following links:
Below are some pared-down interfaces containing only the necessary methods:
For resolution, only the Resolver function in the CROIDRegistry contract is required; other methods permit looking up owners and updating Cronos ID domain from within a contract that owns a name.
With these definitions, Solidity developers can refer to the following code to resolve or reverse-resolve on-chain:
Getting the hash of the domain
We call the hash of the domain 'node' hash, in bytes32 type. You can refer to this doc to understand how to get the hash. Please take note of the following:
Before being hashed with namehash, names are first normalized, using a process called UTS-46 normalization. This ensures that upper- and lower-case names are treated equivalently, and that invalid characters are prohibited. Anything that hashes and resolves a name must first normalize it, to ensure that all users get a consistent view.
Producing node hash off-chain
You can use ethers.js to produce node hash off-chain:
Getting node hash on-chain
For Solidity developers, you can get the node hash of domain or wallet address on-chain. You should add the following code to your contract:
The input parameter ‘name', is the Cronos ID domain without the '.cro’ suffix. e.g. if your Cronos ID domain is "abcde5.cro", the input should be "abcde5".
Who should I contact for support?
If you have any questions about the integration with Cronos ID Domain, drop us a message on our Discord server and we will get in touch with you!
For developers using other programming languages, we can provide language-specific examples to guide you through the integration.
Last updated