Bitcoin Cash API and its usage

Bitcoin Cash API and its usage


Crypto APIs Team

Feb 6, 2020 • 3 min

Following up on our latest API article on Litecoin, here is another hard fork on Bitcoin blockchain: Bitcoin Cash. Before diving into this, we suggest to briefly go through Bitcoin, to better understand its features.

Firstly, this fork was done with the premises to increase the block size from 1 MB to at least 8 MB in 2017. Ever since, the block size can go up to 32 MB. This basically means more transactions per block, less efforts, waiting time and processing costs. For instance, the usual number of transactions per block on Bitcoin is somewhere in the range of 1000 and 1500. On Bitcoin Cash that number reached 25000 for each block. Above all, this has been argued to be one of this fork’s major advantages towards the vision of scalability and adoption.

Secondly, Bitcoin Cash does not include SegWit solution (check Segregated Witness on our glossary). It doesn’t follow the logic of having metadata of a transaction, rather stores the entire data in the block.

However, the two blockchains do have similarities. They both:

  • - use the same consensus mechanism in mining (Proof of Work)
  • - use the same algorithm (Emergency Difficulty Adjustment)
  • - have the same supply cap (21 million).

Hence, the API endpoints are similar to the ones also provided by Bitcoin APIs.

Finally, the focus of this article will be on 3 use cases that CryptoAPIs provides through the use of Bitcoin Cash API: transactionspayment forwarding and webhook notifications.

New transaction endpoint

The New Transaction Endpoint combines three endpoints: Create, Sign and Send Endpoints. Users should provide:

  • - the inputs and outputs fields with the corresponding data
  • - the fee
  • - the wifs (private ECDSA keys) of the addresses

Then, the POST request creates, signs and broadcasts the new transaction to the Bitcoin Cash Blockchain.

For instance:

payload = “{\n\t\”createTx\”: { \n\t\t\t\”inputs\”: [{\n\t\t\t\”address\”: \”bchtest:qrqxlge4wjv7kttm0u9srqjttprhylsz6g84fhjgzf\”,\n\t\t\t\”value\”: 0.00309\n\t\t}],\n\t\t\”outputs\”: [{\n\t\t\t\”address\”: \”qzsq3lqt2s08635y54h96la8002jy5tvlshrnskeux\”,\n\t\t\t\”value\”: 0.00309\n\t\t}],\n\t\t\n\t\t\”fee\”:  {\n\t\t\t\”value\”: 0.00023141\n\t\t}\n\t}, \n\t \”wifs\” : [\n            \”cSKbuySxbKm4uQK9SQQRjpsZfENNBrFxKm3rmoMER9ua6XR79Shs\”\n    ]\n}”

Users can set two optional fields within the createTx object: data and locktime.

The data (string) field is used to send messages/metadata with the transaction. 

The Locktime (integer) field has a default value of zero and can delay the transaction to a specific time.

Delete Payment endpoint

As Bitcoin Cash API helps creating payment forwarding address, the user can also delete it through Delete Payment endpoint. This is done through its id and the current user id.

The request may look like this:

conn.request(“DELETE”, “/v1/bc/bch/testnet/payments/f0e80c20-434b-4195-a1e4-e3cdfd8585f3”, headers=headers)

so the DELETE request has this format: 


where PAYMENT_UUID is the Generated UUID when payment forwarding have been created and it is represents the payment forwarding request the user wants to delete.

Create Transaction Confirmations Webhook

Webhooks are essential when it comes to automatic confirmations on transactions happening behind-the-scenes.  So by creating Confirmed Transaction Webhook, the user will receive a notification after every confirmation (new block) for every new incoming/outgoing transaction.

Using POST request in such format:

conn.request(“POST”, “/v1/bc/bch/mainnet/hooks”, payload, headers)

in order to expect such response object:

{ “event”: “TRANSACTION_CONFIRMATIONS”, “url”:{CALLBACK_URL}, “address” : ${ADDRESS}}, “confirmations” : ${CONFIRMATIONS} }

The confirmations shows the number of confirmations before receiving Webhook. This can be any number between 1 and 20. Set to 1 means that webhooks will be sent immediately after the block that includes transactions with the specified address is mined. However, since there is the possibility of blockchain block re-write, we suggest that users set the confirmations at least to 3.

In conclusion, these are a few examples of how endpoints help in integrating the Bitcoin Cash API into your website. They provide the backbone into the complete process of participating in this blockchain.

Read more on our docs on Bitcoin Cash API.

Related articles