Sign and Broadcast Transaction
To sign and broadcast a transaction to the Bitcoin network, follow these steps from the README of this repository:
-
Initialize the service by installing dependencies.
-
In the config.js file, set your private key and specify the network.
-
Sign the transaction using the code.
-
Finally, send the signed transaction to the Bitcoin network by making a POST request to /api/v1/babylon-btc/{network}/transaction/send.
Example request (for sigNet
network):
curl --request POST \
--url https://api-test.p2p.org/api/v1/babylon-btc/signet/transaction/send \
--header 'accept: application/json' \
--header 'authorization: Bearer <token>' \
--header 'content-type: application/json' \
--data '
{
"tranasctionHex": "70736274ff0100e402000000014f0d8e70d376cda7200bc900803d35dab2658fad9ce15454326b642523660ae90200000000fdffffff04b80b000000000000225120df0ec02350705a695b526f5c7662f33d8f8256cbd80cf8cda6d7c46d7d1578d00000000000000000496a4762626434002be65fdd561fee421c4f4564b02e4de31f74836b9b8cd1bbbf9d9c544733614e4bf609ba8977d3fbf4dee7f9d993c41f2fa584ccd27b3e4bf04a5376267e13c000c8025d0000000000002251208e68d4dba630100ab10ca873c961076b819f0c85b10be7aae6f493b60ed4ec48102700000000000000000000000001012bc5690000000000002251208e68d4dba630100ab10ca873c961076b819f0c85b10be7aae6f493b60ed4ec480000000000",
"maxFee": 1000000
}`
transactionHex
— signed transactionin the hexadecimal format which needs to be broadcasted to the network.maxFee
— maximum fee in SATOSHI that can be charged for processing the transaction (1 BTC = 10⁸ SATOSHI).
Example response:
{
"error": null,
"result": {
"transactionHash": "70736274ff0100e402000000014f0d8e70d376cda7200bc900803d35dab2658fad9ce15454326b642523660ae90200000000fdffffff04b80b000000000000225120df0ec02350705a695b526f5c7662f33d8f8256cbd80cf8cda6d7c46d7d1578d00000000000000000496a4762626434002be65fdd561fee421c4f4564b02e4de31f74836b9b8cd1bbbf9d9c544733614e4bf609ba8977d3fbf4dee7f9d993c41f2fa584ccd27b3e4bf04a5376267e13c000c8025d0000000000002251208e68d4dba630100ab10ca873c961076b819f0c85b10be7aae6f493b60ed4ec48102700000000000000000000000001012bc5690000000000002251208e68d4dba630100ab10ca873c961076b819f0c85b10be7aae6f493b60ed4ec480000000000"
}
}
transactionHash
— hash of the transaction.
What's Next?
- Getting Started.
- Withdrawal.
- Staking API reference.
Updated 29 days ago