Butter Network
Github
  • 🌈About Butter Network
  • 🔥ZK Light Client
    • Understanding Light Client
    • Refactored ZK Light Client
  • 🔥Omnichain Development
    • Omnichain Isomorphism
    • More Possibilities
  • 🌈Butter Omnichain Messaging Integration
    • Introduction
    • Integration Guide
      • Message
      • Message with Ton
      • CALLDATA
      • Message And Relay
    • Contract Interface
    • Fee
    • Deployed Contracts
    • 👨‍💻API for Omnichain Message
      • GET Message History by Source Address
      • GET Message Info by Id
      • GET Message Info by Source Hash
  • 🔥Butter Bridge Integration
    • Integration Guide
    • Contract Interface
    • Fee
    • Deployed Contracts
  • 💰Butter Swap Integration
    • Introduction
    • 🟢Integration Guide
      • Contract Interface
      • Fee
    • Deployed Contracts
      • v2.1
    • 👩‍💻API for Routing
      • Integration Guide
      • GET /route
      • GET /swap
      • GET /routeAndSwap
      • GET /supportedChainList
      • GET /findToken
      • 🔴Error Code List
    • 👨‍💻API for Swap Data
      • GET Swap History by Source Hash
      • GET Swap History by Source Address
      • GET Swap Info by Order ID
      • GET Supported Chain Detail List
      • GET Supported Token Detail List
  • 💰Butter Swap User Guide
    • 🫂User Guide
  • Butter Swap SDK
    • Install
    • Config SDK
    • Request Routes
    • Execute Route
    • Others
  • Butter Swap Widget
    • Usage
  • 📢Resources
    • 🏠Website
    • 🫂Telegram
    • 📄X
Powered by GitBook
On this page
  • Setup SDK
  • Update SDK Configuration
  • Configure SDK Providers
  1. Butter Swap SDK

Config SDK

get started and set up Butter SDK .

Setup SDK

To get started, you need to set up configuration for the Butter SDK. This configuration contains the shared settings and data required for the proper functioning of other SDK features that developers will use. Additionally, the configuration can be updated later as needed.

Config rpcs

import { butterConfig, ChainType } from "@butternetwork/sdk";

butterConfig.setOptions({
  providers: [],
  rpcs: {
    [ChainType.NEAR]: ["https://near-example.node.com/"],
    [ChainType.SOLANA]: ["https://solana-example.node.com/"],
    [ChainType.TRON]: {
      urls: ["https://api.trongrid.io"],
      headers: {
        "TRON-PRO-API-KEY": "your-api-key",
      },
    },
    [ChainType.TON]: [],
  },
});

Update SDK Configuration

To update the configuration, you need to import the global configuration object and use its methods.

import { butterConfig } from "@butternetwork/sdk";

butterConfig.setOptions({
  // ...options
});

Configure SDK Providers

The SDK offers EVM , Solana , TRON , TON and NEAR providers, all with similar configuration options respective to their ecosystems.

Config EVM

The EVM provider execution logic is built based on the Viem library, using some of its types and terminology.

Options available for configuring the EVM provider:

  • walletClient: a signer object that implements the WalletClient interface.

import { useWalletClient } from "wagmi";

const { data: signer } = useWalletClient();

useEffect(() => {
  butterConfig.setOptions({
    providers: [
      createEvmProvider({
        walletClient: signer as any,
      }),
    ],
  });
}, [signer]);

Config Near

The Near provider execution logic is built based on the @near-wallet-selector/core library, using some of its types and terminology.

Options available for configuring the Near provider:

  • getWallet : a function that returns a wallet object.

import { setupWalletSelector } from "@near-wallet-selector/core";

const selector = await setupWalletSelector({
  network: nearConfig.networkId as NetworkId,
  debug: true,
  modules: [
    // ...modules
  ],
});

useEffect(() => {
  selector.wallet().then((wallet) => {
    butterConfig.setOptions({
      providers: [
        createNearProvider({
          getWallet: async () => wallet as any,
        }),
      ],
    });
  });
}, [selector]);

Config Solana

The Solana provider execution logic is built based on the @solana/web3.js and @solana/wallet-adapter-base libraries, using some of its types and terminology.

Options available for configuring the SOLANA provider:

  • getWalletAdapter: a function that returns a wallet adapter object.

import { useWallet } from "@solana/wallet-adapter-react";

const { wallet } = useWallet();

useEffect(() => {
  butterConfig.setOptions({
    providers: [
      createSolanaProvider({
        getWalletAdapter: async () => wallet?.adapter as any,
      }),
    ],
  });
}, [wallet]);

Config Tron

The Tron provider execution logic is built based on the @tronweb3/tronwallet-adapters library, using some of its types and terminology.

Options available for configuring the SOLANA provider:

  • getAdapter: a function that returns a wallet adapter object.

import { useWallet as useTronWallet } from "@tronweb3/tronwallet-adapter-react-hooks";

const { wallet: tronWallet } = useTronWallet();

useEffect(() => {
  butterConfig.setOptions({
    providers: [
      createTronProvider({
        getAdapter: async () => tronWallet?.adapter as any,
      }),
    ],
  });
}, [tronWallet]);

Config Ton

The Ton provider execution logic is built based on the @tonconnect/ui-react library, using some of its types and terminology.

Options available for configuring the TON provider:

  • getConnector: a function that returns a TonConnectUI object.

import { useTonConnectUI } from "@tonconnect/ui-react";

const [tonConnectUI, setOptions] = useTonConnectUI();
useEffect(() => {
  if (!tonConnectUI) {
    return;
  }
  butterConfig.setOptions({
    providers: [
      createTonProvider({
        getConnector: async () => tonConnectUI as any,
      }),
    ],
  });
}, [tonConnectUI]);
PreviousInstallNextRequest Routes

Last updated 4 months ago