Swing Points Program is Live 🚀 Learn More →

Swing SDK Reference

SwingSDK

Example

import { SwingSDK } from '@swing.xyz/sdk';
 
const swingSDK = new SwingSDK();
await swingSDK.init();

Constructors

constructor()

new SwingSDK(options?): SwingSDK
Parameters
ParameterType
options?Options
Returns

SwingSDK

Accessors

api

get api(): Client

bridges

get bridges(): Required< Bridge >[]

chains

get chains(): Chain[]

contracts

get contracts(): Contract[]

isReady

get isReady(): boolean

project

get project(): undefined | ProjectConfig

projectId

get projectId(): undefined | string

rules

get rules(): Partial< Record< ChainSlug | "__any__", {fromTokens: TokenSymbol[]; rules: Partial< Record< TokenSymbol | "__any__", {rules: Partial< Record< ChainSlug | "__any__", {toTokens: TokenSymbol[];} > >; toChainSlugs: ChainSlug[];} > >;} > >

tokens

get tokens(): Required< Token > & {symbol: TokenSymbol;} & {symbol: string;}[]

wallet

get wallet(): object

Methods

claim()

claim(tx): Promise< void >

Claim a transaction

Parameters
ParameterType
txRequired< Pick< Transaction, "toTokenSymbol" | "fromUserAddress" | "toUserAddress" | "bridge" | "txId" | "fromChainSlug" | "toChainSlug" | "fromTokenSymbol" | "fromAmount" | "toAmount" | "fromChainTxHash" > > & {id: number;}
Returns

Promise< void >


continueTransfer()

continueTransfer(tx, stepResults?): Promise< void >

Continue an in-progress transfer

Parameters
ParameterType
txTransaction
stepResults?TransferStepResults
Returns

Promise< void >


getAvailableReceiveChains()

getAvailableReceiveChains(parameters): Chain[]

Get the available receive chains for the current SDK configuration

Parameters
ParameterType
parametersobject
parameters.fromChainSlugChainSlug
parameters.fromTokenSymbolTokenSymbol
Returns

Chain[]


getAvailableReceiveTokens()

getAvailableReceiveTokens(parameters): Token[]

Get the available receive tokens for the current SDK configuration

Parameters
ParameterType
parametersobject
parameters.fromChainSlugChainSlug
parameters.fromTokenSymbolTokenSymbol
parameters.toChainSlugChainSlug
Returns

Token[]


getAvailableSendChains()

getAvailableSendChains(): Chain[]

Get the available send chains for the current SDK configuration

Returns

Chain[]


getAvailableSendTokens()

getAvailableSendTokens(parameters): Token[]

Get the available send tokens for the current SDK configuration

Parameters
ParameterType
parametersobject
parameters.fromChainSlugChainSlug
Returns

Token[]


getAvailableStakingChains()

getAvailableStakingChains(parameters): Chain[]

Get the available chains that are configured for staking

Parameters
ParameterType
parametersobject
parameters.fromChainSlugChainSlug
Returns

Chain[]


getAvailableStakingTokens()

getAvailableStakingTokens(parameters): Token[]

Get the available staking tokens for the chain

Parameters
ParameterType
parametersobject
parameters.chainSlugChainSlug
Returns

Token[]


getBridge()

getBridge(bridgeSlug): undefined | Bridge

Get the available bridge

Parameters
ParameterType
bridgeSlugBridgeOrAggregator
Returns

undefined | Bridge


getChain()

getChain(chainSlug): undefined | Chain

Get the available chain

Parameters
ParameterType
chainSlugChainSlug
Returns

undefined | Chain


getChainRpcUrl()

getChainRpcUrl(chainSlug): undefined | string

Get an RPC URL for a chain

Parameters
ParameterType
chainSlugChainSlug
Returns

undefined | string


getChainsForProtocol()

getChainsForProtocol(protocol): undefined | Chain[]

Get available chains for protocol

Parameters
ParameterType
protocolProtocolType
Returns

undefined | Chain[]


getChainsForTransfer()

getChainsForTransfer(chainSlug): Chain[]

Get the available chains to transfer to from a chain

Parameters
ParameterType
chainSlugChainSlug
Returns

Chain[]


getContract()

getContract({ id }: { id: string }): Contract | undefined;

Get a specific contract

Parameters
ParameterType
contractobject
contract.idstring
Returns

Contract | undefined


getContractsForChain()

getContracts(parameters): Contract[]

Get the contracts for a specific chain

