call_data is the hex-encoded transaction data. Submit it with the returned to_address and exact amount_in_base_units.
How the action differs by token
- For a native token,
to_addressis the deposit recipient,amount_in_base_unitsis the transaction value, andcall_datacontains the matching memo. - For an ERC-20 token,
to_addressis the token contract,amount_in_base_unitsis normally0, andcall_datacontains the encodedtransfer(address,uint256)call plus Layerswap’s matching data. The token amount is already encoded in the calldata. - For
manual_transfer,call_dataisnull; send the exact source asset to the generated address.
call_data.
Transaction construction
1
Parse the deposit action
Extract
call_data, to_address, amount_in_base_units, and network.chain_id from the deposit action.2
Build the transaction
Construct a transaction object with the deposit action fields mapped to standard EVM transaction parameters.
3
Estimate gas (optional)
Call
eth_estimateGas for a more accurate gas limit. If estimation fails, the transaction can still be sent without an explicit gas limit — the wallet or node will estimate it.4
Send the transaction
Sign and broadcast the transaction, then return the hash.
Full example
Pick the library that fits your stack. The viem and ethers.js tabs cover server-side or Node.js use; the wagmi tab is for browser use with a connected wallet.amount_in_base_units avoids float rounding and works for both native-token actions and ERC-20 actions whose native transaction value is zero.
When using a browser wallet, confirm the user is connected to action.network.chain_id and prompt a network switch before sending. For a manual ERC-20 action, call the token contract’s transfer function as in the viem and ethers.js examples instead of sending a transaction with empty data.
Funding via the Depository
The examples above cover the direct-transfer and deposit-address methods. If the swap was created withuse_depository: true, the deposit action targets the on-chain Depository contract instead — submit its call_data, and for ERC-20 approve the contract first:
viem