How to Craft a Bitcoin Transaction with Adamik
This guide provides step-by-step instructions for leveraging the Adamik API to construct Bitcoin transactions. Bitcoin utilizes the UTXO (Unspent Transaction Output) model, where multiple UTXOs may need to be aggregated to satisfy the desired transaction amount.
In the example below, we use a single address as the sender, which contains multiple UTXOs. For scenarios involving wallets with multiple addresses, the Adamik API also supports extended public keys (xpub). This feature enables seamless handling of UTXOs across various addresses within the same wallet, offering enhanced flexibility for more complex transaction workflows.
Please note the following addresses are used for the example purpose only.
Step 1: Prepare Your Request
To initiate the transaction, use the /api/transaction/encode
endpoint with the following payload:
Step 2: Response
The API will respond with a hex-encoded PSBT (Partially Signed Bitcoin Transaction). Example:
Step 3: Analyze the PSBT
The PSBT contains details about the inputs and outputs used in the transaction.
Inputs:
Outputs:
Step 4: Signing the Transaction
The PSBT provided by Adamik API must be signed with a compatible Bitcoin signer.
Example of a signed transaction (hex-encoded):
Please note that the signed transaction is the same as the PSBT, but with the signature added. Different signers may use different formats, so please refer to the documentation of the signer you are using.
Step 5: Finalize and Broadcast
After signing, submit the transaction using the /api/transaction/broadcast
endpoint.
-
Submit the original transaction intent.
-
Input the hex-encoded PSBT.
-
Add the signed BTC transaction in the signature field of the broadcast endpoint
Example of a broadcast request:
Example of a broadcast response:
Summary
- Transaction Intent: Specify sender, recipient, and amount.
- PSBT Generation: The Adamik API will generate the PSBT and automatically select the UTXOs for the transaction, as well as calculate the fees.
- Sign the PSBT: Employ a compatible signer.
- Broadcast: Submit the signed transaction back to the Adamik API, which will broadcast the transaction to the Bitcoin network.
In case of any issues, please connect with us through our Discord Server or directly through GitHub.
Was this page helpful?