Use SNS (Solana Name Service)
The Use SNS tool, part of AgentiPy, allows users to interact with the Solana Name Service (SNS). It provides functionalities to resolve .sol domain names to their corresponding wallet addresses, get a user's favorite domain, retrieve all domains owned by a wallet, and get the transaction object needed to register a new SNS domain. These operations are performed using a QuickNode RPC URL that supports SNS methods.
Functionality
This tool is implemented in the NameServiceManager class. All methods are static and make direct JSON-RPC requests to a QuickNode RPC endpoint that supports SNS methods (configured in agent.quicknode_rpc_url).
Key Methods:
resolve_name_to_address(agent: SolanaAgentKit, domain: str) -> Optional[str]:Resolves an SNS
domain(e.g., "bonfida.sol") to the owner's Solana wallet address.Uses the
sns_resolveDomainRPC method.Returns the wallet address as a string, or
Noneif not found or an error occurs.
get_favourite_domain(agent: SolanaAgentKit, owner: str) -> Optional[str]:Retrieves the favorite domain name set by a specific
owneraddress.Uses the
sns_getFavouriteDomainRPC method.Returns the favorite domain name string or
None.
get_all_domains_for_owner(agent: SolanaAgentKit, owner: str) -> Optional[List[str]]:Fetches all
.soldomain names owned by a specificowneraddress.Uses the
sns_getAllDomainsForOwnerRPC method.Returns a list of domain name strings or
None. (The script currently types output asOptional[str], but RPC typically returns a list).
get_registration_transaction(agent:SolanaAgentKit, domain: str, buyer: str, buyer_token_account: str, space: int, mint: Optional[str] = None, referrer_key: Optional[str] = None) -> Optional[str]:Constructs the transaction needed to register a new
.soldomain name.Parameters:
domain: The domain name to register (e.g., "newdomain.sol").buyer: The Solana public key of the buyer's main wallet (pays for rent and transaction).buyer_token_account: The buyer's token account used for payment (typically USDC or BONK, depending on SNS registrar rules).space: The number of bytes to allocate for the domain name account.mint(Optional): The SPL token mint address used for payment (defaults to USDC if not specified, check SNS documentation for current valid mints).referrer_key(Optional): A referrer's public key, if any.
Uses the
sns_getRegistrationTransactionRPC method.Returns a base64-encoded string of the serialized transaction object. This transaction then needs to be signed and sent by the buyer.
Important Considerations:
QuickNode RPC: This tool specifically requires a QuickNode RPC URL that supports the Solana Name Service methods (e.g.,
sns_resolveDomain,sns_getRegistrationTransaction). This should be set inagent.quicknode_rpc_url.Direct API Interaction: It interacts directly with the specified Solana RPC endpoint (QuickNode). It does not use the Agentipy proxy service.
Domain Registration: The
get_registration_transactionmethod only returns the serialized transaction. The user (or agent) would then need to decode this, sign it with the buyer's wallet, and submit it to the network to complete the domain registration. This is an on-chain transaction with costs.Payment Mints: For domain registration, SNS typically uses specific SPL tokens like USDC or BONK for payment. The correct
buyer_token_accountandmint(if not default) must be used.
Source Code
You can find the source code for this tool on GitHub: https://github.com/niceberginc/agentipy/blob/main/agentipy/tools/use_sns.py
Last updated
