Перейти к содержанию

Blockchain Connector BTC-like Service API

Review

For each supported blockchain, a set of endpoints is available, allowing you to create a transaction, sign it, send it to the network, and retrieve an address from a public key.

Request parameters embedded in the URL, such as the blockchain identifier, are mandatory. Parameters in the query string or JSON body of the request can be optional and are described in detail in the corresponding sections.

Server address: https://cloud.spatium.net/blockchain-connector-btc-like/v1 Swagger

For this server address, interaction with the following blockchains is available:

  • btc;
  • ltc;
  • bch.

The structure of requests and information in responses is the same for them.

Data types

Network

Network - network type. As a rule, blockchains support at least two options: a test network for development (testnet) with fictitious assets and a stable production network (livenet) with real assets. Data structure:

type Network = 'livenet' | 'testnet';

AddressType

AddressType - Legacy (p2pkh) or SegWit (p2wpkh) address format, applicable only for Bitcoin and Litecoin blockchains. Data structure:

type AddressType = 'p2pkh' | 'p2wpkh';

UTXO

UTXO - unspent transaction output. Data structure:

type UTXO = {
  txid: string;
  vout: number;
  value: string;
};

  • txid - transaction identifier;
  • vout - output identifier in this transaction;
  • value - amount.

API

Generate Address from Public Key

Swagger Get address

Request Structure

POST /api/get-address/{chain}

{
   publicKey: string;
   network?: Network;
   type?: AddressType;
   prefix?: boolean;
}
{
  requestId: string;
  data: {
    address: string;
  };
}

Parameters

  • publicKey - public key, required parameter, string,

  • network - network type, optional parameter, default value 'livenet' (Network),

  • type - address format, optional parameter, default value 'p2wpkh', for bch this parameter is ignored (AddressType),

  • prefix - true if address contains prefix, optional parameter, default value false (boolean).

Getting Data to Form a Transaction

To form and estimate transaction fee it is required to get the following set of data:

  • UTXO list,
  • transaction size,
  • price per byte.

Swagger Prepare transaction API

Estimate endpoint allows you to get all data required for transaction formation and estimation with one request. Also there is a possibility to get this data in three separate requests: (utxo-list, size, price-per-byte).

Estimate

This endpoint provides all the data required for transaction formation and estimation

Swagger Prepare transaction Estimate

Request Structure

POST api/prepare-transaction/estimate/{chain}

{
   address: string;
   publicKey: string;
   network?: Network;
   type?: AddressType;
   to: string;
   amount: string;
}
{
  requestId: string;
  data: {
    utxo: UTXO[];
    size: number;
    fees: { normal: string; fast: string; slow: string };
  };
}

Parameters

  • address - sender address, required parameter, string,

  • publicKey - public key, required parameter, string,

  • network - network type, optional parameter, default value 'livenet' (Network),

  • type - address format, optional parameter, default value 'p2wpkh', for bch this parameter is ignored (AddressType),

  • to - recepient address, required parameter, string,

  • amount - amount in internal integer format, required parameter, string,

UTXO list

UTXO list is required to form a correct transaction and estimate its size

Swagger Prepare transaction UTXO

Request Structure

GET /api/prepare-transaction/utxo-list/{chain}?address={address}&network=livenet

Parameters

  • address - sender address, required parameter, string,

  • network - network type, optional parameter, default value 'livenet' (Network),

Response structure

{
 requestId: string;
 data: { utxo: UTXO[] };
}

Transaction size

Transaction size is required to accurately estimate transaction fee size.

Swagger Prepare transaction Size

Request Structure

POST /api/prepare-transaction/size/{chain}

{
   publicKey: string;
   network?: Network;
   type?: AddressType;
   utxo: UTXO[];
   to: string;
   amount: string;
}
{
  requestId: string;
  data: {
    size: number;
  };
}

Parameters

  • publicKey - public key, required parameter, string,

  • network - network type, optional parameter, default value 'livenet' (Network),

  • type - address format, optional parameter, default value 'p2wpkh', for bch this parameter is ignored (AddressType),

  • utxo - a list of unspent transaction outputs, required parameter (UTXO),

  • to - recepient address, required parameter, string,

  • amount - amount in internal integer format, required parameter, string,

Price per Byte

Satosha price for one byte of transaction size. It's necessary to estimate the transaction fee correctly. The amount depends on the sending mode (slow, normal, fast). The final transaction fee is calculated as a product of a transaction size and a satosha sum per byte for the chosen sending mode.

Swagger Prepare transaction Price per byte

Request Structure

GET /api/prepare-transaction/price-per-byte/{chain}?network=livenet

Parameters

  • network - network type, optional parameter, default value 'livenet' (Network),

Response structure

{
 requestId: string;
 data: { bytePrices: { normal: string; fast: string; slow: string } };
}

Transactions

Swagger Transaction API

Getting a Transaction Hash

Swagger Transaction Get hash

Request Structure

POST /api/transaction/get-hash/{chain}

{
   publicKey: string;
   network?: Network;
   type?: AddressType;
   utxo: UTXO[];
   to: string;
   amount: string;
   fee: string;
}
{
  requestId: string;
  data: { hashes: { inputIndex: number; hash: string }[] };
}

Parameters

  • publicKey - public key, required parameter, string,

  • network - network type, optional parameter, default value 'livenet' (Network),

  • type - address format, optional parameter, default value 'p2wpkh', for bch this parameter is ignored (AddressType),

  • utxo - a list of unspent transaction outputs, required parameter (UTXO),

  • to - recepient address, required parameter, string,

  • amount - amount in internal integer format, required parameter, string,

  • fee - transaction commission, required parameter, string,

Transaction Signing

Swagger Transaction Attach signature

Request Structure

POST /api/transaction/attach-signature/{chain}

{
   publicKey: string;
   network?: Network;
   type?: AddressType;
   utxo: UTXO[];
   to: string;
   amount: string;
   fee: string;
   signatures: {
       inputIndex: number;
       signature: {
         s: string;
         r: string;
         recovery: number;
       };
   }[];
}
{
  requestId: string;
  data: { txdata: string };
}

Parameters

  • publicKey - public key, required parameter, string,

  • network - network type, optional parameter, default value 'livenet' (Network),

  • type - address format, optional parameter, default value 'p2wpkh', for bch this parameter is ignored (AddressType),

  • utxo - a list of unspent transaction outputs, required parameter (UTXO),

  • to - recepient address, required parameter, string,

  • amount - amount in internal integer format, required parameter, string,

  • fee - transaction commission, required parameter, string,

  • signatures - array of objects with signing data, required parameter.

Sending Transaction to Network

Swagger Transaction Send

Request Structure

POST /api/transaction/send/{chain}

{
   txdata: string;
   network?: Network;
}
{
  requestId: string;
  data: { txid: string };
}

Parameters

  • txdata - signed transaction data, required parameter, string,

  • network - network type, optional parameter, default value 'livenet' (Network),