Gas-less transactions
Execute swap and bridge transactions without paying gas
The gas-less flow allows users to delegate execution of a transaction and to pay native fees by reserving part of the sent token. The LI.FI API exposes a beta endpoint to this endeavor.
This flow relies on Uniswap's permit2 contracts, which ensures that any ERC20 token can be used.
The steps required for this flow are as follows:
Request a quote
Simply hit the https://gasless.li.quest/v1/quote
endpoint on the dedicated API. Full OpenAPI specs for the endpoint are documented here.
const quote = await axios.post('https://gasless.li.quest/v1/quote',
{
fromChain: 'POL',
fromAmount: '1000000',
fromToken: 'USDC',
fromAddress: '0xb9c0dE368BECE5e76B52545a8E377a4C118f597B',
toToken: 'DAI',
toChain: 'POL'
}
)
This will result in a payload containing two top level keys: quote
and approvalTxs
```json
{
"status": "ok",
"data": {
"quote": {
"tokenOwner": "0xb9c0dE368BECE5e76B52545a8E377a4C118f597B",
"chainId": 137,
"permit": {
"permitted": {
"token": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"amount": "1000000"
},
"spender": "0x3ed258d94ffa1ccd9a5f0be6caff0045a5ae77e1",
"nonce": "7972148125609682451282810309151349552129999784086241067130974562985159910553",
"deadline": 1724651525425
},
"witness": {
"witnessType": {
"Witness": [
{
"type": "address",
"name": "tokenReceiver"
},
{
"type": "address",
"name": "diamondAddress"
},
{
"type": "bytes32",
"name": "diamondCalldataHash"
}
]
},
"witnessTypeName": "Witness",
"witness": {
"tokenReceiver": "0x3ed258d94ffa1ccd9a5f0be6caff0045a5ae77e1",
"diamondAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
"diamondCalldataHash": "0xe69b787fa1f1ad4cbea66cdd15f66688f83a92c91389d058d8db01dd3f4d88cc"
}
},
"permitData": {
"domain": {
"name": "Permit2",
"chainId": 137,
"verifyingContract": "0x000000000022D473030F116dDEE9F6B43aC78BA3"
},
"types": {
"PermitWitnessTransferFrom": [
{
"type": "TokenPermissions",
"name": "permitted"
},
{
"type": "address",
"name": "spender"
},
{
"type": "uint256",
"name": "nonce"
},
{
"type": "uint256",
"name": "deadline"
},
{
"type": "Witness",
"name": "witness"
}
],
"TokenPermissions": [
{
"type": "address",
"name": "token"
},
{
"type": "uint256",
"name": "amount"
}
],
"Witness": [
{
"type": "address",
"name": "tokenReceiver"
},
{
"type": "address",
"name": "diamondAddress"
},
{
"type": "bytes32",
"name": "diamondCalldataHash"
}
]
},
"values": {
"permitted": {
"token": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"amount": "1000000"
},
"spender": "0x3ed258d94ffa1ccd9a5f0be6caff0045a5ae77e1",
"nonce": "7972148125609682451282810309151349552129999784086241067130974562985159910553",
"deadline": 1724651525425
}
},
"step": {
"id": "d315ad3b-5dbc-46a3-ad66-6c6ee31b03ad:0",
"type": "lifi",
"tool": "lifidexaggregator",
"toolDetails": {
"key": "lifidexaggregator",
"name": "LI.FI DEX Aggregator",
"logoURI": "https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/exchanges/lifidexaggregator.svg"
},
"integrator": "lifigasless",
"action": {
"fromChainId": 137,
"fromAmount": "1000000",
"fromToken": {
"address": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"chainId": 137,
"symbol": "USDC",
"decimals": 6,
"name": "USD Coin",
"coinKey": "USDC",
"logoURI": "https://static.debank.com/image/coin/logo_url/usdc/e87790bfe0b3f2ea855dc29069b38818.png",
"priceUSD": "0.9996001599360256"
},
"fromAddress": "0xb9c0dE368BECE5e76B52545a8E377a4C118f597B",
"toChainId": 137,
"toToken": {
"address": "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
"chainId": 137,
"symbol": "DAI",
"decimals": 18,
"name": "(PoS) DAI Stablecoin",
"coinKey": "DAI",
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeAC495271d0F/logo.png",
"priceUSD": "0.9998"
},
"toAddress": "0xb9c0dE368BECE5e76B52545a8E377a4C118f597B",
"slippage": 0.005
},
"estimate": {
"tool": "lifidexaggregator",
"fromAmount": "1000000",
"fromAmountUSD": "1.00",
"toAmount": "959481608953993728",
"toAmountMin": "954684200909223759",
"toAmountUSD": "0.96",
"approvalAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
"feeCosts": [
{
"name": "LIFI Fixed Fee",
"description": "Fixed LIFI fee, independent of any other fee",
"percentage": "0.0403",
"token": {
"address": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"chainId": 137,
"symbol": "USDC",
"decimals": 6,
"name": "USD Coin",
"coinKey": "USDC",
"logoURI": "https://static.debank.com/image/coin/logo_url/usdc/e87790bfe0b3f2ea855dc29069b38818.png",
"priceUSD": "0.9996001599360256"
},
"amount": "40304",
"amountUSD": "0.04",
"included": true
}
],
"gasCosts": [
{
"type": "SEND",
"price": "30000000047",
"estimate": "501663",
"limit": "752495",
"amount": "15049890023578161",
"amountUSD": "0.01",
"token": {
"address": "0x0000000000000000000000000000000000000000",
"chainId": 137,
"symbol": "MATIC",
"decimals": 18,
"name": "MATIC",
"coinKey": "MATIC",
"logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
"priceUSD": "0.4382"
}
}
],
"executionDuration": 30
},
"transactionRequest": {
"to": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
"from": "0xb9c0dE368BECE5e76B52545a8E377a4C118f597B",
"gasLimit": "0xb7b6f",
"gasPrice": "0x6fc23ac2f",
"data": "0x5fd9ae2eabbcae9654f35f3f088d2123adfc24911c911061c0d9d14bafbaa72b8dcde92000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000100000000000000000000000000b9c0de368bece5e76b52545a8e377a4c118f597b0000000000000000000000000000000000000000000000000d3fb838fbdf374f0000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000000b6c6966696761736c657373000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002a307830303030303030303030303030303030303030303030303030303030303030303030303030303030000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000bd6c7b0d2f68c2b7805d88388319cfb6ecb50ea9000000000000000000000000bd6c7b0d2f68c2b7805d88388319cfb6ecb50ea90000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c33590000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c335900000000000000000000000000000000000000000000000000000000000f424000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000084eedd56e10000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c33590000000000000000000000000000000000000000000000000000000000009d700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000b9c0de368bece5e76b52545a8e377a4c118f597b0000000000000000000000000000000000000000000000000000000000000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202e00000000000000000000000046b3fdf7b5cde91ac049936bf0bdb12c5d22202e0000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c33590000000000000000000000008f3cf7ad23cd3cadbd9735aff958023239c6a06300000000000000000000000000000000000000000000000000000000000ea4d000000000000000000000000000000000000000000000000000000000000000e0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001442646478b0000000000000000000000003c499c542cef5e3811e1192ce70d8cc03d5c335900000000000000000000000000000000000000000000000000000000000ea4d00000000000000000000000008f3cf7ad23cd3cadbd9735aff958023239c6a0630000000000000000000000000000000000000000000000000d3fb838fbdf374f0000000000000000000000001231deb6f5749ef6ce6943a275a1d3e7486f4eae00000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000042023c499c542cef5e3811e1192ce70d8cc03d5c335901ffff01bc8f3da0bd42e1f2509cd8671ce7c7e5f7fd39c8011231deb6f5749ef6ce6943a275a1d3e7486f4eae00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"value": "0x0",
"chainId": 137
},
"includedSteps": [
{
"id": "8cf07752-8dc1-464d-b321-0a69a30c1f2f",
"type": "protocol",
"tool": "feeCollection",
"toolDetails": {
"key": "feeCollection",
"name": "Integrator Fee",
"logoURI": "https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/protocols/feeCollection.png"
},
"action": {
"fromChainId": 137,
"fromAmount": "1000000",
"fromToken": {
"address": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"chainId": 137,
"symbol": "USDC",
"decimals": 6,
"name": "USD Coin",
"coinKey": "USDC",
"logoURI": "https://static.debank.com/image/coin/logo_url/usdc/e87790bfe0b3f2ea855dc29069b38818.png",
"priceUSD": "0.9996001599360256"
},
"fromAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
"toChainId": 137,
"toToken": {
"address": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"chainId": 137,
"symbol": "USDC",
"decimals": 6,
"name": "USD Coin",
"coinKey": "USDC",
"logoURI": "https://static.debank.com/image/coin/logo_url/usdc/e87790bfe0b3f2ea855dc29069b38818.png",
"priceUSD": "0.9996001599360256"
},
"toAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
"slippage": 0.005
},
"estimate": {
"tool": "feeCollection",
"fromAmount": "1000000",
"toAmount": "959696",
"toAmountMin": "959696",
"approvalAddress": "0xbD6C7B0d2f68c2b7805d88388319cfB6EcB50eA9",
"feeCosts": [
{
"name": "LIFI Fixed Fee",
"description": "Fixed LIFI fee, independent of any other fee",
"percentage": "0.0403",
"token": {
"address": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"chainId": 137,
"symbol": "USDC",
"decimals": 6,
"name": "USD Coin",
"coinKey": "USDC",
"logoURI": "https://static.debank.com/image/coin/logo_url/usdc/e87790bfe0b3f2ea855dc29069b38818.png",
"priceUSD": "0.9996001599360256"
},
"amount": "40304",
"amountUSD": "0.04",
"included": true
}
],
"gasCosts": [
{
"type": "SEND",
"price": "30000000047",
"estimate": "130000",
"limit": "195000",
"amount": "3900000006110000",
"amountUSD": "0.01",
"token": {
"address": "0x0000000000000000000000000000000000000000",
"chainId": 137,
"symbol": "MATIC",
"decimals": 18,
"name": "MATIC",
"coinKey": "MATIC",
"logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
"priceUSD": "0.4382"
}
}
],
"executionDuration": 0
}
},
{
"id": "0ae86a22-ad48-4fd2-9362-c1b8ffc68459",
"type": "swap",
"tool": "lifidexaggregator",
"toolDetails": {
"key": "lifidexaggregator",
"name": "LI.FI DEX Aggregator",
"logoURI": "https://raw.githubusercontent.com/lifinance/types/main/src/assets/icons/exchanges/lifidexaggregator.svg"
},
"action": {
"fromChainId": 137,
"fromAmount": "959696",
"fromToken": {
"address": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"chainId": 137,
"symbol": "USDC",
"decimals": 6,
"name": "USD Coin",
"coinKey": "USDC",
"logoURI": "https://static.debank.com/image/coin/logo_url/usdc/e87790bfe0b3f2ea855dc29069b38818.png",
"priceUSD": "0.9996001599360256"
},
"fromAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
"toChainId": 137,
"toToken": {
"address": "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
"chainId": 137,
"symbol": "DAI",
"decimals": 18,
"name": "(PoS) DAI Stablecoin",
"coinKey": "DAI",
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeAC495271d0F/logo.png",
"priceUSD": "0.9998"
},
"toAddress": "0x1231DEB6f5749EF6cE6943a275A1D3E7486F4EaE",
"slippage": 0.005
},
"estimate": {
"tool": "lifidexaggregator",
"fromAmount": "959696",
"toAmount": "959481608953993728",
"toAmountMin": "954684200909223759",
"approvalAddress": "0x46B3fDF7b5CDe91Ac049936bF0bDb12c5d22202e",
"feeCosts": [],
"gasCosts": [
{
"type": "SEND",
"price": "30000000047",
"estimate": "110000",
"limit": "165000",
"amount": "3300000005170000",
"amountUSD": "0.01",
"token": {
"address": "0x0000000000000000000000000000000000000000",
"chainId": 137,
"symbol": "MATIC",
"decimals": 18,
"name": "MATIC",
"coinKey": "MATIC",
"logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
"priceUSD": "0.4382"
}
}
],
"executionDuration": 30
}
}
]
}
},
"approvalTxs": [
{
"to": "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
"data": "0x095ea7b3000000000000000000000000b9c0de368bece5e76b52545a8e377a4c118f597b000000000000000000000000000000000022d473030f116ddee9f6b43ac78ba3"
}
]
}
}
```
The approval transactions specify what tokens must be approved to the permit2 contract in order for the flow to work. While it is generally considered safe to perform a maximum approval to the permit contract, our API only returns the minimum amount of approval required for the transaction to work.
The approval transactions must be executed by the user before the delegated relay of this transaction.
Sign the payload
The gas-less flow relies on user signatures to allow tokens to be used on the user's behalf.
A signature will be required for the permitData
portion of the response:
const signedData = await account.signTypedData(
response.data.quote.permitData.domain,
response.data.quote.permitData.types,
response.data.quote.permitData.values
)
Relay the transaction
Once a signature is obtained, the transaction can be scheduled for execution by calling the relay endpoint (https://gasless.li.quest/v1/relay
) as follows:
const relayResponse = await axios.post(
'https://gasless.li.quest/v1/relay',
{
tokenOwner: request.fromAddress,
chainId: request.fromChain,
permit: response.data.quote.permit,
witness: response.data.quote.witness,
signedPermitData: signedData,
callData: response.data.quote.step.transactionRequest!.data!,
}
)
Monitoring the status of a relay
The call to the relay endpoint will provide the caller with a taskId
- this task ID can be used to monitor execution status via our dedicated status endpoint https://gasless.li.quest/v1/status
const taskStatus = await axios.post(
`https://gasless.li.quest/v1/status/${taskId}`
)
Which in case of correct execution will return something like the following:
```json
{
"status": "ok",
"data": {
"status": "DONE",
"message": "All done",
"metadata": {
"chainId": 137,
"txHash": "0xc91147922ba468640d43817f77435a1254800cef8cc130ee04f974deddbdd252"
},
"transactionStatus": {
"transactionId": "0x6151aa8471cbb81c2c3ae38874af7f1ee006e28134b53142e7fd36ebbf21a3b0",
"sending": {
"txHash": "0xc91147922ba468640d43817f77435a1254800cef8cc130ee04f974deddbdd252",
"txLink": "https://polygonscan.com/tx/0xc91147922ba468640d43817f77435a1254800cef8cc130ee04f974deddbdd252",
"amount": "1000000000000000000",
"token": {
"address": "0x0d500B1d8E8eF31E21C99d1Db9A6444d3ADf1270",
"chainId": 137,
"symbol": "WMATIC",
"decimals": 18,
"name": "WMATIC",
"coinKey": "WMATIC",
"logoURI": "https://static.debank.com/image/matic_token/logo_url/0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270/f6e604ba0324726a3d687c618aa4f163.png",
"priceUSD": "0.4189"
},
"chainId": 137,
"gasPrice": "32979160144",
"gasUsed": "340653",
"gasToken": {
"address": "0x0000000000000000000000000000000000000000",
"chainId": 137,
"symbol": "MATIC",
"decimals": 18,
"name": "MATIC",
"coinKey": "MATIC",
"logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
"priceUSD": "0.4189"
},
"gasAmount": "11234449840534032",
"gasAmountUSD": "0.01",
"amountUSD": "0.42",
"timestamp": 1723119469
},
"receiving": {
"txHash": "0xc91147922ba468640d43817f77435a1254800cef8cc130ee04f974deddbdd252",
"txLink": "https://polygonscan.com/tx/0xc91147922ba468640d43817f77435a1254800cef8cc130ee04f974deddbdd252",
"amount": "395555449466183982",
"token": {
"address": "0x8f3Cf7ad23Cd3CaDbD9735AFf958023239c6A063",
"chainId": 137,
"symbol": "DAI",
"decimals": 18,
"name": "(PoS) DAI Stablecoin",
"coinKey": "DAI",
"logoURI": "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/0x6B175474E89094C44Da98b954EedeAC495271d0F/logo.png",
"priceUSD": "0.9999"
},
"chainId": 137,
"gasPrice": "32979160144",
"gasUsed": "340653",
"gasToken": {
"address": "0x0000000000000000000000000000000000000000",
"chainId": 137,
"symbol": "MATIC",
"decimals": 18,
"name": "MATIC",
"coinKey": "MATIC",
"logoURI": "https://static.debank.com/image/matic_token/logo_url/matic/6f5a6b6f0732a7a235131bd7804d357c.png",
"priceUSD": "0.4189"
},
"gasAmount": "11234449840534032",
"gasAmountUSD": "0.01",
"amountUSD": "0.42",
"timestamp": 1723119469
}
}
}
}
```
Last updated