Skip to main content
This flow funds an ERC-20 Layerswap swap from a Privy server wallet. It creates a swap with use_depository: true, batches the token approval with the Depository call, and submits both through Privy’s gas sponsorship, so the wallet does not need native gas. See the full example on GitHub.

Prerequisites

Testnets are supported — use a testnet API key from the dashboard and get testnet funds from the Circle faucet.

Integration

1

Create a Layerswap swap

Create the swap with use_depository: true for the Privy wallet address:
use_depository: true is recommended when using Layerswap from a contract or a server wallet.
The response includes deposit_actions with everything needed for the on-chain calls:
2

Check allowance and build the call batch

For ERC-20 transfers, the wallet needs to approve the depository contract before the bridge call:
If allowance is already sufficient the approve call is skipped. Otherwise both calls are batched into a single sponsored wallet_sendCalls request.
3

Submit the sponsored transaction

Submit the batched calls with Privy wallet_sendCalls and sponsor: true:
Privy returns a transaction_id — poll privyClient.transactions().get(transactionId) until transaction_hash is available, then use it in the next step.
4

Check the swap status

After Privy returns the final chain transaction hash, look it up through Layerswap:
This maps the final transaction back to the Layerswap swap record. See Swap lifecycle & statuses for the state machine.