Skip to content

Connect the core client to websocket feed

After you have created a Core Client instance, you can connect it to a websocket feed to listen for transactions pending custody. You will be using the Core Client websocket idas created in the previous section to connect to the unique websocket feed.

This topic presents the process to connect a core client instance to the websocket service. For illustrative purposes, we will use the familiar Signing Client tool, but this time take advantage of its core client functionality.

You can create and connect as many core client instances as you need.

Connect to feed

The example uses the example Signing Client provided by Qredo.

Prerequisite: You must have Golang installed.

  1. Clone the repo at https://github.com/qredo/partner-api-sign.

  2. cd to repo:

    cd partner-api-sign
    
  3. Build the app:

    Build Signing Client in CLI

    You can also use this command on Windows using PowerShell:

    go build -o partner-api-sign
    

    Use command prompt: cmd.exe:

    go build -o partner-api-sign.exe
    

  4. Start listening on the websocket using the command:

    Start listening to websocket

    You can also use this command on Windows using PowerShell:

    ./partner-api-sign websocket -url wss://api.qredo.network/api/v1/p/coreclient/{client_id}/feed
    

    Use command prompt: cmd.exe:

    partner-api-sign.exe websocket -url wss://api.qredo.network/api/v1/p/coreclient/{client_id}/feed
    

Prerequisites: You must have Python v3.6.1 (or later) with the websocket library installed: (use pip3 install websocket in CLI to install it).

Once you have the prerequisites, run the following example script:

from websocket import create_connection
ws = create_connection("wss://api.qredo.network/api/v1/p/coreclient/{client_id}/feed", header={"x-api-key": "<`API_key`>","x-sign": "<SIGNATURE>", "x-timestamp": "1111111111"})
while True:
    result =  ws.recv()
    print (result)

Upon success, the CLI displays connected actions from the core client in compressed JSON format.

C:\path-to-core-client>partner-api-sign.exe websocket -url wss://api.qredo.network/api/v1/p/coreclient/9niR8TyupNQspJmEXXXXXXXXXXXXXXXXQCqkmHGRW3xu/feed
url:  wss://api.qredo.network/api/v1/p/coreclient/9niR8TyupNQspJmEXXXXXXXXXXXXXXXXQCqkmHGRW3xu/feed
Hash: ef547e65e8116442f7766df44713b77cfa239ffe6c04aac0d66b38a1fa82a265
x-sign: VoYl4fMfSbYOQEnK07UBJPzPHhCCmp1WjV4528KRsdg0ZxGfsQ0BQeKg5KtuRUOI53Ko0koEzuu4Yyhpmv6UsKTVFwMJMGeBHjQ56xWTkdMxldzUevLn4HxENPAc-45JJo4B6gd4x0Wa9d1qILDW0gnizYJnemeHgCJwiuZy6DUPr2iKdl_mfzsqTjsmOJXKW5SJ-Gt_nxl_BXGAKsFBriP0ASGzYBKe8jZS2jRvAJKzR0_615j7iQMz6Ie64rMRP4O7RqVLDgL98V8EQqs9xkqiVB_C8zYfkuN6KW09rJ2_jlDjfket7jPYJLyW87IFflcmU7JLVmr1nS0xnunLgA
x-timestamp: 1636125880
connecting to wss://api.qredo.network/api/v1/p/coreclient/9niR8TyupNQspJmEXXXXXXXXXXXXXXXXQCqkmHGRW3xu/feed
connected

Your core client is connected and your feed is live

From the moment your core client connects, any transaction or withdrawal request (from a wallet that uses this core client as a custodian) will be displayed in the CLI.

See the websocket feed examples below.

Now that you are connected to your feed, you start to receive transactions pending approval.

Receive live feed

When you have set up and connected your core client as explained above, you will be getting feed with each request for transactions out of Qredo wallets that this core client applies custody to.

Core client gets feed for specified wallets only

Do not forget that the core client must be an appointed custodian for transactions out a wallet and all transaction/withdrawal requests pertain to such wallets only.

Note that if your core client disconnects from the websocket feed, you must reconnect it manually again in order to start receiving your feed again. Once you reconnect, the core client will print out all current requests pending approval, including ones that have been submitted while the core client was disconnected.

Query for queued up requests

When the core client is disconnected, it obviously cannot receive requests. Regardless of the live feed, you can check out if there are transaction/withdrawal requests queued up using the GET coreclient/{client_id}/actions resource as explained in the next section: Core client custody.

Transaction feed

When a transaction request out your wallet is submitted, the core client CLI window prints out transaction requests formatted as follows:

{
  "coreClientID": "<core client ID, e.g.: '9niR8TyupNQspJmEXXXXXXXXXXXXXXXXQCqkmHGRW3xu'>",
  "expireTime": "<timestamp in Epoch when request expires, e.g. 1637855804>",
  "id": "<action ID, e.g.: 21Mg07BDBE09AARwUPJcVQT0fnO>",
  "status": "<tx status: 'pending'>",
  "timestamp": "<timestamp in Epoch when request was submitted, e.g. 1637756144>",
  "type": "<type of transaction to approve: 'ApproveTransfer' for transfer>"
}

The action id is not the same as tx_id

Do not mistake the tx_id you receive with each transaction request for the id received on the core client side. This difference is obvious in the JSON response of the GET /transfer/{tx_id} request where the actionID is listed as part of the tx object.

Withdrawal feed

If you perform tests with withdrawals, do not forget to have the destination withdrawal wallet whitelisted, as explained in the Partner API walkthrough Step 6: Perform a withdrawal.

When a withdrawal request out your wallet is submitted, the core client CLI window prints it out in format similar to that of a transaction request:

{
  "coreClientID": "<core client ID, e.g.: '9niR8TyupNQspJmEXXXXXXXXXXXXXXXXQCqkmHGRW3xu'>",
  "expireTime": "<timestamp in Epoch when request expires, e.g. 1699998800>",
  "id": "<action ID, e.g.: 21PWl0QKlKfOIkXbhdwxSinEsK2>",
  "status": "<tx status: 'pending'>",
  "timestamp": "<timestamp in Epoch when request was submitted, e.g. 1637843349>",
  "type": "<type of transaction to approve: 'ApproveWithdraw' for withdrawal"
}

Transfer vs Withdrawal in feed

Notice that the format with both request types is the same with the exception that transfers appear of type ApproveTransfer while withdrawals are of type ApproveWithdraw.

Atomic swaps feed

The atomic swap is a transaction type that two counterparties swap assets, e.g. some BTC in exchange for some ETH. This means both counterparties have a swap transfer out transaction. These are covered in detail in the Atomic swaps section.


Last update: 2021-12-17