Skip to content

  Spin up a managed Avalanche node cluster in minutes! Learn More.

The Sync Blog

Updates and insights from the Bloq team

« Blog Home

How to: Query/Submit on Bitcoin and Bitcoin Cash Simultaneously

In this how-to lesson, we’re going to go over how to query and submit to two blockchains simultaneously, using Bitcoin and Bitcoin Cash as examples. We can imagine, for instance, a crypto-friendly merchant wants to process payments across multiple cryptocurrencies. Below, we’ll outline the required steps. Be sure to reference the “Getting Started” post if you haven’t already.

Javascript SDK Setup

From previous installments, you may recall that the Javascript SDK requires a valid client id and secret. Your id/secret is akin to a username/password combo that allows your code to interact with the Bloq API. You can generate client keys through the Bloq Command Line.

First, sign in with bcl login. Once logged in, you can produce new client keys with bcl client-keys create.

After that, create a Javascript (.js) file for your code. In your text editor of choice, produce this header with your newly created client id and secret:

Every desired method call through the Javascript SDK is placed in the same document, below the header. Here’s the method to grab the current mining difficulty of Bitcoin:

Query/Submit: Multiple Blockchains

In the same manner that we can string any number of commands in a Javascript file, we can also call commands to multiple blockchains at once. Below, we’ll outline the code required to interact with Bitcoin and Bitcoin Cash blockchains simultaneously.

Bitcoin and Bitcoin Cash method calls use the same syntax. To make calls to both chains at once, the first step is to place the existing code into a function that takes the specified chain as the input. Make sure to update the 'coin' field to reflect the input chain value:

Below that, place two method calls below the function. One for BTC, another for BCH:

One final step, let’s update the output string to reflect both BTC and BCH outputs:

From here, you can add as many calls to both chains within the function as you like. This can be useful to compare block times, mining difficulty, fees, and so on between both chains. As highlighted above, the ability to interact with multiple blockchains simultaneously also established the base layer for interoperability between chains.