WDK logoWDK documentation

Orchestra API Reference

API reference for the Flashnet Orchestra community Swidge module.

API Reference

Package

import Orchestra, {
  OrchestraApiError,
  OrchestraError,
  OrchestraStateError,
  OrchestraSubmitError,
  OrchestraTimeoutError
} from 'wdk-protocol-swidge-orchestra'

The package exports Orchestra as both the default export and a named export.

Use the Flashnet Orchestra docs for provider-maintained route support, API concepts, and integration patterns outside the WDK package interface.

Class: Orchestra

Orchestra extends SwidgeProtocol from @tetherto/wdk-wallet/protocols.

Constructor

new Orchestra(account, config?)

Parameters:

  • account: IWalletAccount | IWalletAccountReadOnly | undefined
  • config: OrchestraConfig

Use undefined only for discovery or status flows that do not send source payments. Write flows require a WDK account with source-payment methods.

Swidge methods

MethodDescriptionReturns
quoteSwidge(options)Calls Orchestra estimate and returns a side-effect-free WDK Swidge quote.Promise<SwidgeQuote>
swidge(options, config?)Creates a quote, sends the source payment, submits the source transaction, and returns a WDK Swidge result.Promise<SwidgeResult>
getSwidgeStatus(id, options?)Reads an Orchestra order and maps the order status to WDK Swidge status.Promise<SwidgeStatusResult>
getSupportedChains()Reads Orchestra's route matrix and returns supported chains.Promise<SwidgeSupportedChain[]>
getSupportedTokens(options?)Reads supported tokens, optionally filtered by source chain, source token, or destination chain.Promise<SwidgeSupportedToken[]>

Production flow methods

MethodDescriptionReturns
prepareSwap(options, requestOptions?)Creates a durable Orchestra quote with deposit address and idempotency keys. Persist the returned intent before source payment.Promise<OrchestraSwapIntent>
executeSwapIntent(intentOrState, options?)Sends the source payment and submits the transfer id to Orchestra.Promise<OrchestraSwapState>
submitSourceTx(intentOrState, sourceTxHash, options?)Submits an already-sent source transaction without sending another source payment.Promise<OrchestraSwapState>
resumeSwap(state, options?)Reads status, submits an existing source transaction, or resumes a fresh source payment only when explicitly allowed.Promise<OrchestraSwapState | StatusResponse>
getOrderStatus(target)Reads status by order id, quote id, or source transaction hash.Promise<StatusResponse>
waitForCompletion(target, options?)Polls status until a terminal Orchestra order status or timeout.Promise<StatusResponse>
subscribeOrder(target, callbacks, options?)Opens an SSE status subscription and returns a closable subscription.OrderSubscription

quoteSwidge(options)

const quote = await orchestra.quoteSwidge({
  fromToken: 'spark:BTC',
  toToken: 'tron:USDT',
  fromTokenAmount: 7116n,
  recipient: 'TRecipient...',
  slippage: 0.01
})

quoteSwidge() calls the estimate endpoint. It does not reserve a deposit address and does not move funds.

swidge(options, config?)

const result = await orchestra.swidge({
  fromToken: 'spark:BTC',
  toToken: 'tron:USDT',
  fromTokenAmount: 7116n,
  recipient: 'TRecipient...'
}, {
  maxNetworkFeeBps: 20n,
  maxProtocolFeeBps: 100n
})

swidge() can send a source payment. Show confirmation first and persist state through onStateChange when using this path.

Options

OrchestraSwidgeOptions

