InjNameService Class Implementation
The recommended approach is to create your ownInjNameService class that encapsulates the name service functionality. This provides a clean, reusable interface for domain resolution and reverse lookups.
Creating the InjNameService Class
Here’s a complete implementation you can use in your application:Using the InjNameService Class
Raw Smart Contract Querying
If you need more control or want to query the contracts directly without the abstraction layer, here are the individual methods:Domain Resolution (Forward Lookup)
Resolve a .inj domain name to an Injective address.Step 1: Get the Resolver Address
Step 2: Get the Address for the Domain
Reverse Resolution (Address to Domain)
Resolve an Injective address to its primary .inj domain name.Note: If you’re using theInjNameServiceclass shown earlier, you can simplify this verification to:await injNameService.fetchInjAddress(name)
Best Practices
- Always normalize domain names before processing them to ensure consistency
- Verify reverse resolutions by performing a forward lookup to ensure the name actually points back to the address
- Handle errors gracefully - not all addresses have .inj names, and not all names are registered
- Use proper network configuration - ensure you’re querying the correct network (Mainnet vs Testnet)
- Cache results when appropriate to reduce unnecessary contract queries
