WDK logoWDK documentation

LayerSwap Swidge API Reference

Reference the LayerSwap source adapters, shared methods, result fields and errors.

Community modules are developed and maintained independently by third-party contributors.

Tether and the WDK Team do not endorse or assume responsibility for their code, security, or maintenance. Use your own judgment and proceed at your own risk.

Imports and construction

Each source package exports its adapter class as the default. The common methods below apply to all four adapters.

import LayerswapProtocolEvm, {
  LayerswapApiClient,
  ProviderError,
  SwidgeError
} from '@layerswap/wdk-protocol-swidge-layerswap-evm'

The other default classes are LayerswapProtocolSolana, LayerswapProtocolBitcoin and LayerswapProtocolTon from their corresponding source packages. Use new Protocol(account, config?) with the matching account. An omitted account supports discovery and explicit-fromChain quotes; sending requires a writable account with that adapter's capabilities.

Type-only imports are separate:

import type {
  LayerswapProtocolConfig,
  LayerswapSwidgeOptions,
  LayerswapSwidgeConfig
} from '@layerswap/wdk-protocol-swidge-layerswap-evm'

Main methods

MethodResultSide effects and constraints
quoteSwidge(options)Promise<SwidgeQuote>Exact-input quote without creating a provider swap. It does not validate recipient, refund address or minimum output. Source gas estimation can be omitted on failure.
swidge(options, config?)Promise<SwidgeResult>Creates a provider swap, prepares and sends the source deposit. Returns before destination settlement.
getSwidgeStatus(id, options?)Promise<SwidgeStatusResult>Reads the provider swap. Use the returned swap id, not its source hash.
getSupportedChains()Promise<SwidgeSupportedChain[]>Reads the cached provider catalog. Chain id is a provider network name.
getSupportedTokens(options?)Promise<SwidgeSupportedToken[]>Filters by toChain, otherwise fromChain; fromToken is ignored.
getTransactionStatus(hash, options?)Promise<LayerswapTransactionStatus>Returns { status }, where status is 'completed', 'failed' or 'pending'. TON first resolves its message hash through TON Center.
getApiClient()LayerswapApiClientReturns the raw client described below.

There is no implemented local simulation method in these adapters. Discovery is a catalog query, not a route-capability or liquidity check.

Swidge options

FieldMeaning
fromTokenRequired source token identifier. Prefer discovery's token field, which is a provider symbol.
toTokenDestination identifier required by the exported types. JavaScript runtime falls back to the source token's symbol when it is absent.
fromChainOptional provider source network name; otherwise detected from the account.
toChainOptional provider destination network name; omission selects the source network.
fromTokenAmountRequired exact-input base-unit integer. Use bigint for large values.
toTokenAmountUnsupported; supplying it rejects an exact-output request.
minAmountOutAccepted minimum in destination-token base units. Compared with the execution quote's minimum output.
slippageNon-negative finite fraction; 0.005 means 0.5%.
recipientDestination address. Fallback to the source account's address requires matching source/destination VM types.
refundAddressSource-network refund address; defaults to the source account address.
refuelOptional request for a destination native-gas drop.
referenceIdOptional reference for the provider swap.
feeRateBitcoin adapter only: fee rate in sat/vB.

Execution resolves fromChain and toChain by provider network name, even though some declarations admit numeric values. getSwidgeStatus() chain hints separately accept provider network names or chain IDs; getTransactionStatus() uses a provider network name for sourceChain. Use discovered names for operation options.

Token contract lookup recognizes a lowercase-0x prefix with 42 characters; other identifiers are matched as symbols. A non-EVM mint or contract address from the token's address metadata is not a universal accepted option value.

Constructor fields and per-call fee configuration are listed in Configuration. Amount and fee declarations use number | bigint; runtime conversion of integer options also accepts values convertible by BigInt. Prefer the declared types rather than depending on wider runtime coercion.

Quotes and execution results

FieldQuoteExecutionMeaning
fromTokenAmountYesYesSource-token base units. A preview uses the caller's requested amount.
toTokenAmountYesYesProvider-reported destination output in destination-token base units.
toTokenAmountMinYesYesProvider minimum, falling back to receive amount when absent in a quote.
feesYesYesItemized fees with their own token, chain and inclusion context.
estimatedDurationOptionalNoProvider completion-time estimate converted to seconds.
idNoYesProvider swap ID for settlement polling.
hashNoYesSource deposit hash; for TON, an external-message body hash.
transactionsNoYesInitially the source hash, chain and type: 'source'.

