Sonic Name Service (SNS) SDK
JavaScript/TypeScript SDK for easy integration with Sonic Name Service - the decentralized domain name system for the Sonic blockchain.
Features
🚀 Simple Integration - Easy-to-use API for domain resolution and management
🔄 Unified Interface - Single point of access for all SNS functionality
⚡ Performance Optimized - Built-in caching and retry mechanisms
🛡️ Type Safe - Full TypeScript support with comprehensive type definitions
🔗 Batch Operations - Efficiently resolve multiple domains or addresses
📝 Record Management - Support for address, content, and text records
🎯 Error Handling - Detailed error types and clear error messages
Installation
Note: This SDK requires ethers.js v6. If you're using ethers v5, please upgrade to v6.
Quick Start
Configuration
API Reference
Resolution Methods
resolve(domain: string): Promise<string>
resolve(domain: string): Promise<string>
Resolve a domain name to an Ethereum address.
reverseResolve(address: string): Promise<string>
reverseResolve(address: string): Promise<string>
Reverse resolve an address to a domain name.
getContent(domain: string): Promise<string>
getContent(domain: string): Promise<string>
Get content hash for a domain.
getText(domain: string, key: string): Promise<string>
getText(domain: string, key: string): Promise<string>
Get text record for a domain.
Batch Operations
resolveBatch(domains: string[]): Promise<BatchResolutionResult>
resolveBatch(domains: string[]): Promise<BatchResolutionResult>
Resolve multiple domains in batches.
reverseResolveBatch(addresses: string[]): Promise<BatchReverseResolutionResult>
reverseResolveBatch(addresses: string[]): Promise<BatchReverseResolutionResult>
Reverse resolve multiple addresses in batches.
Domain Management
isAvailable(domain: string): Promise<boolean>
isAvailable(domain: string): Promise<boolean>
Check if a domain is available for registration.
getPrice(domain: string, years: number): Promise<PriceResult>
getPrice(domain: string, years: number): Promise<PriceResult>
Get registration price for a domain.
register(domain: string, years: number, signer: Signer): Promise<string>
register(domain: string, years: number, signer: Signer): Promise<string>
Register a new domain.
renew(domain: string, years: number, signer: Signer): Promise<string>
renew(domain: string, years: number, signer: Signer): Promise<string>
Renew an existing domain.
Record Management
setAddress(domain: string, address: string, signer: Signer): Promise<string>
setAddress(domain: string, address: string, signer: Signer): Promise<string>
Set the address record for a domain.
setText(domain: string, key: string, value: string, signer: Signer): Promise<string>
setText(domain: string, key: string, value: string, signer: Signer): Promise<string>
Set a text record for a domain.
setContent(domain: string, content: string, signer: Signer): Promise<string>
setContent(domain: string, content: string, signer: Signer): Promise<string>
Set content hash for a domain.
Utility Methods
getDomainInfo(domain: string): Promise<DomainRecord>
getDomainInfo(domain: string): Promise<DomainRecord>
Get comprehensive information about a domain.
validateDomain(domain: string): ValidationResult
validateDomain(domain: string): ValidationResult
Validate a domain name according to SNS rules.
Error Handling
The SDK provides detailed error types for better error handling:
Pricing
Domain pricing is based on length and registration duration:
3 characters: 15 S per year
4 characters: 10 S per year
5 characters: 7.5 S per year
6+ characters: 5 S per year
Multi-year Discounts
2 years: 5% discount
3 years: 10% discount
4 years: 15% discount
5 years: 20% discount
Text Record Keys
Common text record keys supported:
Advanced Usage
Custom Network Configuration
Cache Management
Custom Retry Configuration
Contract Addresses
Sonic Mainnet
Registry:
0x3D9D5ACc7dBACf1662Bc6D1ea8479F88B90b3cfb
Registrar:
0xc50DBB6F0BAab19C6D0473B225f7F58e4a2d440b
Resolver:
0x90DB11399F3577BeFbF5B8E094BcaD35DA348Fc9
Contributing
Fork the repository
Create your feature branch (
git checkout -b feature/your-feature
)Commit your changes (
git commit -m 'Add some amazing feature'
)Push to the branch (
git push origin feature/your-feature
)Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Support
Changelog
v1.0.0
Initial release
Basic resolution and registration functionality
Batch operations support
Comprehensive error handling
TypeScript support