1. Home
  2. bloXroute Documentation
  3. Gateway-API
  4. Sending Transactions via Gateway-API

Sending Transactions via Gateway-API

Sending transactions directly to the Gateway using the Gateway-API allows you to send a single or batch of transactions that will be distributed faster to the blockchain network.

In order to use this service, you must register an account on the bloXroute website and use a paid tier.

During the registration process, a certificate, private key, and secret-hash will be generated for your account. The certificate and key will be used to authenticate your account by the Gateway-API. Visit this page for more information on running the Gateway with an account.

The bloXroute best practice is for users to send transactions to both the Gateway-API and to their blockchain node. You should first send transactions to the Gateway (consider using asynchronous mode to improve performance) and then to your blockchain node as a backup.

Example of Curl Command

‌Assume that the Gateway IP is 127.0.0.1 with port 28332

curl http://127.0.0.1:28332 \
--data '{"method": "blxr_tx", "id": "c85c96c2-587f-4be0-a58a-ac9b91716312", "params": {"transaction": "f86b01847735940082520894a2f6090c0483d6e6ac90a9c23d42e461fee2ac5188016147191f13b0008025a0784537f9801331b707ceedd5388d318d86b0bb43c6f5b32b30c9df960f596b05a042fe22aa47f2ae80cbb2c9272df2f8975c96a8a99020d8ac19d4d4b0e0b58219", "synchronous": "True"}}' \
--header "Content-Type:text/plain" \
--header "Authorization:xxxxxxxxxxxx"

 

Explanation:

  • --data '{...}' – This section includes a JSON string on the requested command
  • "method": "blxr_tx" – This is a blxr_tx command – sending a transaction to a bloXroute Gateway.
    • "id": "c85c96c2-587f-4be0-a58a-ac9b91716312" – Each command can have its own request id, so your code can check the response and match them to the requests. You can enter any value here.
    • "params": {...} – This section includes a JSON string that has additional parameters required for the execution on the command. In this example, the parameters should include the raw transaction and optionally an indication if to send it asynchronous or synchronous.
      • "transaction": "..." – (Mandatory) raw transaction based on your blockchain protocol.
      • "synchronous": "true" – (optional, default: True) a boolean flag indicating if the caller waits for a complete answer from BDN.
  • --header "Content-Type:text/plain" – required by the protocol to indicate the format of the http request
  • --header "Authorization:xxxxxxxxxxx" – used to authenticate the request. Authentication is done against the –rpc-user and –rpc-password the Gateway started with.

 
Example of Gateway Reply in Synchronous Mode:

<<< "{\"jsonrpc\": \"2.0\", \"id\": \"c85c96c2-587f-4be0-a58a-ac9b91716312\", \"result\": {\"tx_hash\": \"ffd59870844e5411f9e4043e654146b054bdcabe726a4bc4bd716049bfa54a69\", \"quota_type\": \"paid_daily_quota\", \"synchronous\": \"True\"}}"

Example of Gateway Reply in Asynchronous Mode:

<<< "{\"jsonrpc\": \"2.0\", \"id\": \"c85c96c2-587f-4be0-a58a-ac9b91716312\", \"result\": {\"tx_hash\": \"not available with async\", \"quota_type\": \"paid_daily_quota\", \"synchronous\": \"False\"}}"

 

Example of Python Requests Package


import requests
raw_tx = "f88a82......35ac1e"
authorization_header = "XXXXX"
tx_params = {
    "transaction": raw_tx,
    "synchronous": "True" # use False for faster asynchronous transaction sending, but transaction hash is not available
}
request_json = {
    "method": "blxr_tx",
    "params": tx_params
}
result = requests.post(
    "http://127.0.0.1:28332",
    json=request_json,
    headers={
        "Content-Type": "text/plain",
        "Authorization": authorization_header
    }
)
result_json = result.json()

 
Example of Gateway Reply in Synchronous Mode:


>>> print(result_json)
{
    "jsonrpc": "2.0",
    "id": null,
    "result": {
        "tx_hash": "ffd59870844e5411f9e4043e654146b054bdcabe726a4bc4bd716049bfa54a69",
        "quota_type": "paid_daily_quota",
        "synchronous": "True"
    }
}

Example of Gateway Reply in Asynchronous Mode:


>>> print(result_json)
{
    "jsonrpc": "2.0",
    "id": null,
    "result": {
        "tx_hash": "not available with async",
        "quota_type": "paid_daily_quota",
        "synchronous": "False"
    }
}