Sound SDK
Getting Started

Sound SDK

Official Sound on-chain development tools for the JavaScript ecosystem leveraging Viem, with first-class support of TypeScript and ESM

Sound SDK Github repo

Sound.xyz SDK Next.js Usage Example

Install

@soundxyz/sdk @soundxyz/sdk

npm install @soundxyz/sdk

Peer Dependencies

Sound.xyz SDK requires the following peer dependencies to be installed:

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 ecosystem.

On client-side it can be used alongside web3 integrations that follow Viem like wagmi, 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.

Example

You can also visit our github.com/soundxyz Next.js example which contains more comprehensive examples on how you can interact with the Sound SDK

Editions

Please check Interacting with editions 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 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

api.ts
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 and Sound.xyz API.

  • Lanyard
lanyard.ts
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
api.ts
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))
// ...