DocsShadeSwap SDK
ShadeSwap SDK
Privacy-first, ZK-powered swap infrastructure for JavaScript/TypeScript
shadeswap
Privacy-first, ZK-powered swap infrastructure
Version
0.0.3
License
MIT
Size
3.16 kB
Files
7
ShadeSwap enables non-custodial, anonymous asset swaps with zero traces and no logs. Built for developers who value privacy, security, and simplicity.
Installation
Install the SDK using your preferred package manager:
npm install shadeswapor
pnpm add shadeswapor
yarn add shadeswapQuick Start
import { ShadeSwap } from 'shadeswap'
// Initialize client (no API key needed for basic usage)
const shadeswap = new ShadeSwap()
// Get available currencies
const currencies = await shadeswap.getCurrencies()
console.log(currencies)
// Get exchange estimate
const estimate = await shadeswap.getEstimate({
fromCurrency: 'btc',
toCurrency: 'xmr',
fromAmount: 0.1
})
console.log(`You will receive: ${estimate.toAmount} XMR`)
// Create an exchange
const exchange = await shadeswap.createExchange({
fromCurrency: 'btc',
toCurrency: 'xmr',
fromAmount: 0.1,
address: 'your_xmr_address',
refundAddress: 'your_btc_address' // optional
})
console.log(`Send BTC to: ${exchange.depositAddress}`)
console.log(`Exchange ID: ${exchange.id}`)
// Check status
const status = await shadeswap.getExchangeStatus(exchange.id)
console.log(`Status: ${status.status}`)TypeScript Support
The SDK is written in TypeScript and includes full type definitions.
import {
ShadeSwap,
Currency,
Estimate,
Exchange,
ExchangeStatus
} from 'shadeswap'
const shadeswap = new ShadeSwap()
// All responses are fully typed
const currencies: Currency[] = await shadeswap.getCurrencies()
const estimate: Estimate = await shadeswap.getEstimate({
fromCurrency: 'btc',
toCurrency: 'eth',
fromAmount: 1
})
const exchange: Exchange = await shadeswap.createExchange({
fromCurrency: 'btc',
toCurrency: 'eth',
fromAmount: 1,
address: '0x...'
})
const status: ExchangeStatus = await shadeswap.getExchangeStatus(exchange.id)React Hook
For React applications, we provide a convenient hook:
import { useShadeSwap } from 'shadeswap/react'
function SwapComponent() {
const {
currencies,
estimate,
exchange,
createExchange,
isLoading,
error
} = useShadeSwap()
const handleSwap = async () => {
const result = await createExchange({
fromCurrency: 'btc',
toCurrency: 'xmr',
fromAmount: 0.1,
address: 'xmr_address'
})
console.log('Deposit to:', result.depositAddress)
}
return (
<button onClick={handleSwap} disabled={isLoading}>
{isLoading ? 'Creating...' : 'Create Swap'}
</button>
)
}Error Handling
import { ShadeSwap, ShadeSwapError } from 'shadeswap'
const shadeswap = new ShadeSwap()
try {
const exchange = await shadeswap.createExchange({
fromCurrency: 'btc',
toCurrency: 'xmr',
fromAmount: 0.0001, // Too small
address: 'invalid_address'
})
} catch (error) {
if (error instanceof ShadeSwapError) {
console.error(`Error code: ${error.code}`)
console.error(`Message: ${error.message}`)
switch (error.code) {
case 'AMOUNT_TOO_SMALL':
console.log('Please increase the amount')
break
case 'INVALID_ADDRESS':
console.log('Check the destination address')
break
default:
console.log('An error occurred')
}
}
}