Parameters
ParameterType
parametersobject
parameters.chainSlugChainSlug
Returns

Contract[]


getContractsForChainToken()

getContractsForChainToken(parameters): Contract[]

Get the contracts for a specific chain and token

Parameters
ParameterType
parametersobject
parameters.chainSlugChainSlug
parameters.tokenSymbolTokenSymbol
Returns

Contract[]


getDefaultChainForProtocol()

getDefaultChainForProtocol(protocol): undefined | Chain

Get default chain for protocol

Parameters
ParameterType
protocolProtocolType
Returns

undefined | Chain


getNativeTokenForChain()

getNativeTokenForChain(chainSlug): undefined | Token

Get the chain's native currency token

Parameters
ParameterType
chainSlugChainSlug
Returns

undefined | Token


getPopularTokensForChain()

getPopularTokensForChain(chainSlug): Token[]

Get popular tokens for a chain

Parameters
ParameterType
chainSlugChainSlug
Returns

Token[]


getQuote()

getQuote(params, opts = {}): Promise< {debug: string[]; fromChain: Chain; fromToken: Token; routes: {distribution: {}; duration: number; gas: string; gasUSD: string; quote: {amount: string; amountUSD: string; bridgeFee: string; bridgeFeeInNativeToken: string; bridgeFeeInNativeTokenUSD: string; bridgeFeeUSD: string; decimals: number; fees: Fee[]; fromAmount: string;}; route: Route[];}[]; toChain: Chain; toToken: Token;} >

Get a list of routes for a specific transfer or contract call

Parameters
ParameterType
paramsTransferParams
optsobject
opts.signal?GenericAbortSignal
Returns

Promise< {debug: string[]; fromChain: Chain; fromToken: Token; routes: {distribution: {}; duration: number; gas: string; gasUSD: string; quote: {amount: string; amountUSD: string; bridgeFee: string; bridgeFeeInNativeToken: string; bridgeFeeInNativeTokenUSD: string; bridgeFeeUSD: string; decimals: number; fees: Fee[]; fromAmount: string;}; route: Route[];}[]; toChain: Chain; toToken: Token;} >


getStartingPair()

getStartingPair(): object

Gets a valid token pair for the current SDK configuration

Returns
fromChain
fromChain: undefined | Chain;
fromToken
fromToken: undefined | Token;
toChain
toChain: undefined | Chain;
toToken
toToken: undefined | Token;

getStepsForBridge()

getStepsForBridge(bridgeSlug): TransferStep[]

Get the required transfer steps for a bridge

Parameters
ParameterType
bridgeSlugBridgeOrAggregator
Returns

TransferStep[]


getTokenForChain()

getTokenForChain(chainSlug, tokenSymbol): undefined | Token

Get a specific token on a chain

Parameters
ParameterType
chainSlugChainSlug
tokenSymbolstring | string & {}
Returns

undefined | Token


getTokenForChainByAddress()

getTokenForChainByAddress(chainSlug, tokenAddress): undefined | Token

Get a specific token on a chain by address

Parameters
ParameterType
chainSlugChainSlug
tokenAddressstring
Returns

undefined | Token


getTokensForChain()

getTokensForChain(chainSlug): Token[]

Get tokens for a chain

Parameters
ParameterType
chainSlugChainSlug
Returns

Token[]


getValidContractsForChainToken()

getValidContractsForChainToken(parameters): Contract[] | undefined

Get the contract for a specific chain and token

Provide contractId to get a specific token, otherwise the first available token will be returned.

Parameters
ParameterType
parametersobject
parameters.chainSlugChainSlug
parameters.contractId?string
parameters.tokenSymbolTokenSymbol
Returns

Contract | undefined


getValidReceiveChain()

getValidReceiveChain(parameters): undefined | Chain

Get a valid chain for the receive side

Provide toChainSlug to get a specific chain, otherwise the first available chain will be returned.

Parameters
ParameterType
parametersobject
parameters.fromChainSlugChainSlug
parameters.fromTokenSymbolTokenSymbol
parameters.toChainSlug?ChainSlug
Returns

undefined | Chain


getValidReceiveToken()

getValidReceiveToken(parameters): undefined | Token

Get a valid token for the receive chain

Provide toTokenSymbol to get a specific token, otherwise the first available token will be returned.

Parameters
ParameterType
parametersobject
parameters.fromChainSlugChainSlug
parameters.fromTokenSymbolTokenSymbol
parameters.toChainSlugChainSlug
parameters.toTokenSymbol?TokenSymbol
Returns