Execution with no quote in the create-swap response uses fees: [], toTokenAmount: 0n and toTokenAmountMin: 0n. A positive minimum output prevents broadcast in that case. Those placeholders are missing data, not independent verification of cost or settlement.

Each fee has type, amount and token, with optional chain, included and description. Included service/destination fees are in source-token units; separate source gas is in native units. See fee-limit behavior before interpreting a cap.

Status methods

getSwidgeStatus(id, { fromChain?, toChain? }) returns { status, transactions }. Hints constrain the lookup; a mismatch can produce NoSuchElementError.

The mapper recognizes action-required, pending, completed, failed, expired, cancelled, refund-pending and refunded. Unknown provider swap states fall back to pending. Do not interpret that fallback as proof the provider is making progress.

The first output transaction takes precedence when completed. Otherwise the first refund transaction determines refunded or refund-pending, and a non-completed first output is pending. Transactions without a hash are omitted; mapped transaction types are source, destination, refund and other.

getTransactionStatus(hash, { sourceChain? }) queries the source transaction separately and returns { status: 'completed' | 'failed' | 'pending' }. Read result.status, rather than comparing the whole result with a status string. NoSuchElementError can mean that the provider has not indexed it yet or that the lookup identifiers are wrong. See TON hash handling.

Swap and bridge adapters

Prefer the Swidge methods for new integrations. The explicit bridge adapter keeps the source hash in hash and returns the provider swap ID as swapId. Its fee is source gas in native units; bridgeFee is included provider cost in source-token units. Do not sum them across different assets.

bridge() and quoteBridge() take legacy fields: targetChain, recipient, token, amount, optional destinationToken, sourceChain, refundAddress, referenceId, refuel and percentage-string slippage. For 0.5%, Swidge takes 0.005 while bridge takes '0.5'.

bridge() and quoteBridge() wrap only SwidgeError as BridgeError; other errors pass through unchanged.

Inherited swap() and quoteSwap() are same-chain adapters. They use the provider swap ID as their hash and aggregate fee amounts, which does not preserve the full Swidge denomination breakdown.

Raw client

getApiClient() returns the same LayerswapApiClient instance used by the protocol. Its values are LayerSwap wire-format responses rather than WDK result shapes.

MethodHTTP requestPurpose
getNetworks()GET /api/v2/networksCached network/token catalog.
getQuote(params)GET /api/v2/quoteRead a prospective quote.
getSwap(swapId)GET /api/v2/swaps/{id}Read provider swap state.
getTransactionStatus(networkName, transactionId)GET /api/v2/transaction_statusRead source deposit assessment.
createSwap(params)POST /api/v2/swapsCreate a real provider swap.
speedUpDeposit(swapId, transactionId)POST /api/v2/swaps/{id}/deposit_speedupNotify the provider of a broadcast deposit.

The core package also exports pure mapping and unit-conversion helpers for adapter authors; they are separate from the protected protocol hooks.

The last two methods mutate provider state. Direct client calls bypass the protocol's route, amount, deposit and fee checks; they are not a replacement execution tutorial.

Errors

Import runtime error classes from the same adapter package used by your protocol.

ErrorCommon trigger
AccountRequiredErrorNo writable account for execution.
DisposalErrorThe bound account is disposed.
ValueErrorUnsupported exact-output request, invalid integer option, invalid route/network or missing required recipient.
InvalidTokenErrorToken lookup fails, or Bitcoin source is not native BTC.
ProviderRequiredErrorThe operation requires an account provider that is unavailable.
ProviderErrorAPI/RPC failure, malformed provider response or deposit instructions, or a wallet error normalized to provider failure. It can carry code, status and reason.
SwidgeErrorMinimum output is not met or a wallet error indicates insufficient funds.
MaximumFeeExceededErrorA provider fee guard or the source wallet's fee policy rejects the operation.
NoSuchElementErrorSwap/transaction is not found, not indexed yet, or does not match lookup hints.

A ValueError raised while selecting or preparing the provider's deposit instructions is normalized to ProviderError; it is not exposed as caller-input validation. A thrown error after source submission does not prove the deposit was absent; reconcile it before retrying.

Next Steps


Need Help?

On this page