Gasless Swaps
Overview
To enable gasless transactions in your swap process, you can add the gasless=true flag to the quotes request. This ensures that only transactions that can be executed without the user paying for gas are returned.
Key Flags
gasless=true: When set to true, this parameter ensures that all returned transactions (including both token approvals and swaps) can be executed without the end-user paying for gas fees. The gas costs will be covered by the protocol, creating a seamless user experience without requiring native tokens for transaction feesgaslessSwap=true: When set to true, this parameter guarantees that swap transactions will be executed without the end-user paying for gas fees. Unlike the gasless parameter, this option specifically focuses on making the swap operation gasless, while token approval transactions may or may not require gas payment depending on the specific tokens involved in the swap.
Workflow
Quote Request:
Include the
gasless=trueflag to get gasless (approval + swap) transaction quotes.Include
gaslessSwap=trueto get gasless transaction for swaps, but approvals may or may not require gas.
/createTx and /nextTx Calls:
Once you've received the quotes, make the
/createTxand/nextTxcalls as usual. The process for these calls remains the same.
Handling Gasless Transactions
Response from /nextTx and /createTx
/nextTx and /createTxThe response from both endpoints will contain a
gaslessfield.gasless: false: The transaction requires user gas. The user must sign and submit the transaction via RPC.gasless: true: The transaction is gasless, and you should make a/submitcall with the signed transaction data.
Gasless Transaction Process
For gasless transactions, the process differs slightly:
Transaction Data:
The transaction data for gasless transactions is different from standard transactions. It only needs to be signed by the user, not submitted to the network via RPC.
Signing the Transaction:
The user must sign the transaction using the provided
txnData(example signing process shared in the code snippet below).
Submit the Transaction:
Once signed, the transaction must be submitted to Blockend via the
/submitAPI.
Request Body for
/submitResponse Example from
/submitstatus: success: The signed transaction has been successfully submitted.status: in-progress: The transaction is still being processed. Wait for it to complete.
Waiting for Transaction Fulfilment
You can use the normal status check endpoint to monitor the status of the transaction. The key difference is that the txnHash field is not required, as the actual transaction hash is generated by Blockend.
Request Body for /status
/statusThe response will be similar to the one from a regular transaction, but the transaction hash is managed by Blockend.
Example TypeScript Code for Gasless Swap
Last updated
Was this helpful?