API References
Overview​
There are currently four endpoints involved in a Gasless API transaction:
/tx-relay/v1/swap/price
/tx-relay/v1/swap/quote
/tx-relay/v1/swap/submit
/tx-relay/v1/swap/status/:trade-hash
Gasless API also includes two additional endpoints to provide a list of supported tokens for each feature:
- Gasless Approvals Token List
/tx-relay/v1/swap/gasless-approval-tokens
- Gasless Swaps Token List for Mainnet
/tx-relay/v1/swap/supported-tokens
There is no Gasless Swaps Token List for other chains because we support swapping all tokens on those chains.
Gasless API is supported on the following chains via https://api.0x.org/. Select the chain in your request by providing the corresponding chain id with the 0x-chain-id
header.
Chain | Chain ID |
---|---|
Ethereum (Mainnet) | 1 |
Polygon | 137 |
Arbitrum | 42161 |
Base | 8453 |
Optimism | 10 |
Signed Orders are Settled by 0x Protocol Smart Contracts​
Once signed orders hit the blockchain,
- If the orders are swap only, they are settled by 0x Protocol smart contracts directly,
- For meta-transaction v2 orders, they are settled by the contract
MetaTransactionsFeatureV2
and filled by theexecuteMetaTransactionV2
function, available here. - For otc order, they are settled by the contract
OtcOrdersFeature
and filled by thefillTakerSignedOtcOrderForEth
orfillTakerSignedOtcOrder
functions, available here.
If the orders are approval and swap, they are settled by permitAndCall
contract which handles the approval and swap atomically. The swap would be forwarded to 0x Protocol smart contracts and handled by the same functions.
Addresses of 0x Protocol smart contracts are available here.
Addresses of permitAndCall
contracts
Network | Address |
---|---|
Ethereum (Mainnet) | 0x1291c02d288de3de7dc25353459489073d11e1ae |
Polygon | 0x2ddd30fe5c12fc4cd497526f14bf3d1fcd3d5db4 |
Technical Appendix​
Presenting EIP-712 Signatures for signTypedData
​
If you are user facing wallet that shows the users the details of what they are signing, then you will most likely want to use the EIP-712 signing strategy. Some commonly used tools for this include:
- integrating with MetaMask (via
signTypedData_v4
) - using wagmi's
useSignTypedData
hook for signing typed data (see an example implementation in the Gasless API Demo App here and read the guide here)
In order to do so, you will need the following:
domain
types
primaryType
message
The message
will be MetaTransactionDataV2
that is returned at the time of /quote
. However, you will also need the other fields.
The domain
will change per chain, but the name
and version
fields are consistent. Example:
const domain = {
chainId: 1,
verifyingContract: '0xdef1c0ded9bec7f1a1670819833240f027b25eff',
name: 'ZeroEx',
version: '1.0.0',
};
For types
and primaryTypes
, it will depend on the message format.
For
MetaTransactionDataV2
const primaryType = 'MetaTransactionDataV2';
const types = {
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'verifyingContract',
type: 'address',
},
],
MetaTransactionDataV2: [
{
type: 'address',
name: 'signer',
},
{
type: 'address',
name: 'sender',
},
{
type: 'uint256',
name: 'expirationTimeSeconds',
},
{
type: 'uint256',
name: 'salt',
},
{
type: 'bytes',
name: 'callData',
},
{
type: 'address',
name: 'feeToken',
},
{
type: 'MetaTransactionFeeData[]',
name: 'fees',
},
],
MetaTransactionFeeData: [
{
type: 'address',
name: 'recipient',
},
{
type: 'uint256',
name: 'amount',
},
],
};For
OtcOrder
const primaryType = 'OtcOrder';
const types = {
EIP712Domain: [
{
name: 'name',
type: 'string',
},
{
name: 'version',
type: 'string',
},
{
name: 'chainId',
type: 'uint256',
},
{
name: 'verifyingContract',
type: 'address',
},
],
OtcOrder: [
{
type: 'address',
name: 'makerToken',
},
{
type: 'address',
name: 'takerToken',
},
{
type: 'uint128',
name: 'makerAmount',
},
{
type: 'uint128',
name: 'takerAmount',
},
{
type: 'address',
name: 'maker',
},
{
type: 'address',
name: 'taker',
},
{
type: 'address',
name: 'txOrigin',
},
{
type: 'uint256',
name: 'expiryAndNonce',
},
],
};More information on signing 0x orders is available here.
Computing a trade hash​
You could / should verify that the hash we provide in our request matches the meta-transaction provided.
For the trade.hash
field:
- If it's a meta-transaction v2, verify that the
meta-transaction v2
hashes to thetrade.hash
:getMetaTransactionV2Hash
link - It it's an otc, verify that
otc
hashes to thetrade.hash
:getOtcOrderHash
link
If you need to call these functions on the 0x smart contracts to validate your code, you may need:
- The ABI: https://github.com/0xProject/protocol/blob/development/packages/contract-artifacts/artifacts/IZeroEx.json
- The Contract address (depends on the chain): https://docs.0x.org/introduction/0x-cheat-sheet#exchange-proxy-addresses