FieldTypeDescription
fromTokenstringSource token, preferably chain-qualified such as spark:BTC or bsc:USDT.
toTokenstringDestination token, preferably chain-qualified.
fromChainstring | numberOptional source-chain override.
toChainstring | numberOptional destination-chain override.
recipientstringDestination recipient. Required when the destination is not the source account.
refundChainstringRefund chain for routes that need refund metadata.
refundAddressstringRefund address for routes that need refund metadata.
fromTokenAmountnumber | bigint | stringExact source amount. Do not pass with toTokenAmount.
toTokenAmountnumber | bigint | stringExact destination amount. Do not pass with fromTokenAmount.
slippagenumberDecimal slippage, for example 0.01 for 1%.
slippageBpsnumberSlippage in basis points.
idempotencyKeystringQuote idempotency key for prepareSwap().
submitIdempotencyKeystringSubmit idempotency key.
sourceTxHashstringExisting source transaction id to submit instead of sending a new payment.
sourceNetworkFeebigint | number | stringSource wallet fee for an existing source transaction.
sourceAddressstringSource wallet address used for submit metadata.
sourceSparkAddressstringSpark source address used for Spark submit metadata.
sourceTokenIdentifierstringPer-call Spark token identifier override when the app should not rely only on constructor-level sparkTokenIdentifiers.
sourceTokenAddressstringPer-call source token contract address override when the app should not rely only on constructor-level sourceTokenAddresses.
sourceTxVoutnumberBitcoin output index when needed for submit metadata.
feeRatenumber | bigintBitcoin source fee rate option.
confirmationTargetnumberBitcoin source confirmation target option.
broadcastTimeoutMsnumberBitcoin broadcast timeout.
allowNewSourcePaymentbooleanAllows resumeSwap() to send a fresh source payment. Use only after wallet-history recovery.
ignoreQuoteExpirybooleanBypasses quote expiry protection.
quoteExpirySafetyMsnumberPer-call quote expiry safety window.
appFeesAppFee[]App fee metadata passed to Orchestra.
affiliateIdstringAffiliate id metadata.
affiliateIdsstring[]Affiliate id metadata.

OrchestraConfig

See Configuration for the full constructor config. Common fields are apiKey, baseUrl, authMode, sourceChain, sourceTokenAddresses, sparkTokenIdentifiers, onStateChange, timeout settings, and retry settings.

OrchestraSwidgeStatusOptions

FieldTypeDescription
readTokenstringScoped client-key status token returned on submitted Orchestra state. Pass it to getSwidgeStatus(id, options?) when status reads do not use an admin key.

State objects

OrchestraSwapIntent

Returned by prepareSwap(). Persist it before calling executeSwapIntent().

Key fields:

  • version
  • quoteId
  • sourceChain
  • sourceAsset
  • destinationChain
  • destinationAsset
  • recipientAddress
  • amountMode
  • amountIn
  • estimatedOut
  • depositAddress
  • expiresAt
  • quoteIdempotencyKey
  • submitIdempotencyKey
  • createdAt

OrchestraSwapState

Returned after source payment, submit, or recovery steps. It extends OrchestraSwapIntent.

Additional key fields:

  • sourceTxHash
  • sourceNetworkFee
  • orderId
  • status
  • readToken
  • sourcePaymentStartedAt
  • fundedAt
  • submittedAt

Persist the full object, not only orderId. Recovery may need the quote id, deposit address, source transaction hash, read token, source chain, and idempotency keys.

Status mapping

getSwidgeStatus() maps Orchestra order statuses to WDK Swidge statuses:

Orchestra statusWDK Swidge status
processing or unknown in-flight statepending
completedcompleted
failedfailed
unfulfilledfailed
expiredexpired
refundedrefunded

Errors

All package-specific errors extend OrchestraError.

ErrorDescriptionUseful fields
OrchestraErrorBase package error.code, details
OrchestraApiErrorOrchestra returned an API error or invalid API response.code, status, details
OrchestraStateErrorInput state is incomplete, unsafe to resume, expired, or incompatible with the requested source payment.code, details
OrchestraSubmitErrorSource payment was sent, but submit, post-submit validation, or post-submit state persistence failed.state, cause
OrchestraTimeoutErrorHTTP request or wait operation timed out.code, details

Source repository tooling

The package repository includes a funded live-test harness. Those commands can move mainnet funds by default and are not required for normal WDK docs examples. Review the package repository before running them.

On this page