Swing SDK Reference
SwingSDK
Example
Constructors
constructor()
Parameters
Parameter | Type |
---|---|
options ? | Options |
Returns
Accessors
api
bridges
chains
contracts
isReady
project
projectId
rules
tokens
wallet
Methods
claim()
Claim a transaction
Parameters
Parameter | Type |
---|---|
tx | Required < Pick < Transaction , "toTokenSymbol" | "fromUserAddress" | "toUserAddress" | "bridge" | "txId" | "fromChainSlug" | "toChainSlug" | "fromTokenSymbol" | "fromAmount" | "toAmount" | "fromChainTxHash" > > & {id : number ;} |
Returns
Promise
< void
>
continueTransfer()
Continue an in-progress transfer
Parameters
Parameter | Type |
---|---|
tx | Transaction |
stepResults ? | TransferStepResults |
Returns
Promise
< void
>
getAvailableReceiveChains()
Get the available receive chains for the current SDK configuration
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug | ChainSlug |
parameters.fromTokenSymbol | TokenSymbol |
Returns
Chain
[]
getAvailableReceiveTokens()
Get the available receive tokens for the current SDK configuration
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug | ChainSlug |
parameters.fromTokenSymbol | TokenSymbol |
parameters.toChainSlug | ChainSlug |
Returns
Token
[]
getAvailableSendChains()
Get the available send chains for the current SDK configuration
Returns
Chain
[]
getAvailableSendTokens()
Get the available send tokens for the current SDK configuration
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug | ChainSlug |
Returns
Token
[]
getAvailableStakingChains()
Get the available chains that are configured for staking
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug | ChainSlug |
Returns
Chain
[]
getAvailableStakingTokens()
Get the available staking tokens for the chain
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.chainSlug | ChainSlug |
Returns
Token
[]
getBridge()
Get the available bridge
Parameters
Parameter | Type |
---|---|
bridgeSlug | BridgeOrAggregator |
Returns
undefined
| Bridge
getChain()
Get the available chain
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
Returns
undefined
| Chain
getChainRpcUrl()
Get an RPC URL for a chain
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
Returns
undefined
| string
getChainsForProtocol()
Get available chains for protocol
Parameters
Parameter | Type |
---|---|
protocol | ProtocolType |
Returns
undefined
| Chain
[]
getChainsForTransfer()
Get the available chains to transfer to from a chain
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
Returns
Chain
[]
getContract()
Get a specific contract
Parameters
Parameter | Type |
---|---|
contract | object |
contract.id | string |
Returns
Contract | undefined
getContractsForChain()
Get the contracts for a specific chain
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.chainSlug | ChainSlug |
Returns
Contract[]
getContractsForChainToken()
Get the contracts for a specific chain and token
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.chainSlug | ChainSlug |
parameters.tokenSymbol | TokenSymbol |
Returns
Contract[]
getDefaultChainForProtocol()
Get default chain for protocol
Parameters
Parameter | Type |
---|---|
protocol | ProtocolType |
Returns
undefined
| Chain
getNativeTokenForChain()
Get the chain's native currency token
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
Returns
undefined
| Token
getPopularTokensForChain()
Get popular tokens for a chain
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
Returns
Token
[]
getQuote()
Get a list of routes for a specific transfer or contract call
Parameters
Parameter | Type |
---|---|
params | TransferParams |
opts | object |
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()
Gets a valid token pair for the current SDK configuration
Returns
fromChain
fromToken
toChain
toToken
getStepsForBridge()
Get the required transfer steps for a bridge
Parameters
Parameter | Type |
---|---|
bridgeSlug | BridgeOrAggregator |
Returns
getTokenForChain()
Get a specific token on a chain
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
tokenSymbol | string | string & {} |
Returns
undefined
| Token
getTokenForChainByAddress()
Get a specific token on a chain by address
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
tokenAddress | string |
Returns
undefined
| Token
getTokensForChain()
Get tokens for a chain
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
Returns
Token
[]
getValidContractsForChainToken()
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
Parameter | Type |
---|---|
parameters | object |
parameters.chainSlug | ChainSlug |
parameters.contractId ? | string |
parameters.tokenSymbol | TokenSymbol |
Returns
Contract | undefined
getValidReceiveChain()
Get a valid chain for the receive side
Provide toChainSlug
to get a specific chain, otherwise the first available chain will be returned.
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug | ChainSlug |
parameters.fromTokenSymbol | TokenSymbol |
parameters.toChainSlug ? | ChainSlug |
Returns
undefined
| Chain
getValidReceiveToken()
Get a valid token for the receive chain
Provide toTokenSymbol
to get a specific token, otherwise the first available token will be returned.
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug | ChainSlug |
parameters.fromTokenSymbol | TokenSymbol |
parameters.toChainSlug | ChainSlug |
parameters.toTokenSymbol ? | TokenSymbol |
Returns
undefined
| Token
getValidSendChain()
Get a valid chain for the send side
Provide fromChainSlug
to get a specific chain, otherwise the first available chain will be returned.
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug ? | ChainSlug |
Returns
undefined
| Chain
getValidSendToken()
Get a valid token for the send chain.
Provide fromTokenSymbol
to get a specific token, otherwise the first available token will be returned.
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug | ChainSlug |
parameters.fromTokenSymbol ? | TokenSymbol |
Returns
undefined
| Token
getValidStakingChain()
Get a valid staking chain.
Provide toChainSlug
to get a specific chain, otherwise the first available chain will be returned.
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.fromChainSlug | ChainSlug |
parameters.toChainSlug ? | ChainSlug |
Returns
undefined
| Chain
getValidStakingToken()
Get a valid staking chain.
Provide toTokenSymbol
to get a specific token, otherwise the first available token will be returned.
Parameters
Parameter | Type |
---|---|
parameters | object |
parameters.toChainSlug | ChainSlug |
parameters.toTokenSymbol ? | TokenSymbol |
Returns
undefined
| Token
getWallet()
Get the connected wallet for an address
Parameters
Parameter | Type |
---|---|
address | string |
Returns
undefined
| SwingWallet
init()
Initialize the SDK
Returns
Promise
< void
>
isNativeToken()
Checks if token is the chain's native token
Parameters
Parameter | Type |
---|---|
chainSlug | ChainSlug |
tokenSymbol | TokenSymbol |
Returns
boolean
on()
READY
the SDK is initialized and ready to be usedTRANSFER
a transfer process step's status has updated
Type parameters
Parameter |
---|
P extends keyof EventMap |
Parameters
Parameter | Type |
---|---|
type | P |
listener | (...args ) => void |
Returns
Returns
void
transfer()
Start the transfer process for the selected route
Parameters
Parameter | Type | Description |
---|---|---|
transferRoute | object | - |
transferRoute.distribution ? | object | - |
transferRoute.duration | number | Average estimated length of time (in minutes) this transfer will take to complete |
transferRoute.gas | string | DEPRECATED - please see new fees return object. Gas limit for the deposit. example: 4000000000 |
transferRoute.gasUSD | string | DEPRECATED - please see new fees return object |
transferRoute.quote | object | - |
transferRoute.quote.amount | string | - |
transferRoute.quote.amountUSD | string | - |
transferRoute.quote.bridgeFee | string | DEPRECATED - please see new fees return object |
transferRoute.quote.bridgeFeeInNativeToken | string | DEPRECATED - please see new fees return object |
transferRoute.quote.bridgeFeeInNativeTokenUSD | string | DEPRECATED - please see new fees return object |
transferRoute.quote.bridgeFeeUSD | string | DEPRECATED - please see new fees return object |
transferRoute.quote.decimals | number | - |
transferRoute.quote.fees | Fee [] | 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.route | Route [] | - |
transferParams | TransferParams | - |
Returns
Promise
< void
>
Bridge
Bridge.steps
BridgeOrAggregator
BridgeSlug
Chain
ChainSlug
ContractCallInfo
Contract
EventMap
Type declaration
READY
Returns
void
TRANSFER
Parameters
Parameter | Type |
---|---|
transferStepStatus | TransferStepResult |
transferResults | TransferStepResults |
Returns
void
Options
Type declaration
analytics
debug
projectId
ProtocolType
SupportedProtocols
Token
Token.symbol
TokenSymbol
Transaction
Transaction.id
Transaction.transferStatus
Transaction.transferStep
TransactionStatus
TransferParams
Type declaration
amount
contractId
Identifier for the contract to use
fromChain
fromToken
fromUserAddress
toChain
toToken
toUserAddress
TransferRoute
TransferStatus
TransferStatusWithData
TransferStep
TransferStepParams
Type declaration
bridge
bridgeFee
Deprecated
This property might no longer be used. Please use fees instead in the next API version.
bridgeFeeInNativeToken
Deprecated
This property might no longer be used. Please use fees instead in the next API version.
contractId
Identifier for the contract to use
fees
fromChain
fromToken
fromUserAddress
route
toAmount
toChain
toToken
toUserAddress
tokenAmount
TransferStepResult
TransferStepResults
TransferStepResults.id
TransferStepResults.status