Skip to main content

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

ParameterDescriptionRequired
userAddrAddress of the user who requested the quote.Yes
pathIdID of the path returned from /sor/quote/{version}.Yes
simulateSimulate the transaction to ensure it executes successfully. Increases response time. Defaults to false.No
receiverOptional address to receive transaction output (default = userAddr).No

Response Body

ParameterDescription
deprecatedMessage if endpoint or fields are deprecated.
blockNumberBlock number the quote was generated for.
gasEstimateNaive gas estimate.
gasEstimateValueUSD value of the gas estimate.
inputTokensList of input token addresses and amounts.
outputTokensList of output token addresses and amounts.
netOutValueNet USD value of output tokens after gas.
outValuesOutput values corresponding to output tokens.
transactionTransaction object required for execution.
simulationResults 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}.

ParameterDescription
chainIdChain ID for execution.
gasSuggested gas limit (2x naive estimate or +10% above simulation).
gasPriceGas price used during path generation.
valueInput amount of gas token (0 if gas token is not an input).
toOdos router address to execute against.
fromSource wallet executing the transaction.
dataEncoded calldata payload for the Odos router.
nonceStandard Ethereum nonce.

Simulation Object

Result of the transaction simulation.

ParameterDescription
isSuccessIndicates if the transaction executed successfully.
amountsOutToken output amounts from the simulation.
simGasUsedGas used during the simulation.
gasEstimateGas estimate from eth_estimateGas.
simulationErrorError details if the simulation failed.

Example: Assemble a Transaction

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);

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
}
}