Technical Appendix
The following is the typical flow when using Gasless API. This guide covers how to complete steps 3 - 4 below.
- Get an indicative price using
/gasless/price - Get a firm quote using
/gasless/quote - Submit the transaction using
/gasless/submit- Sign the gasless approval object (if applicable)
- Sign the trade object
- Split the signatures
- Package split signed objects into a format that can be POST to
/gasless/submit - Compute trade hash
- Check the trade status using
/gasless/status/{tradeHash}
Checkout the Gasless API Runnable Headless Example to see these steps in action.
Signing objects
To take advantage of gaslesses approvals and gasless trades, user must sign the approval.eip712 and the trade.eip712 objects returned by /quote. These objects contain everything (domain, types, primaryType, message) needed when signing these objects .
There are different EIP-712 signing strategies if you are user facing wallet that shows the users the details of what they are signing. Some commonly used tools for this include:
- integrating with MetaMask (via
signTypedData_v4) - viem’s signTypedData
- wagmi’s signTypedData
Sign gasless approval object
If a token supports gasless approvals, the /quote response will return an “approval” object which contains the necessary information to process a gasless approval, see below:
Keep in mind that the domain field of this object must follow a strict ordering as specified in EIP-712. The approval.eip712 object will present the correct ordering, but make sure that this ordering is preserved when obtaining the signature:
name,version,chainId,verifyingContract,salt- Contracts may not utilize all of these fields (i.e. one or more may be missing), but if they are present, they must be in this order
- Any other field must follow in alphabetical order
Here is an example to sign it using viem’s signTypedData:
Sign trade object
Similar to gasless approval, to submit a trade, you must have your user sign trade.eip712 object returned at the time of the /quote. All the instructions & caveats are the same as previous section.
See example code to sign trade object
Here is an example to sign it using viem’s signTypedData:
Split signatures
Once signed, the signature needs to be split to its individual components (v, r, s) and to be formatted in an object that can be POST to /submit (see object format here).
Example code showing how to implement a split signature function. This is a variation of this splitSignature implementation.
Example code using split signature to split approval and trade signatures
POST the split signatures to /submit
Example request
Once the signatures have been split, in order to POST to /submit, approval and trade objects must be formatted to contain the following key/value pairs:
Here is an example code snippet of how to submit it using JavaScript:
Example response
If the submitted trade is successful, and object with type, tradeHash, and zid are returned.
Status Code
201if successful400:- If the trade is too close to expiration time.
- If the signature in the payload is invalid.
- If the balance / allowance of the taker is less than the trade amount.
- (
otconly) If the trade has been outstanding for too long. - (
otconly) If the balance / allowance of the market maker selected to settle the trade is less than the trade amount (very unlikely). - If the query params are not able to pass validation.
429if there is already a trade associated with a taker address and a taker token that’s not been settled by our relayers yet. For example, ifaddress Aalready has aUSDC -> WETHtrade submitted and it has not settled yet, then a subsequent/submitcall withaddress AandUSDC -> *trade will fail with429. The taker is, however, allowed to submit other trades with a different taker token.500if there is an internal server error.
Note for go-ethereum
- If you’re using
go-ethereum, fordomain, make sure you order the fields in the exact same order as specified in https://eips.ethereum.org/EIPS/eip-712 sincego-ethereumdoes not enforce ordering. Also, make sure you skipped fields that are absent.
- If you’re using
ethers v6(v5andv4are fine), there is an issue for signing EIP-712 object. Make sure you updatedethersversion to>= 6.3.0.