Within this section, we will look at how to query the Injective Name Service contracts to resolve .inj domain names and perform reverse lookups.
InjNameService Class Implementation
The recommended approach is to create your own InjNameService 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.
Important: Always verify reverse resolution by checking that the name resolves back to the original address. Here’s how to perform the verification using forward resolution:
Note: If you’re using the InjNameService class 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
Dependencies
To use the Injective Name Service, you’ll need the following packages:
Last modified on March 30, 2026