Overview
The Depository is a Layerswap-operated smart contract that acts as an on-chain entry point for funding a swap. Your wallet calls a single method on the Depository contract; it records the deposit, tags it with the identifier of your swap, and forwards the funds to the solver that fills it. Layerswap watches for the resultingDeposited event and progresses your swap automatically.
This is the recommended funding path when you are integrating Layerswap as an aggregator, or when
funding from a smart-contract wallet, server wallet, or any programmable wallet (e.g.
Privy, Safe, account-abstraction wallets).
Layerswap encodes the call for you. When you create a swap with
use_depository: true, the deposit
action includes the contract address (to_address) and the fully encoded call_data — so the
simplest path is to submit call_data as-is (plus a token approval for ERC20). The individual
arguments, including the swap id and receiver that Layerswap assigns, are also returned in
encoded_args if you’d rather build or verify the call yourself.use_depository: true and use_deposit_address: true is rejected.
Supported networks
- EVM chains where a Depository contract is deployed. Native and ERC20 deposits are both supported.
- Tron — TRC20 tokens only. Native TRX deposits via the Depository are not supported.
use_depository: true on a network that does not have a Depository deployed, swap
creation fails with an “unsupported depository” error. The set of enabled networks grows over time —
always rely on the to_address returned by the API rather than hard-coding addresses (see
Contract addresses).
How it works
- Create the swap with
use_depository: true. - Fetch the deposit actions (returned inline on swap creation, or via
GET /swaps/{swapId}/deposit_actions). The action’sto_addressis the Depository contract andcall_datais the encoded deposit call. - For ERC20 only: approve the Depository contract (
to_address) to spend the token amount. - Submit the transaction to
to_addresswith the returnedcall_data(andvaluefor native deposits — see below). - Layerswap detects the on-chain
Depositedevent, correlates it to your swap via the embeddedid, and completes delivery on the destination chain.
The contract
The Depository exposes two deposit methods:Using the Depository via the API
1. Create the swap
2. Read the deposit action
The response includes adeposit_actions array. For a Depository swap the relevant fields are:
| Field | Meaning |
|---|---|
to_address | The Depository contract address on the source chain — your transaction target and the ERC20 approval target |
call_data | The fully encoded depositNative / depositERC20 call — submit as-is |
amount / amount_in_base_units | For native deposits: the value to send (msg.value), in decimal and base units. For ERC20 deposits both are 0 |
token | The token being deposited (symbol, contract, decimals) |
fee_token | The gas asset on the network |
encoded_args | The individual decoded arguments, in order, for inspection |
gas_limit | Suggested gas limit |
order | Execution order when an action has multiple steps |
- ERC20 deposit
- Native deposit
amount is 0 (no native value is sent). The token and amount live inside
call_data / encoded_args, so you must approve first — see below.3. Approve (ERC20 only)
Before callingdepositERC20, approve the Depository contract (to_address) to spend the deposit
amount. Native deposits skip this step.
4. Submit the deposit transaction
- EVM (viem)
- Tron (TronWeb)
viem
Deposit detection
Theid argument encoded in call_data ties your on-chain deposit to your swap. Layerswap monitors
the Deposited event and matches its id back to your swap, then fills the destination side. From
this point the swap follows the normal swap lifecycle.
Contract addresses
The authoritative Depository address for a given swap is always theto_address returned in the
deposit action — read it per swap rather than caching a global value, since deployments are added
over time and a few chains use a different address.
Most EVM chains share a single deterministically-deployed Depository address. A small number of
chains (e.g. those where deterministic deployment wasn’t possible) use a chain-specific address. In
all cases, trust the API response.
Common errors
| Situation | What happens |
|---|---|
use_depository: true on a network with no Depository deployed | Swap creation fails (unsupported depository) |
use_depository: true and use_deposit_address: true | Rejected — the two methods are mutually exclusive |
ERC20 deposit without sufficient approval to to_address | On-chain revert; approve the Depository first |
Deposit to a receiver that isn’t the one Layerswap assigned | On-chain revert (NotWhitelisted); use the receiver from the deposit action |
Related
- Privy wallets recipe — end-to-end Depository flow with a Privy server wallet
- Get deposit actions — full response schema
- Deposit Widget — drop-in UI that handles this for you
- Security — Depository audit report