Sound SDK
Official Sound on-chain development tools for the JavaScript ecosystem leveraging Viem (opens in a new tab), with first-class support of TypeScript (opens in a new tab) and ESM (opens in a new tab)
Sound SDK Github repo (opens in a new tab)
Sound.xyz SDK Next.js Usage Example (opens in a new tab)
Install
@soundxyz/sdk
(opens in a new tab)
pnpm add @soundxyz/sdk
bun add @soundxyz/sdk
yarn add @soundxyz/sdk
npm install @soundxyz/sdk
Peer Dependencies
Sound.xyz SDK requires the following peer dependencies to be installed:
pnpm add viem zod
bun add viem zod
yarn add viem zod
npm install viem zod
Usage
This library is designed to be isomorphic, so that it can be used both on server-side or client-side leveraging the Viem (opens in a new tab) ecosystem.
On client-side it can be used alongside web3 integrations that follow Viem like wagmi (opens in a new tab), which allows connecting the user's wallet and using the contracts directly from the browsers.
On server-side it's required to use an ethereum network provider, we use and recommend Alchemy (opens in a new tab).
Example
You can also visit our github.com/soundxyz Next.js example (opens in a new tab) which contains more comprehensive examples on how you can interact with the Sound SDK
Editions
Please check Interacting with editions (opens in a new tab) for information on how to use the SDK with the different types of editions contracts of Sound Protocol
Sound.xyz API
The SDK provides direct connection with www.sound.xyz (opens in a new tab) API, which needs an API Key
. The usage is optional, but certain functions like extra information or processed indexed data will require it.
To get an API Key
contact us on our discord server discord.gg/soundxyz
(opens in a new tab)
import { SoundAPI } from '@soundxyz/sdk/api/sound'
// ...
const apiKey = process.env.SOUNDXYZ_API_KEY
if (!apiKey) throw Error('Missing sound API key')
export const soundAPI = SoundAPI({
apiKey,
})
Merkle Providers
When interacting with Merkle
aka Presale
it's required to specify a merkle provider while extending the viem instance.
Currently the SDK provides integrations with Lanyard (opens in a new tab) and Sound.xyz API.
- Lanyard
import { withMerkleProvider } from '@soundxyz/sdk'
import { LanyardMerkleProvider } from '@soundxyz/sdk/api/lanyard'
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
export const publicClient = createPublicClient({
chain: mainnet,
transport: http('...'),
}).extend(withMerkleProvider(LanyardMerkleProvider))
// ...
- Sound.xyz API
import { withMerkleProvider } from '@soundxyz/sdk'
import { SoundAPI } from '@soundxyz/sdk/api/sound'
import { createPublicClient, http } from 'viem'
import { mainnet } from 'viem/chains'
// ...
const apiKey = process.env.SOUNDXYZ_API_KEY
if (!apiKey) throw Error('Missing sound API key')
export const soundAPI = SoundAPI({
apiKey,
})
export const publicClient = createPublicClient({
chain: mainnet,
transport: http('...'),
}).extend(withMerkleProvider(soundAPI))
// ...