Sign and Broadcast Transaction

To complete staking or withdrawal operations on Babylon, sign the unsigned transaction provided by the Staking API and broadcast it to the network.

1. Prepare the transaction

  1. Initialize the service by installing dependencies from this repository.

  2. In the config.js file, set your private key and specify the network.

2. Sign and send the transaction

  1. Sign the transaction using the code from the repository.

  2. 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.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
     }`
  • transactionHexsigned transaction in 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?