Go from zero to a working swap integration in under 5 minutes. This guide covers quoting, connecting to the relayer, submitting a relayed transaction, and waiting for confirmation β all in one runnable example.
Prerequisites
A MultiversX wallet with an Ed25519 keypair
Enough EGLD in the wallet to cover gas fees (typically 0.05 EGLD for a swap)
Node.js 18+ with npm available
Step 1: Get a swap quote
The arb-algo API finds the optimal route across all supported DEXs and returns a ready-to-use transaction payload.
The response includes txData (base64 smart contract call payload), amountOut (expected output), and amountOutMin (minimum output after slippage). You use all three when building the transaction.
Amounts are always in the smallest unit of each token. WEGLD has 18 decimals (1000000000000000000 = 1 WEGLD). USDC has 6 decimals (42500000 = 42.5 USDC).
Step 2: Connect to the relayer and subscribe to gas stats
The relayer WebSocket streams per-shard gas statistics every 50ms. Subscribe before building the transaction to set a competitive gasPrice.
Step 3: Subscribe to tx-status before sending
Compute the transaction hash from the fully signed transaction and subscribe to tx-status/{hash} before sending the relay action. The event fires once and is never replayed β subscribing after the fact means missing it.
Step 4: Send the relay transaction
Send a relay action containing your signed transaction. The relayer validates shard alignment, appends its co-signature, and broadcasts to the MultiversX P2P network.
Then await the relay acknowledgment (broadcast confirmed) and the tx-status event (on-chain confirmed separately):
Complete Example
The following self-contained script performs a WEGLD β USDC swap using the arb-algo quote API and the relayer WebSocket. Install dependencies, add your wallet, and run it.