undefined | Token


getValidSendChain()

getValidSendChain(parameters): undefined | Chain

Get a valid chain for the send side

Provide fromChainSlug to get a specific chain, otherwise the first available chain will be returned.

Parameters
ParameterType
parametersobject
parameters.fromChainSlug?ChainSlug
Returns

undefined | Chain


getValidSendToken()

getValidSendToken(parameters): undefined | Token

Get a valid token for the send chain.

Provide fromTokenSymbol to get a specific token, otherwise the first available token will be returned.

Parameters
ParameterType
parametersobject
parameters.fromChainSlugChainSlug
parameters.fromTokenSymbol?TokenSymbol
Returns

undefined | Token


getValidStakingChain()

getValidStakingChain(parameters): undefined | Chain

Get a valid staking chain.

Provide toChainSlug to get a specific chain, otherwise the first available chain will be returned.

Parameters
ParameterType
parametersobject
parameters.fromChainSlugChainSlug
parameters.toChainSlug?ChainSlug
Returns

undefined | Chain


getValidStakingToken()

getValidStakingToken(parameters): undefined | Token

Get a valid staking chain.

Provide toTokenSymbol to get a specific token, otherwise the first available token will be returned.

Parameters
ParameterType
parametersobject
parameters.toChainSlugChainSlug
parameters.toTokenSymbol?TokenSymbol
Returns

undefined | Token


getWallet()

getWallet(address): undefined | SwingWallet

Get the connected wallet for an address

Parameters
ParameterType
addressstring
Returns

undefined | SwingWallet


init()

init(): Promise< void >

Initialize the SDK

Returns

Promise< void >


isNativeToken()

isNativeToken(chainSlug, tokenSymbol): boolean

Checks if token is the chain's native token

Parameters
ParameterType
chainSlugChainSlug
tokenSymbolTokenSymbol
Returns

boolean


on()

on<P>(type, listener): () => void
  • READY the SDK is initialized and ready to be used
  • TRANSFER a transfer process step's status has updated
Type parameters
Parameter
P extends keyof EventMap
Parameters
ParameterType
typeP
listener(...args) => void
Returns
(): void
Returns

void


transfer()

transfer(transferRoute, transferParams): Promise< void >

Start the transfer process for the selected route

Parameters
ParameterTypeDescription
transferRouteobject-
transferRoute.distribution?object-
transferRoute.durationnumberAverage estimated length of time (in minutes) this transfer will take to complete
transferRoute.gasstringDEPRECATED - please see new fees return object. Gas limit for the deposit.
example:
4000000000
transferRoute.gasUSDstringDEPRECATED - please see new fees return object
transferRoute.quoteobject-
transferRoute.quote.amountstring-
transferRoute.quote.amountUSDstring-
transferRoute.quote.bridgeFeestringDEPRECATED - please see new fees return object
transferRoute.quote.bridgeFeeInNativeTokenstringDEPRECATED - please see new fees return object
transferRoute.quote.bridgeFeeInNativeTokenUSDstringDEPRECATED - please see new fees return object
transferRoute.quote.bridgeFeeUSDstringDEPRECATED - please see new fees return object
transferRoute.quote.decimalsnumber-
transferRoute.quote.feesFee[]Returns all fees associated with this quote and transfer. This includes gas and bridge fees (i.e liquidity, protocol, relayer and bonder). Every fee is also denominated in either the source, destination or source-native token. Fees are also converted to USD$ equivalents for convenience.
transferRoute.quote.fromAmount?string-
transferRoute.routeRoute[]-
transferParamsTransferParams-
Returns

Promise< void >


Bridge

Bridge: Omit< Required< Paths.V0TransferGetConfig.Responses.$200["bridges"][0] >, "steps" > & {steps: TransferStep[];}

Bridge.steps

steps: TransferStep[]

BridgeOrAggregator

BridgeOrAggregator: Components.Schemas.Bridge | Components.Schemas.Aggregator;

BridgeSlug

BridgeSlug: Components.Schemas.Bridge;

Chain

Chain: Components.Schemas.Chain;

ChainSlug

ChainSlug: Components.Schemas.ChainSlug;

ContractCallInfo

ContractCallInfo: Components.Schemas.ContractCallInfo;

Contract

interface Contract {
  id: string; // Unique Swing Identifier
  type: 'deposit' | 'withdraw';
  address: string; // Deployed contract address
  method: string; // Contract method (eg. deposit, withdraw)
  chain: string;
 
