Overview
In this quickstart, you’ll execute a cross-chain swap that transfers 0.1 USDC from Polygon to Arbitrum. This example demonstrates the complete flow: creating an order, approving token spending, and submitting the bridge transaction.Before you begin: Make sure you’ve completed the environment setup and have a small amount of USDC on Polygon plus MATIC for gas fees.
What you’ll learn
By the end of this guide, you’ll understand how to:- Create a cross-chain order using the deBridge API
- Handle ERC-20 token approvals
- Submit bridge transactions and track them on block explorers
- Parse order estimations for fees and expected output
Run your first swap
Monitor your transaction
The script outputs Polygonscan links for both transactions:
- Approval transaction: Allows deBridge to spend your USDC
- Bridge transaction: Initiates the cross-chain transfer
Track order fulfillment
Cross-chain transfers take 1-10 minutes depending on network conditions. Track your order on the deBridge Explorer using your wallet address or transaction hash.
Understanding the code
Let’s break down what theexample-swap.ts script does:
1. Load configuration and connect to providers
.env, then creates provider connections and a wallet signer.
2. Construct the order parameters
Token amounts must be in atomic units (smallest denomination). USDC has 6 decimals, so 0.1 USDC = 100,000 atomic units. Use
ethers.parseUnits("0.1", 6) to convert.3. Create the order via deBridge API
createDebridgeBridgeOrder function calls:
tx: Transaction object ready to submitestimation: Expected input/output amounts and fees
4. Approve token spending
Before deBridge can transfer your USDC, you must approve the spending:5. Submit the bridge transaction
Once approved, submit the bridge transaction:Order parameters explained
Here are the key parameters you’ll use in every deBridge order:| Parameter | Type | Description | Example |
|---|---|---|---|
srcChainId | string | Source chain ID | "137" (Polygon) |
srcChainTokenIn | string | Input token address | "0x3c499c542cEF5E..." (USDC) |
srcChainTokenInAmount | string | Input amount in atomic units | "100000" (0.1 USDC) |
dstChainId | string | Destination chain ID | "42161" (Arbitrum) |
dstChainTokenOut | string | Output token address | "0xaf88d065e77c8c..." (USDC) |
dstChainTokenOutRecipient | string | Recipient address | "0x742d35Cc663..." |
account | string | Sender address | "0x742d35Cc663..." |
srcChainOrderAuthorityAddress | string | Who can cancel the order | "0x742d35Cc663..." |
Optional parameters
Optional parameters
Authority addresses
Authority addresses
Understanding fees
Understanding fees
The Fees cover:
estimation object shows all fees:- deBridge protocol fee
- Market maker rewards
- Operating expenses (gas on destination)
Customize the example
Modify the script to try different scenarios:Common issues
Error: insufficient funds for intrinsic transaction cost
Error: insufficient funds for intrinsic transaction cost
You don’t have enough MATIC for gas fees. Get at least 0.01 MATIC from an exchange:
- Buy on Polygon Bridge
- Transfer from Coinbase/Binance
Error: ERC20: transfer amount exceeds balance
Error: ERC20: transfer amount exceeds balance
You don’t have enough USDC on Polygon. Check your balance:Get USDC by:
- Bridging from another chain
- Swapping MATIC for USDC on a DEX
Error: Source and destination chains must differ
Error: Source and destination chains must differ
You can’t swap on the same chain using the cross-chain API. For same-chain swaps, see
/src/scripts/same-chain/ examples.Transaction takes a long time
Transaction takes a long time
Cross-chain transfers typically complete in 1-10 minutes but can take longer during:
- High network congestion
- Low liquidity periods
- Source or destination chain issues
How to get testnet tokens?
How to get testnet tokens?
These examples run on mainnet only. deBridge’s liquidity network operates on production chains. Use minimal amounts for testing:
- Start with 0.1 USDC transfers
- Keep $5-10 in tokens for multiple tests
Next steps
Explore more examples
Browse 20+ examples including Solana, TRON, hooks, and affiliate programs
Query order status
Learn how to track and manage orders programmatically
Add hooks
Execute custom logic after transfers, like supplying to Aave
API reference
Explore the complete deBridge API documentation