npm install @riftresearch/sdk
BTC → ERC20 Swap
import { RiftSdk, Currencies } from '@riftresearch/sdk'
// initialize SDK
const sdk = new RiftSdk({ integratorName: "sdk-demo" })
// get a quote
const { quote, executeSwap } = await sdk.getQuote({
from: Currencies.Bitcoin.BTC,
to: Currencies.Ethereum.CBBTC,
amount: '100000000', // 1 BTC (8 decimals)
mode: 'exact_input',
})
// execute the swap
const swap = await executeSwap({
refundAddress: 'bc1q...', // sending address
destinationAddress: '0xdeadbeef...', // receiving address
sendBitcoin: async ({ recipient, amountSats }) => {
// call your bitcoin wallet's transfer function here
},
})
// check status
const status = await sdk.getSwapStatus(swap.swapId)
console.log(`Status: ${status.status}`)
ERC20 → BTC Swap
import { RiftSdk, Currencies } from '@riftresearch/sdk'
import { createPublicClient, createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { ethereum } from 'viem/chains'
// initialize SDK
const sdk = new RiftSdk({ integratorName: "sdk-demo" })
// get a quote
const { quote, executeSwap } = await sdk.getQuote({
from: Currencies.Base.USDC,
to: Currencies.Bitcoin.BTC,
amount: '100000000', // 100 USDC (6 decimals)
mode: 'exact_input', // or 'exact_output'
})
// setup wallet clients for reading / writing to the EVM
const publicClient = createPublicClient({
chain: ethereum,
transport: http(process.env.ETH_RPC)
})
const walletClient = createWalletClient({
account: privateKeyToAccount('0x...'),
chain: ethereum,
transport: http(process.env.ETH_RPC)
})
// execute the swap
const swap = await executeSwap({
refundAddress: '0xdeadbeef...', // sending address
destinationAddress: 'bc1q...', // receiving address
publicClient,
walletClient,
onExecuteStep: async (type: ExecuteSwapStepType) => {
// either "approval", or "transaction"
// update app UI accordingly
},
})
// check status
const status = await sdk.getSwapStatus(swap.swapId)
console.log(`Status: ${status.status}`)
ERC20 → ERC20 Swaps
import { RiftSdk, Currencies, createCurrency } from '@riftresearch/sdk'
// same imports...
const sdk = new RiftSdk({ integratorName: "sdk-demo" })
// create a custom ERC-20
const pepe = createCurrency({
chainId: 1,
address: '0x6982508145454Ce325dDbE47a25d4ec3d2311933',
decimals: 18,
})
// get a quote
const { quote, executeSwap } = await sdk.getQuote({
from: Currencies.Ethereum.ETH,
to: pepe, // must be same chain as from asset
amount: '1000000000000000000', // 1 ETH (18 decimals)
mode: 'exact_input',
})
// setup wallet clients (same as above)
const publicClient = ...
const walletClient = ...
// execute the swap
const swap = await executeSwap({
refundAddress: '0xdeadbeef...', // sending address
destinationAddress: '0xdeadbeef...', // receiving address
publicClient,
walletClient,
onExecuteStep: async (type: ExecuteSwapStepType) => {
// either "approval", or "transaction"
// update app UI accordingly
},
})