Bonfida / sns-sdk

Solana Name Service SDKs monorepo
https://sns.id/
MIT License
34 stars 28 forks source link
python react rust solana typescript web3 web3-domains

SNS SDK



SNS SDK monorepo


🚧 This repository is in active development and is subject to changes 🚧



Table of contents


  1. SNS documentation
  2. Javascript
  3. Rust
  4. SDK Proxy
  5. Python
  6. Java
  7. Swift
  8. CLI
  9. React
  10. Vue
  11. Examples
  1. Bounties


SNS documentation


This repository contains the Developer documentation specifically for the SNS SDK. You can find the general SNS documentation at sns.guide


Javascript


yarn add @bonfida/spl-name-service
npm i @bonfida/spl-name-service

The JS SDK is the most complete SDK, it contains all the utils methods to interact with domain names as well as instruction builders to register domain names.


Rust


The Rust SDK provides everything you need for resolving domain ownership and records within the Solana Name Service (SNS)

The functions in this code are available in both blocking and non-blocking (asynchronous) versions. To use the blocking version one must enable the blocking feature.


SDK Proxy


The SDK proxy is a Cloudflare worker that proxies the JS SDK via REST calls. It's meant to be used if you are programming in a language that is not supported. It currently supports the following endpoints:

NOTE: All endpoints capable of performing RPC calls currently support an optional rpc query parameter for specifying a custom RPC URL. In the future, this parameter will become mandatory, and the Cloudflare worker will exclusively proxy calls to a specified custom RPC URL.

The SDK proxy is deployed at: https://sns-sdk-proxy.bonfida.workers.dev/


CLI


The CLI can be installed with:

cargo install sns-cli

The CLI has the following commands:

For instance

$ sns resolve bonfida solana.sol coinbase

+------------+----------------------------------------------+----------------------------------------------------------------------------------+
| Domain     | Owner                                        | Explorer                                                                         |
+------------+----------------------------------------------+----------------------------------------------------------------------------------+
| bonfida    | HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA | https://explorer.solana.com/address/HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA |
+------------+----------------------------------------------+----------------------------------------------------------------------------------+
| solana.sol | 3Wnd5Df69KitZfUoPYZU438eFRNwGHkhLnSAWL65PxJX | https://explorer.solana.com/address/3Wnd5Df69KitZfUoPYZU438eFRNwGHkhLnSAWL65PxJX |
+------------+----------------------------------------------+----------------------------------------------------------------------------------+
| coinbase   | 7sF2JumHpWiPjS3XtnQ8cKraTzzfcGSvQHcV3yTaPZ5E | https://explorer.solana.com/address/7sF2JumHpWiPjS3XtnQ8cKraTzzfcGSvQHcV3yTaPZ5E |
+------------+----------------------------------------------+----------------------------------------------------------------------------------+


Python


Work in progress


Java


Work in progress


Swift


Work in progress


React


This package contains a set of useful React hooks to help you build your perfect dApp. If you are interested in a hook that is not included in this package please open an issue to let us know!

npm i @bonfida/sns-react
yarn add @bonfida/sns-react


Vue


This package contains a set of useful Vue composables to help you build your perfect dApp. If you are interested in a composable that is not included in this package please open an issue to let us know!

npm i @bonfida/sns-vue
yarn add @bonfida/sns-vue

Demo app with an example of each composable usage.


Examples



Resolving a domain


The following examples show how to resolve the domain `bonfida.sol`: 1. With the JS SDK ```js const connection = new Connection(clusterApiUrl("mainnet-beta")); const owner = await resolve(connection, "bonfida"); expect(owner.toBase58()).toBe("HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA"); ``` 2. With the Rust SDK ```rust let client = RpcClient::new(std::env::var("RPC_URL").unwrap()); let res = resolve_owner(&client, "bonfida").await.unwrap(); assert_eq!(res, pubkey!("HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA")); ``` 3. With the CLI ```bash $ sns resolve bonfida +---------+----------------------------------------------+----------------------------------------------------------------------------------+ | Domain | Owner | Explorer | +---------+----------------------------------------------+----------------------------------------------------------------------------------+ | bonfida | HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA | https://explorer.solana.com/address/HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA | +---------+----------------------------------------------+----------------------------------------------------------------------------------+ ``` 4. With the Cloudflare worker ```bash GET https://sns-sdk-proxy.bonfida.workers.dev/resolve/bonfida ``` ```json { "s": "ok", "result": "HKKp49qGWXd639QsuH7JiLijfVW5UtCVY4s1n2HANwEA" } ``` 5. With the React SDK ```ts import { useConnection, useWallet } from "@solana/wallet-adapter-react"; import { useDomainOwner, useDomainsForOwner } from "@bonfida/sns-react"; export const Example = () => { const { connection } = useConnection(); const { publicKey, connected } = useWallet(); const { result } = useDomainOwner(connection, "bonfida"); // ... }; ```

Bounties


| Feature | Description | In progress | Completed | Bounty | | ------- | ----------------------------------------------------------------------------------- | ----------- | --------- | ------ | | Golang | Translate JS SDK into a robust, well-tested Golang SDK; high-quality code essential | ❌ | ❌ | ✅ | | Python | Translate JS SDK into a robust, well-tested Python SDK; high-quality code essential | ❌ | ❌ | ✅ | | Java | Translate JS SDK into a robust, well-tested Java SDK; high-quality code essential | ❌ | ❌ | ✅ | | Swift | Translate JS SDK into a robust, well-tested Swift SDK; high-quality code essential | ❌ | ❌ | ✅ |
_If you have any questions or suggestions, feel free to open an issue or pull request, or simply contact us at [@bonfida](https://twitter.com/bonfida). We're always here for a good chat about Solana and the decentralized web!_