UNPKG

blockchain-api-client

Version:

Blockchain Api Client which maps Results of all supported Blockchain API's into a unified interface

34 lines (28 loc) 1.22 kB
import { Endpoints } from "../../../base/endpoints"; import { Network } from "../../../base/types"; // TODO Deal with different Blockchains e.g. what if /btc/ should be /eth/ export const blockCypherEndpoints = (network: Network): Endpoints => { const networkPath = getNetworkPath(network); return { balance: function (address: string): string { return `https://api.blockcypher.com/v1/btc/${networkPath}/addrs/${address}/full`; }, transactions: function (address: string, query: URLSearchParams): string { return `https://api.blockcypher.com/v1/btc/${networkPath}/addrs/${address}/full?${query.toString()}`; }, utxo: function (transactionHash: string, index: number): string { return `https://api.blockcypher.com/v1/btc/${networkPath}/txs/${transactionHash}/${index}`; }, fees: function (): string { return "https://api.blockcypher.com/v1/btc/" + networkPath; }, broadcastTransaction: function (): string { return `https://api.blockcypher.com/v1/btc/${networkPath}/txs/push`; }, }; }; const getNetworkPath = (network: Network) => { if (network === "MAIN") return "main"; if (network === "TEST") return "test3"; return "test3"; };