Assemble
The /sor/assemble endpoint is used after calling /sor/quote/v3 and receiving a pathId. The pathId is used in the assemble request to return the call data to be executed onchain.
A quote is valid for 60 seconds. If it is not assembled within that time, the path must be re-quoted.
Use the data from this endpoint exactly as provided — modifying calldata can lead to irreversible loss of funds.
Odos does not provide support for transactions using modified calldata.
Request Body
| Parameter | Description | Required |
|---|---|---|
userAddr | Address of the user who requested the quote. | Yes |
pathId | ID of the path returned from /sor/quote/{version}. | Yes |
simulate | Simulate the transaction to ensure it executes successfully. Increases response time. Defaults to false. | No |
receiver | Optional address to receive transaction output (default = userAddr). | No |
Response Body
| Parameter | Description |
|---|---|
deprecated | Message if endpoint or fields are deprecated. |
blockNumber | Block number the quote was generated for. |
gasEstimate | Naive gas estimate. |
gasEstimateValue | USD value of the gas estimate. |
inputTokens | List of input token addresses and amounts. |
outputTokens | List of output token addresses and amounts. |
netOutValue | Net USD value of output tokens after gas. |
outValues | Output values corresponding to output tokens. |
transaction | Transaction object required for execution. |
simulation | Results of transaction simulation. |
Transaction Object
This structure can be signed by a wallet and executed on the Odos router contract.
In a smart contract, use the following call pattern:
(bool success, bytes memory result) = router.call{value: $ethInput}(data);
Where $ethInput is 0 unless the native coin is used as input.
ERC20 inputs must be approved to the router address beforehand.
The router address is provided in the to field or can be retrieved from /info/router/{version}/{chain_id}.
| Parameter | Description |
|---|---|
chainId | Chain ID for execution. |
gas | Suggested gas limit (2x naive estimate or +10% above simulation). |
gasPrice | Gas price used during path generation. |
value | Input amount of gas token (0 if gas token is not an input). |
to | Odos router address to execute against. |
from | Source wallet executing the transaction. |
data | Encoded calldata payload for the Odos router. |
nonce | Standard Ethereum nonce. |
Simulation Object
Result of the transaction simulation.
| Parameter | Description |
|---|---|
isSuccess | Indicates if the transaction executed successfully. |
amountsOut | Token output amounts from the simulation. |
simGasUsed | Gas used during the simulation. |
gasEstimate | Gas estimate from eth_estimateGas. |
simulationError | Error details if the simulation failed. |
Example: Assemble a Transaction
- JavaScript
- Python
import 'dotenv/config';
import fetch from 'node-fetch';
const assembleUrl = 'https://enterprise-api.odos.xyz/sor/assemble';
const assembleRequestBody = {
userAddr: '0x...', // same user address used in quote step
pathId: quote.pathId, // from /sor/quote response
simulate: true
};
const response = await fetch(assembleUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': process.env.ODOS_API_KEY
},
body: JSON.stringify(assembleRequestBody)
});
const assembled = await response.json();
console.log(assembled.transaction);
import os
import requests
from dotenv import load_dotenv
load_dotenv()
assemble_url = 'https://enterprise-api.odos.xyz/sor/assemble'
assemble_request_body = {
"userAddr": "0x...",
"pathId": quote["pathId"],
"simulate": True
}
headers = {
"Content-Type": "application/json",
"x-api-key": os.getenv("ODOS_API_KEY")
}
response = requests.post(assemble_url, json=assemble_request_body, headers=headers)
assembled = response.json()
print(assembled["transaction"])
Example Response
{
"blockNumber": 23619524,
"gasEstimate": 214504,
"gasEstimateValue": 1.12,
"transaction": {
"to": "0x221a4c9e54baebd678ff1823e4fca2ac3685ca64",
"from": "0x5AD89031aAfFe2F82dF3b98Fa4181E08B5dCFF9C",
"data": "0x12ab34cd...",
"chainId": 8453,
"gas": 235000,
"gasPrice": "1000000000",
"value": "0",
"nonce": 112
},
"simulation": {
"isSuccess": true,
"amountsOut": ["1833893"],
"simGasUsed": 203421,
"gasEstimate": 214504,
"simulationError": null
}
}