The following is the typical flow when using Gasless API. This guide covers how to complete steps 3 - 4 below.
/gasless/price/gasless/quote/gasless/submit
/gasless/submit/gasless/status/{tradeHash}Checkout the Gasless API Runnable Headless Example to see these steps in action.
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:
signTypedData_v4)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
Here is an example to sign it using viem’s signTypedData:
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:
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
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:
If the submitted trade is successful, and object with type, tradeHash, and zid are returned.
201 if successful400:
otc only) If the trade has been outstanding for too long.otc only) If the balance / allowance of the market maker selected to settle the trade is less than the trade amount (very unlikely).500 if there is an internal server error.go-ethereum, for domain, make sure you order the fields in the exact same order as specified in https://eips.ethereum.org/EIPS/eip-712 since go-ethereum does not enforce ordering. Also, make sure you skipped fields that are absent.ethers v6 (v5 and v4 are fine), there is an issue for signing EIP-712 object. Make sure you updated ethers version to >= 6.3.0.