Skip to content

πŸͺ™ Node.js RESTful API for bitcoin blockchain

License

Notifications You must be signed in to change notification settings

bitchain/bitcoin-api

Repository files navigation

bitcoin-api

CircleCI CI

This project is a proof of concept for the Bitcoin's Mainnet and Testnet. This RESTful API is designed to support multiple blockchain providers. Can be an external API like BlockCypher or even a full node. The goal is to ensure availability even if one of the providers is offline.

You can access the /shared/providers folder to create your own implementation.

βœ… Main Features

  • Shows the Wallet Balance
  • Shows the Wallet Transactions History
  • Creates a Wallet
  • Shows Transaction details
  • Creates and Broadcast a Transaction
  • Supports multiple Bitcoin providers

🌍 Ecosystem

Below the technologies, used to build this API:

Name Status
node version
express version
axios version
typescript version
celebrate version
eslint version
bitcore version

▢️ Getting started

$ git clone https://github.com/bitchain/bitcoin-api.git

$ cd bitcoin-api

$ npm install

$ npm run dev:server

This will launch the Network service at http://localhost:3333/.

🟣 GET

/wallets/:address: Get wallet balance and transactions history

:address is a string representing the public address you're interested in querying.

Example: tb1qe8ayn3j3adu72496v48v5cvj40gqpjz09uh800

Response example
{
  "address": "tb1qe8ayn3j3adu72496v48v5cvj40gqpjz09uh800",
  "balance": 1030000,
  "confirmedBalance": 1030000,
  "unconfirmedBalance": 0,
  "transactionsReference": [
    {
      "transactionId": "d8db85b8aa834bab65c59eac0159ad166c3b89e09a06520412c9821e71222f52",
      "confirmations": 10,
      "value": 10000,
      "blockHeight": 1938604
    },
    ...
  ]
}

/transactions/:id: Get transaction information

:id is a string representing the hex-encoded transaction hash you're interested in querying.

Example: d3571c42e5379ea70bce0c2c3c571018a293c5598dad4b2e0c0b7b4f0e625c53

Response example
{
  "id": "d3571c42e5379ea70bce0c2c3c571018a293c5598dad4b2e0c0b7b4f0e625c53",
  "fee": 24547,
  "confirmations": 4,
  "date": "2021-03-02T21:02:23.000Z",
  "transactionInput": [
    {
      "address": "tb1q3yyq37lalgq0chareur9yykgtgpqwztt5uezvz",
      "value": 78836818
    },
    ...
  ],
  "transactionOutput": [
    {
      "address": "mhfNudm6YDYnYkegFSjcsppucpAA8TRviD",
      "value": 100000000
    },
    ...
  ]
}

🟒 POST

/wallets/create: Create a new Wallet

privateKey is a secret number that allows bitcoins to be spent, so be careful when handling it!

Response example
{
  "address": "mffzq5WLcJVsokpSjVgPmjPmUCK5K2UoZN",
  "privateKey": "cW33mrcvCY2YzoFegug4xfQ8U4yNEAeLRUs2z78ZwCwb4w1Fn35K"
}

/transactions/fee: Get estimated fee for a transaction

Request example
{
  "addressFrom": "muwAf337HUDpuajeA2yERod4bPZyWpcqbd",
  "addressTo": "mjDaJzEDCjiS86jJWmpn38nGe2A9N7EStd",
  "value": 10000
}
Response example
{
  "transactionEstimatedFee": 15200
}

/transactions/create: Create and broadcast a transaction

Request example
{
  "privateKey": "cW33mrcvCY2YzoFegug4xfQ8U4yNEAeLRUs2z78ZwCwb4w1Fn35K",
  "addressTo": "muwAf337HUDpuajeA2yERod4bPZyWpcqbd",
  "value": 1000
}
Response example
{
  "id": "9b04e5034e547e0e47291488a2986e5120b0dd38e01541f7ee71136d2a676877",
  "fee": 13700,
  "transactionInput": [
    {
      "address": "mjDaJzEDCjiS86jJWmpn38nGe2A9N7EStd",
      "value": 41700
    }
  ],
  "transactionOutput": [
    {
      "address": "muwAf337HUDpuajeA2yERod4bPZyWpcqbd",
      "value": 1000
    },
    ...
  ]
}

NOTE: All currency amounts are in units of satoshis (1/100,000,000 of a Bitcoin).

πŸ’» Development Process

The contribution workflow is described in CONTRIBUTING.md.

πŸ“ License

Bitchain Network is released under the MIT License. Please refer to the LICENSE file that accompanies this project for more information including complete terms and conditions.