Bitcoin Integration
IBEX FI API – Bitcoin Endpoints (Client Integration Guide)
This document explains how to integrate all Bitcoin-related endpoints exposed by IBEX FI API. It covers two complementary flows:
- Direct, off-chain Bitcoin helpers under
GET/POST /v1.2/safes/bitcoin/* - An authorization wrapper via Safe Operations using the
BITCOIN_SENDoperation type onPOST /v1.2/safes/operations(no on-chain Safe tx is created; it is an off-chain flow for client-side PSBT signing and broadcast)
Unless stated otherwise, endpoints require JWT auth via an Authorization: Bearer <token>`` header. All amounts are expressed in satoshis where applicable.
How fees are paid (two operating modes)
- Simple mode (wallet pays own fees):
- The sender wallet A funds the transaction and the network fees from A's UTXOs.
- Use
/v1.2/safes/bitcoin/send/prepare(orBITCOIN_SENDvia/v1.2/safes/operations) to getprepared. - A builds and signs the PSBT locally and broadcasts via
/v1.2/safes/bitcoin/tx/broadcast. - Effect: fees are implicitly paid by A (sum(inputs A) − sum(outputs) = feeSat).
- Collaborative PSBT (sponsored by another wallet):
- A defines the business outputs (e.g., amount to C) and exports an unsigned PSBT.
- B adds its own inputs (and B's change) to cover the fee, signs only B's inputs, and returns the PSBT to A.
- A verifies outputs are unchanged, signs only A's inputs, finalizes, and broadcasts.
- Effect: fees are paid from B's inputs without exposing A or B private keys to the server; use SIGHASH_ALL and let A sign last.
Networks
- Use query/body param
networkwith valuesmainnetortestnetwhere supported. - If omitted, the server infers a default from environment (e.g.,
BTC_NETWORK).
1) Bitcoin helper endpoints (/v1.2/safes/bitcoin)
These endpoints help you fetch UTXOs, estimate fees, prepare simple sends, and broadcast a signed raw transaction. No server-side signing occurs.
GET /v1.2/safes/bitcoin/info
- Auth: JWT
- Purpose: Basic network info (proxy to Core
getblockchaininfo). - Query params:
network(optional):mainnet|testnet
- 200 Response (example):
Example curl:
GET /v1.2/safes/bitcoin/fees
- Auth: JWT
- Purpose: Estimate fee tiers using Core
estimatesmartfeefor 1/6/12 blocks. - Query params:
network(optional):mainnet|testnet
- 200 Response:
Example curl:
GET /v1.2/safes/bitcoin/utxos
- Auth: JWT
- Purpose: List UTXOs for a Bitcoin address (uses Core
scantxoutset addr(<address>)). - Query params:
address(required): Bitcoin address (bech32 recommended)network(optional):mainnet|testnet
- 200 Response:
- Notes:
valueis in satoshis.- If
utxosis empty, the server returns 200 with an empty list; some composed flows may enforce non-empty.
Example curl:
POST /v1.2/safes/bitcoin/send/prepare
- Auth: JWT
- Purpose: Prepare a simple send by selecting UTXOs, estimating fees, computing change. Returns a structure suitable for building a PSBT client-side.
- Body:
- 200 Response:
- Notes:
- Greedy coin selection; rough vbytes sizing:
68 * nInputs + 31 * nOutputs + 10. - If
sendAll=true, theamountSatin the response is set to the computed value (sum(UTXO) - feeSat) and there is typically no change output. - This endpoint does not build/sign a PSBT; build it client-side using the returned
inputsUsed/outputs/change.
- Greedy coin selection; rough vbytes sizing:
Example curl:
POST /v1.2/safes/bitcoin/tx/broadcast
- Auth: JWT
- Purpose: Broadcast a signed raw transaction (hex) to the network.
- Body:
- 200 Response:
Example curl:
POST /v1.2/safes/bitcoin/psbt/build (placeholder)
- Auth: JWT
- Purpose: Reserved for a future server-side PSBT builder. Currently returns
501 Not Implemented.
2) Safe Operations wrapper for Bitcoin – BITCOIN_SEND
You can request a WebAuthn authorization and receive the same prepared structure via the Safe Operations endpoint by submitting only BITCOIN_SEND operations. No Safe (EVM) transaction is created; the flow remains off-chain for Bitcoin.
POST /v1.2/safes/operations
- Auth: JWT
- Body (example):
- 200 Response:
- Notes:
- This route performs the same preparation as
/send/prepare, adds a WebAuthncredentialRequestOptionschallenge, and returns immediately. - No Safe user operation is created; do not call
PUT /v1.2/safes/operationsfor this Bitcoin flow. - Use the
preparedobject to build/sign your PSBT client-side, then broadcast via/v1.2/safes/bitcoin/tx/broadcast.
- This route performs the same preparation as
3) Building and signing a PSBT (client-side)
Use the output of /send/prepare or the prepared object from BITCOIN_SEND to construct a PSBT:
- Inputs: for each
inputsUsed[i], add a PSBT input withtxid,vout, and the script/amount context your library requires (e.g.,nonWitnessUtxoorwitnessUtxoderived fromscriptPubKeyandvalue). - Outputs: add the main
tooutput and the optionalchangeoutput if present. - Fees: the server returns an estimated
feeSat; total inputs minus total outputs equalsfeeSat. - Sign: sign with the private key controlling
from(client custody). - Finalize and extract hex.
- Broadcast the hex with
POST /v1.2/safes/bitcoin/tx/broadcast.
Because wallet libraries differ, refer to your PSBT library docs (e.g., bitcoinjs-lib, bc-lib, etc.) for the exact fields to populate per input type (P2WPKH, P2TR, etc.).
4) Typical integration sequence
- Fetch UTXOs for the sender address:
GET /v1.2/safes/bitcoin/utxos?address=... - Get fee tiers:
GET /v1.2/safes/bitcoin/fees - Prepare send:
POST /v1.2/safes/bitcoin/send/prepare(orPOST /v1.2/safes/operationswith a singleBITCOIN_SENDop if you need WebAuthn authorization) - Build PSBT client-side using the prepared structure
- Sign PSBT client-side
- Broadcast:
POST /v1.2/safes/bitcoin/tx/broadcast
5) Validation and error handling
- 400 Bad Request
- Missing/invalid fields (e.g.,
amountSatmust be > 0 whensendAll=false) - No UTXOs for
fromaddress - Insufficient funds (including fees)
- For
BITCOIN_SENDvia/v1.2/safes/operations:'from' is requiredwhen using that path
- Missing/invalid fields (e.g.,
- 401 Unauthorized
- Missing/invalid JWT
- 409 Conflict
- Not applicable to Bitcoin helpers; may appear in other Safe flows
- 500 Internal Server Error
- Underlying RPC failure (info/fees/utxos), prepare failure, broadcast errors
- 501 Not Implemented
/v1.2/safes/bitcoin/psbt/build
6) Notes and constraints
- The server does not sign Bitcoin transactions. Keep custody and signing on the client.
- Coin selection is greedy and fee estimation is approximate; you may re-run prepare with a different
feeProfile. - Address validation is minimal server-side; ensure your client validates address formats.
- For
sendAll=true, the change is omitted and theamountSatis adjusted to use all inputs minus fees.
7) Quick examples
Prepare (send specific amount):
Broadcast:
Safe Operations wrapper (request WebAuthn + prepare):
Use the returned prepared object to build and sign your PSBT client-side, then broadcast.