  inputToken: Token; // Token you send to the contract
  outputToken: Token | null; // Token you receive from the contract
 
  // Swing's integration provider
  integration: {
    type: 'staking';
    slug: string;
    name: string;
    logo: string;
    monetization: boolean;
  };
}

EventMap

EventMap: object;

Type declaration

READY

READY: () => void
Returns

void


TRANSFER

TRANSFER: (transferStepStatus, transferResults) => void
Parameters
ParameterType
transferStepStatusTransferStepResult
transferResultsTransferStepResults
Returns

void


Options

Options: object;

Type declaration

analytics

optional analytics: boolean

debug

optional debug: boolean

projectId

optional projectId: string

ProtocolType

ProtocolType: Components.Schemas.ProtocolType;

SupportedProtocols

SupportedProtocols: 'evm' | 'solana' | 'ibc' | 'multiversx';

Token

Token: Required< Components.Schemas.Token > & {symbol: TokenSymbol;}

Token.symbol

symbol: TokenSymbol;

TokenSymbol

TokenSymbol: Components.Schemas.TokenSymbol;

Transaction

Transaction: Components.Schemas.Transaction & Required< Pick< Components.Schemas.Transaction, "fromChainSlug" | "toChainSlug" | "fromTokenSymbol" | "toTokenSymbol" | "bridge" > > & {id: number; transferStatus: TransferStepStatus; transferStep: TransferStep;}

Transaction.id

id: number;

Transaction.transferStatus

optional transferStatus: TransferStepStatus

Transaction.transferStep

optional transferStep: TransferStep

TransactionStatus

TransactionStatus: Transaction['status'];

TransferParams

TransferParams: object;

Type declaration

amount

amount: string;

contractId

optional contractId: string

Identifier for the contract to use


fromChain

fromChain: ChainSlug;

fromToken

fromToken: TokenSymbol;

fromUserAddress

fromUserAddress: string;

toChain

toChain: ChainSlug;

toToken

toToken: TokenSymbol;

toUserAddress

toUserAddress: string;

TransferRoute

TransferRoute: Paths.V0TransferGetQuote.Responses.$200['routes'][0];

TransferStatus

TransferStatus: 'PENDING' | 'FAILED' | 'SUCCESS';

TransferStatusWithData

TransferStatusWithData: {status: "SUCCESS" | "PENDING" | "ACTION_REQUIRED" | "BRIDGING" | "CONFIRMING" | undefined;} | {error: string; status: "FAILED";} | {address: string; chain: Chain; status: "CHAIN_SWITCH_REQUIRED" | "WALLET_CONNECTION_REQUIRED"; token: Token;}

TransferStep

TransferStep: 'allowance' | 'approve' | 'send' | 'bridge' | 'sign' | 'claim';

TransferStepParams

TransferStepParams: object;

Type declaration

bridge

bridge: BridgeOrAggregator;

bridgeFee

optional bridgeFee: string
Deprecated

This property might no longer be used. Please use fees instead in the next API version.


bridgeFeeInNativeToken

optional bridgeFeeInNativeToken: string
Deprecated

This property might no longer be used. Please use fees instead in the next API version.


contractId

optional contractId: string

Identifier for the contract to use


fees

optional fees: Components.Schemas.Fee[]

fromChain

fromChain: Chain;

fromToken

fromToken: Token;

fromUserAddress

fromUserAddress: string;

route

route: Components.Schemas.Route[]

toAmount

toAmount: string;

toChain

toChain: Chain;

toToken

toToken: Token;

toUserAddress

toUserAddress: string;

tokenAmount

tokenAmount: string;

TransferStepResult

TransferStepResult: StepResult & TransferStatusWithData;

TransferStepResults

TransferStepResults: Record< TransferStep, TransferStepResult > & {id: number; status: TransferStatus;}

TransferStepResults.id

optional id: number

TransferStepResults.status

status: TransferStatus;

TransferStepStatus

TransferStepStatus: TransferStatus |
  'BRIDGING' |
  'CONFIRMING' |
  'ACTION_REQUIRED' |
  'CHAIN_SWITCH_REQUIRED' |
  'WALLET_CONNECTION_REQUIRED';

TransferStepStatusName

TransferStepStatusName: Components.Schemas.TransferStepStatus;

TransferTxData

TransferTxData: Components.Schemas.TransferTxData;

WalletProvider

WalletProvider: Web3Provider |
  ExternalProvider |
  JsonRpcFetchFunc |
  Keplr |
  CoinbaseWalletProvider |
  ExtensionProvider;