Custom Contract Calls
The custom contract calls for the deposits
Custom Contract Calls
Custom contract calls allow you to execute additional smart contract operations after the deposit swap is completed. This enables advanced use cases like automatically staking tokens, providing liquidity, or interacting with any protocol contract—all within a single user transaction flow.
Purpose
Custom contract calls extend the Swapper deposit SDK to support complex DeFi workflows beyond simple token deposits. Common use cases include:
Staking: Automatically stake deposited tokens into a staking contract
Liquidity Provision: Deposit tokens into liquidity pools
Token Wrapping: Convert tokens (e.g., ETH to WETH)
Protocol Interactions: Interact with lending protocols, vaults, or any custom contract
The SDK handles the entire flow: swap → deposit → custom operations, all executed atomically in the user's transaction.
How It Works
User deposits funds using any supported method (crypto transfer, on-ramp, etc.)
Swapper routes and swaps to the destination token
Custom contract calls are executed in sequence
Final tokens are delivered to the recipient wallet
Each custom call is a ContractCall object that specifies:
callType: How to handle token amounts (exact amount vs. full balance)
target: The contract address to call
value: ETH value to send (usually "0" for ERC20 operations)
callData: Encoded function call data
payload: Additional data for balance encoding
Basic Example
TypeScript SDK (iframe)
Helper Functions
The SDK provides built-in helper functions for common ERC20 operations, eliminating the need for manual ABI encoding.
Exact Amount Functions
Use these when you know the exact amount to transfer:
approve(tokenAddress, spender, amount)
Approves a specific amount of tokens for spending.
transfer(tokenAddress, recipient, amount)
Transfers a specific amount of tokens.
transferFrom(tokenAddress, from, to, amount)
Transfers a specific amount from one address to another.
Full Balance Functions
Use these when you want to use the entire token balance (most common for post-swap operations):
approveBalance(tokenAddress, spender)
Approves the full token balance for spending.
transferBalance(tokenAddress, recipient)
Transfers the full token balance to a recipient.
Contract Call Types
Different call types determine how the SDK handles token amounts:
ContractCallType.DEFAULT (0)
ContractCallType.DEFAULT (0)Use exact amounts specified in callData. The SDK does not modify amounts.
ContractCallType.FULL_TOKEN_BALANCE (1)
ContractCallType.FULL_TOKEN_BALANCE (1)Uses the complete balance of a specified token. The SDK automatically replaces amount placeholders with the actual balance.
ContractCallType.FULL_NATIVE_BALANCE (2)
ContractCallType.FULL_NATIVE_BALANCE (2)Uses the complete native token (ETH) balance.
ContractCallType.COLLECT_TOKEN_BALANCE (3)
ContractCallType.COLLECT_TOKEN_BALANCE (3)Collects the accumulated token balance from previous operations.
Important Notes
Order Matters: Custom calls execute sequentially. Ensure approvals come before operations that require them.
Gas Estimation: Complex call chains may require more gas. The SDK handles estimation automatically.
Last updated