Build

POST /v1/build takes a quote_id from a previous Quote response and assembles an unsigned transaction ready for wallet signing and on-chain submission. This is the second step in the swap flow.

New to the API? Start with Getting Started for authentication and your first quote request.

Basic Build

Assemble a transaction from a quote:

curl -X POST "https://api.infraredtrading.com/v1/build" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
    "quote_id": "550e8400-e29b-41d4-a716-446655440000"
  }'

Build with Permit2 Signature

Attach a Permit2 signature for gasless token approval. The signature comes from signing the permit2.eip712 typed data returned in the quote response (when requested with include_permit2=true):

curl -X POST "https://api.infraredtrading.com/v1/build" \
  -H "Content-Type: application/json" \
  -H "X-API-Key: YOUR_API_KEY" \
  -d '{
    "quote_id": "550e8400-e29b-41d4-a716-446655440000",
    "permit2_signature": "0x1234567890abcdef..."
  }'

The permit2_signature is silently ignored if the original quote was not requested with include_permit2=true.

Build with Simulation

Run a fork simulation on the assembled transaction before returning. The simulation verifies the transaction will succeed and reports actual output amounts:

Simulation failures do not block the response -- the transaction is still returned with simulation.success=false and an error message.

Request Fields

Field
Type
Required
Default
Description

quote_id

string

Yes

--

Quote identifier from a previous /v1/quote response.

permit2_signature

string

No

--

Hex-encoded Permit2 signature from signing the EIP-712 typed data in the quote's permit2 field.

simulate

boolean

No

false

Run fork simulation on the assembled transaction.

Quotes can be built multiple times -- building does not consume or invalidate the quote.

Response Fields

A successful response returns HTTP 200:

transaction

Unsigned transaction ready for wallet signing:

Field
Type
Description

to

string

ExecutionProxy contract address (EIP-55 checksummed).

data

string

ABI-encoded calldata for the ExecutionProxy.

value

string

ETH value to send in wei (decimal string). "0" for ERC-20 only swaps.

gas

integer

Recommended gas limit for the transaction.

chain_id

integer

Target blockchain network ID.

estimated_outputs

Carried forward from the quote. Same structure as the Quote response.

simulation

Only present when simulate=true. Fork simulation result:

Field
Type
Description

success

boolean

Whether the simulation succeeded.

gas_used

integer

Actual gas consumed in simulation. Only present on success.

output_amounts

object

Map of token addresses to simulated output amounts. Only present on success.

error

string

Error message if simulation failed (e.g., "execution reverted: INSUFFICIENT_OUTPUT_AMOUNT").

Example with simulation:

What to Do Next

After receiving the build response:

  1. Check estimated outputs -- Verify the expected_amount and minimum_amount meet your requirements.

  2. Review simulation results (if requested) -- If simulation.success is false, the transaction is likely to revert on-chain. Check the error field for details.

  3. Sign the transaction -- Use the to, data, value, gas, and chain_id fields to construct and sign the transaction with the taker's wallet.

  4. Submit on-chain -- Broadcast the signed transaction to the network. The transaction executes atomically through the ExecutionProxy contract -- all swaps succeed or the entire transaction reverts.

  5. Handle ERC-20 approvals -- If the quote response included approvals, ensure the taker has approved the specified tokens and amounts for the spender address before submitting the transaction. Alternatively, use Permit2 to handle approvals via signature.

Last updated