Integration Guide
This guide demonstrates how to integrate Sanko Name Service (SNS) into your application using Viem, a TypeScript interface for Ethereum.
Since SNS is essentially ENS, you can utilize the built-in utilities for ENS provided by Viem.
Prerequisites
- Familiarity with JavaScript/TypeScript and Ethereum concepts
- Node.js (or equivalent) environment
- Viem library installed (
npm install viem
)
Setting up Viem
First, initialize Viem client connected to Sanko chain.
Find the
sanko
chain definition here
Interacting with SNS
Resolving SNS Names
To resolve an SNS name to an address:
Resolving Address to Name
Using Viem
Important Note: Reverse resolution is not enabled by default. Some users may not have set their primary address, which can result in null when resolving an address to a name using the method above.
For this reason, it is recommended to use the subgraph instead.
To perform reverse resolution (address to name):
Through Subgraph
For comprehensive reverse resolution, it's recommended to query the SNS subgraph. Here's how you can do that using TypeScript:
Common Pitfalls
- Incorrect Contract Addresses: Ensure you're using the correct SNS contract addresses for the Sanko chain.
- Name Normalization: SNS names should be normalized before querying or registering.
- Transaction Underpricing: Make sure to use the rentPrice function to get the total price for registration. This ensures you're sending enough value with the transaction.
- CommitmentTooNew Error: This error occurs when trying to register a name too soon after making a commitment.
References
Sanko Chain Definition
Since Viem does not include Sanko by default, you will need to define it yourself.