Understanding Gasless API
Description: Learn how 0x’s Gasless API works, including the terminology, mechanics, and how to implement gasless swaps and approvals in your app.
Why Use the Gasless API?
In typical Web3 flows, users must pay gas fees using the network’s native token (e.g., ETH, POL) during:
- Token approval – granting a contract permission to spend tokens.
- Swap execution – submitting the swap transaction itself.
This requirement increases onboarding friction—especially for new users without native tokens. The Gasless API removes that hurdle by allowing a relayer (e.g., 0x) to cover gas costs. Users can then complete swaps without needing the native token in their wallet.
How It Works
The Gasless API returns indicative prices and firm quotes for swaps. If the user accepts a quote, they sign an EIP-712 message authorizing:
- A gasless token approval (if supported), and/or
- The swap transaction itself.
0x then submits the signed data as a meta-transaction on-chain and pays the gas cost.
While “gasless” means no upfront gas from the user, gas is still consumed—just paid by a relayer like 0x. Gas fees are usually deducted from the input token (the token the user is selling).
Note: Gasless swaps work for all non-native ERC-20 tokens.
Supported Tokens
Gasless functionality is split into two categories:
Feature | Supported Tokens |
---|---|
Gasless Approvals | Tokens that support EIP-2612. Check supported tokens via the API endpoint. |
Gasless Swaps | Any non-native ERC-20 token. |
Key Concepts
Token Allowances
A token allowance lets a smart contract move a user’s tokens. For tokens that don’t support gasless approvals, the user must call approve()
themselves (gasful). See how to set token allowances.
For gasless flows, the user signs an EIP-712 message instead of broadcasting a transaction.
EIP-712: Typed Message Signing
EIP-712 enables human-readable signatures for structured data. Wallets can show users exactly what they're signing—crucial for both gasless approvals and gasless swaps.
EIP-2612: Gasless Approvals
EIP-2612 adds a permit()
method to ERC-20 tokens, allowing gasless approvals using an EIP-712 signature. This avoids needing an approve()
transaction.
Permit2
Permit2 is a smart contract by Uniswap that enables a universal allowance model:
- Deployed to
0x000000000022D473030F116dDEE9F6B43aC78BA3
on all chains. - Users approve Permit2 once, and it can then authorize other contracts (like 0x’s Settler) to transfer tokens on their behalf using a signed EIP-712 message.
Gasless Approvals
Supported if the token has permit()
(EIP-2612). The user signs an EIP-712 message to grant allowance. This is possible for tokens that support the Permit Extension (EIP-2612).
Gasless Transactions
User signs an EIP-712 message authorizing a swap. 0x pays gas and executes on-chain via metatransactions
Settler Metatransaction
Metatransactions are messages that authorize smart contracts to perform actions on your behalf.
Settler Metatransactions, settler_metatransaction
, represents a type of gasless transactions returned by the Gasless API /gasless/quote
endpoint. Settler Metatransaction leverages the Swap API to fetch indicative pricing and quotes. 0x submits these transactions to the blockchain on behalf of the user.
WETH Example
Let’s say the user wants to sell WETH:
- WETH does not support EIP-2612, so gasless approvals are not possible.
- However, gasless swaps are supported using an EIP-712 signature.
- First, set a token allowance for WETH (this requires gas).
- After Permit2 has spending permission, the user can sign an EIP-712 trade message to execute the swap without paying gas.
Technical Flow Diagrams
The Gasless API can be combined with the Swap API to provide flexible execution options. This allows for a seamless user experience where advanced users can choose to enable or disable Gasless execution without compromising their experience:
- Default to gasless trades when possible.
- Fallback to regular Swap API when:
- The token is native and unsupported for gasless.
- There’s not enough input token to cover relayer gas costs.
🔍 Try It Live
Want to explore this in a live app?
- 🧪 Try Matcha Auto: https://matcha.xyz
- 🎥 Watch the demo: YouTube – Matcha Auto