Skip to content

Basic Usage

Viem
import { Symphony } from "symphony-sdk/viem";
import { walletClient } from "./walletClient";
 
// Get route for swapping 1 SEI to SEIYAN
const symphony = new Symphony()
const nativeAddress = symphony.getConfig().nativeAddress; //SEI
const seiyanAddress = '0x5f0e07dfee5832faa00c63f2d33a0d79150e8598' //SEIYAN
 
//Get wallet client
const [address] = await walletClient.requestAddresses();
 
//Make sure walletClient has address has a valid account property
//Connecting a wallet using connectors will automatically create a valid client
walletClient.account = { address };
 
 
symphony.connectWalletClient(walletClient);
 
const route = await symphony.getRoute(
  nativeAddress,
  seiyanAddress,
  "1.0"   // 1 SEI
);
 
console.log(`Expected output: ${route.amountOutFormatted} SEIYAN`);
 
const transaction = await route.swap({
  slippage:{
    slippageAmount:'1',
  }
});
 
console.log(`Transaction Hash: ${transaction.swapReceipt.transactionHash}`);

Trigger Approve and Swap

Viem
import { Symphony } from "symphony-sdk/viem";
import { walletClient } from "./walletClient";
 
// Get route for swapping 1 SEIYAN to SEI
const symphony = new Symphony()
const nativeAddress = symphony.getConfig().nativeAddress; //SEI
const seiyanAddress = '0x5f0e07dfee5832faa00c63f2d33a0d79150e8598' //SEIYAN
 
//Get wallet client
const [address] = await walletClient.requestAddresses();
 
//Make sure walletClient has address has a valid account property
//Connecting a wallet using connectors will automatically create a valid client
walletClient.account = { address };
 
 
symphony.connectWalletClient(walletClient);
 
const route = await symphony.getRoute(
  seiyanAddress,
  nativeAddress,
  "1.0"   // 1 SEI
);
 
console.log(`Expected output: ${route.amountOutFormatted} SEI`);
 
const transaction = await route.swap({
  slippage:{
    slippageAmount: '1', // 1%
  },
  //This options configuration will first request approval transaction if needed
  //then proceed to requesting swap transaction
  options: {
    skipApproval: false,
    skipCheckApproval: false,
  },
});
 
console.log(`Swap Transaction Hash: ${transaction.swapReceipt.transactionHash}`);
console.log(`Approve Transaction Hash: ${transaction.approveReceipt.transactionHash}`);