Skip to content

Latest commit

 

History

History
835 lines (660 loc) · 17.9 KB

api-documentation.md

File metadata and controls

835 lines (660 loc) · 17.9 KB

API Documentation

Transactions

Send Raw Transaction

POST /api/BTC/mainnet/tx/send

Response
Use Curl command in terminal to get a response
curl -v POST -H "Content-Type: application/json" -d '{"rawTx":"02000000016ac3043549876ec53aa8bd4a0839c07f52211a6b880920418cbb20b54142f1cf000000006a473044022013bfe2132c843196c43993a3562868ed26b58b5667bc3f934216afcf1643b51102206d7676a5efca242255b4f9fbd1db41273164c82723b0e01f6a324e68971aacf80121035165d8ce5fa0890e14c76bdf22cdc8be9c5ee12080aad89f897cb2026b1aba2cffffffff02706f9800000000001976a914c7cb6d4f64bf68c37a052fb094f2e0ff385e8b0a88ac804a5d05000000001976a914bb89aec81ebb0812532c34d5ee997e7319012c5c88ac00000000"}' "http://localhost:3000/api/BTC/mainnet/tx/send"
{
    "txid": "3b96bb7e197ef276b85131afd4a09c059cc368133a26ca04ebffb0ab4f75c8b8"
}

Get Transactions by blockHeight

GET /api/BTC/mainnet/tx?blockHeight=12

Response
Use Curl command in terminal to get a response
curl -v localhost:3000/api/BTC/mainnet/tx?blockHeight=12
[
    {
        "_id": "5c34b35d69d5562c2fc44026",
        "txid": "3b96bb7e197ef276b85131afd4a09c059cc368133a26ca04ebffb0ab4f75c8b8",
        "network": "mainnet",
        "chain": "BTC",
        "blockHeight": 12,
        "blockHash": "0000000027c2488e2510d1acf4369787784fa20ee084c258b58d9fbd43802b5e",
        "blockTime": "2009-01-09T04:21:28.000Z",
        "blockTimeNormalized": "2009-01-09T04:21:28.000Z",
        "coinbase": true,
        "locktime": -1,
        "inputCount": 1,
        "outputCount": 1,
        "size": 134,
        "fee": -1,
        "value": 5000000000,
        "confirmations": 99754
    }
]

Get Transactions by blockHash

GET /api/BTC/mainnet/tx?blockHash=000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/tx?blockHash=000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd
[
    {
        "_id": "5c34b35d69d5562c2fc43eff",
        "txid": "9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5",
        "network": "mainnet",
        "chain": "BTC",
        "blockHeight": 2,
        "blockHash": "000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd",
        "blockTime": "2009-01-09T02:55:44.000Z",
        "blockTimeNormalized": "2009-01-09T02:55:44.000Z",
        "coinbase": true,
        "locktime": -1,
        "inputCount": 1,
        "outputCount": 1,
        "size": 134,
        "fee": -1,
        "value": 5000000000,
        "confirmations": 102293
    }
]

Get Transaction by txid

GET /api/BTC/mainnet/tx/:txid

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/tx/9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5
{
    "_id": "5c34b35d69d5562c2fc43eff",
    "txid": "9b0fc92260312ce44e74ef369f5c66bbb85848f2eddd5a7a1cde251e54ccfdd5",
    "network": "mainnet",
    "chain": "BTC",
    "blockHeight": 2,
    "blockHash": "000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd",
    "blockTime": "2009-01-09T02:55:44.000Z",
    "blockTimeNormalized": "2009-01-09T02:55:44.000Z",
    "coinbase": true,
    "locktime": -1,
    "inputCount": 1,
    "outputCount": 1,
    "size": 134,
    "fee": -1,
    "value": 5000000000,
    "confirmations": 102293
}

Get Authhead

GET /BTC/mainnet/tx/:txid/authhead

Response
Use Curl command in terminal to get a response
curl -v localhost:3000/api/BTC/mainnet/tx/3b96bb7e197ef276b85131afd4a09c059cc368133a26ca04ebffb0ab4f75c8b8/authhead
{
    "authbase": "3b96bb7e197ef276b85131afd4a09c059cc368133a26ca04ebffb0ab4f75c8b8",
    "chain": "BTC",
    "identityOutputs": [],
    "network": "mainnet"
}

Get Coins

GET /BTC/mainnet/tx/:txid/coins

Response
Use Curl command in terminal to get a response
curl -v localhost:3000/api/BTC/mainnet/tx/3b96bb7e197ef276b85131afd4a09c059cc368133a26ca04ebffb0ab4f75c8b8/coins
{
    "inputs": [],
    "outputs": [
        {
          "address": "1EVzaFkkNNXq6RJh2oywwJMn8JPiq8ikDi",
          "chain": "BTC",
          "coinbase": true,
          "confirmations": -1,
          "mintHeight": 568302,
          "mintIndex": 0,
          "mintTxid": "4e9d6f0602ead97ad54c47530c7adeb2384edc21f3a8968ae62204c2797cdaef",
          "network": "mainnet",
          "script": "76a91494155788e7233d7bea9aa29feb2ed37bc878c40b88ac",
          "spentHeight": -2,
          "spentTxid": "",
          "value": 1272312279,
          "_id": "5c94f52512025b0a390269b3"
        },
        {
          "address": "false",
          "chain": "BTC",
          "coinbase": true,
          "confirmations": -1,
          "mintHeight": 568302,
          "mintIndex": 1,
          "mintTxid": "4e9d6f0602ead97ad54c47530c7adeb2384edc21f3a8968ae62204c2797cdaef",
          "network": "mainnet",
          "script": "6a24aa21a9eda7e97a9c6ca28da3a62a0330946682f8c5d2aae854990ada44329e61c4d84111",
          "spentHeight": -2,
          "spentTxid": "",
          "value": 0,
          "_id": "5c94f52512025b0a390269b6"
        }
    ]
}

Address

Get Address Transactions

GET /api/BTC/mainnet/address/:address/txs

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/address/12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX/txs
[
    {
        "_id": "5bd0b60d19b81e4567d3a10d",
        "chain": "BTC",
        "network": "mainnet",
        "coinbase": true,
        "mintIndex": 0,
        "spentTxid": "",
        "mintTxid": "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
        "mintHeight": 1,
        "spentHeight": -2,
        "address": "12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX",
        "script": "410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac",
        "value": 5000000000,
        "confirmations": -1
    },
    {
        "_id": "5bd0be3f6d88cf473695b007",
        "chain": "BTC",
        "network": "mainnet",
        "coinbase": false,
        "mintIndex": 1,
        "spentTxid": "",
        "mintTxid": "d6be34ccf6edddc3cf69842dce99fe503bf632ba2c2adb0f95c63f6706ae0c52",
        "mintHeight": 127659,
        "spentHeight": -2,
        "address": "12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX",
        "script": "76a914119b098e2e980a229e139a9ed01a469e518e6f2688ac",
        "value": 2000000,
        "confirmations": -1
    },
    ...
]

Get Transaction Outputs by Address

GET /api/BTC/mainnet/address/:address/?unspent=true

if you want to filter out conflicting utxos, you can add excludeConflicting=true to the end of the url.

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/address/12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX/?unspent=true
[
    {
        "_id": "5c34b35d69d5562c2fc43e89",
        "chain": "BTC",
        "network": "mainnet",
        "coinbase": true,
        "mintIndex": 0,
        "spentTxid": "",
        "mintTxid": "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
        "mintHeight": 1,
        "spentHeight": -2,
        "address": "12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX",
        "script": "410496b538e853519c726a2c91e61ec11600ae1390813a627c66fb8be7947be63c52da7589379515d4e0a604f8141781e62294721166bf621e73a82cbf2342c858eeac",
        "value": 5000000000,
        "confirmations": -1
    }
]

Get Balance for an Address

GET /api/BTC/mainnet/address/:address/balance

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/address/12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX/balance
{
    "confirmed": 5000000000,
    "unconfirmed": 0,
    "balance": 5000000000
}

Block

Get Block

GET /api/BTC/mainnet/block/:blockId

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/block/00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048
{
    "_id": "5c34b53569d5562c2fc8e65a",
    "chain": "BTC",
    "network": "mainnet",
    "hash": "00000000839a8e6886ab5951d76f411475428afc90947ee320161bbf18eb6048",
    "height": 1,
    "version": 1,
    "size": 215,
    "merkleRoot": "0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
    "time": "2009-01-09T02:54:25.000Z",
    "timeNormalized": "2009-01-09T02:54:25.000Z",
    "nonce": 2573394689,
    "bits": 486604799,
    "previousBlockHash": "000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f",
    "nextBlockHash": "000000006a625f06636b8bb6ac7b960a8d03705d1ace08b1a19da3fdcc99ddbd",
    "reward": 5000000000,
    "transactionCount": 1,
    "confirmations": 102295
}

Get Current Height

GET /api/BTC/mainnet/block/tip

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/block/tip
{
    "_id": "5c94f6da12025b0a3904ba43",
    "chain": "BTC",
    "network": "mainnet",
    "hash": "000000000000000000256c7224f97c8c508fc8b4bb5537b0d731b7d45741408a",
    "height": 568303,
    "version": 1073676288,
    "size": 857826,
    "merkleRoot": "b982461de5253a8811c8a2106d800a10d08e8a185243b863378319d759a9a899",
    "time": "2019-03-22T14:53:30.000Z",
    "timeNormalized": "2019-03-22T14:53:30.000Z",
    "nonce": 4185218842,
    "bits": 388915479,
    "previousBlockHash": "0000000000000000002254ad0d85d25bb554f7a85f88130934fd67451653477c",
    "nextBlockHash": "",
    "reward": 1275381759,
    "transactionCount": 1644,
    "confirmations": 1
}

Authenticated Methods

Wallet

To test wallet api routes change allowUnauthenticatedCalls: true inside bitcore.config.json

"bitcoreNode": {
    "services": {
        "api": {
            "wallets": {
                "allowCreationBeforeCompleteSync": true
            }
        }
    },
    ...
}

Create 5 Sample Wallets with transactions, addresses, and UTXOS

Inside the project root directory /bitcore/ run:

node packages/bitcore-node/build/test/benchmark/wallet-benchmark.js

Add Wallet

POST /api/BTC/mainnet/wallet

BODY:

{
    "name": "WalletName2",
    "chain": "BTC",
    "network": "mainnet",
    "pubKey": "03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d",
    "path": "m/44'/0'/0'"
}
Response

Use Curl command in terminal to get a response

curl -v POST -H "Content-Type: application/json" -d '{
  "name": "WalletName2",
  "chain": "BTC",
  "network": "mainnet",
  "pubKey": "03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d",
  "path": "m/44'/0'/0'"
}'
"http://localhost:3000/api/BTC/mainnet/wallet/"
{
    "chain": "BTC",
    "network": "mainnet",
    "name": "WalletName2",
    "pubKey": "03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d",
    "path": "m/44'/0'/0'",
    "_id": "5c3631e538704e27c6f146c3"
}

Get Wallet

GET /api/BTC/mainnet/wallet/:pubKey

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/wallet/03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d
{
    "_id": "5c3639d1e60f7b2e174afc65",
    "chain": "BTC",
    "network": "mainnet",
    "name": "WalletName",
    "pubKey": "03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d",
    "path": "m/44'/0'/0'",
    "singleAddress": null
}

Import Addresses

POST /api/BTC/mainnet/wallet/:pubKey

BODY: raw jsonl wallet file of the form

{
    "address": "mmEsgUprBEQkGDKowPQSLEYDbMtGRKxaF4"
}
Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/wallet/03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d
{
    "_id": "5c3639d1e60f7b2e174afc65",
    "chain": "BTC",
    "network": "mainnet",
    "name": "WalletName",
    "pubKey": "03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d",
    "path": "m/44'/0'/0'",
    "singleAddress": null
}

Get Wallet Addresses

GET /api/BTC/mainnet/wallet/:pubKey/addresses

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/wallet/03bdb94afdc7e5c4811bf9b160ac475b82156ea42c8659c8358b68c828df9a1c3d/addresses
[
    {
        "address": "12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX"
    },
    {
        "address": "1HLoD9E4SDFFPDiYfNYnkBLQ85Y51J3Zb1"
    },
    {
        "address": "1FvzCLoTPGANNjWoUo6jUGuAG3wg1w4YjR"
    }
]

Get Wallet Transactions

GET /api/BTC/mainnet/wallet/:pubKey/transactions

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/wallet/02870d8366cf8e50f383e38e5fafc01d956b67f25fbf5c1dd4e3766cf85acbc400/transactions
[
    {
        "id":"5c34b35d69d5562c2fc43e8c",
        "txid":"0e3e2357e806b6cdb1f70b54c3a3a17b6714ee1f0e68bebb44a74b1efd512098",
        "fee":0,"size":134,
        "category":"receive",
        "satoshis":5000000000,
        "height":1,
        "address":"12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX",
        "outputIndex":0,
        "blockTime":"2009-01-09T02:54:25.000Z"
    }
]

Get Balance

GET /api/BTC/mainnet/wallet/:pubKey/balance

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/wallet/02870d8366cf8e50f383e38e5fafc01d956b67f25fbf5c1dd4e3766cf85acbc400/balance
{
    "confirmed": 46800000000,
    "unconfirmed": 0,
    "balance": 46800000000
}

Get Wallet UTXOS

GET /api/BTC/mainnet/wallet/:pubKey/utxos

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/wallet/02870d8366cf8e50f383e38e5fafc01d956b67f25fbf5c1dd4e3766cf85acbc400/utxos
[
    {
        "_id": "5c34b36069d5562c2fc45b09",
        "chain": "BTC",
        "network": "mainnet",
        "coinbase": false,
        "mintIndex": 1,
        "spentTxid": "",
        "mintTxid": "828ef3b079f9c23829c56fe86e85b4a69d9e06e5b54ea597eef5fb3ffef509fe",
        "mintHeight": 248,
        "spentHeight": -2,
        "address": "12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S",
        "script": "410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac",
        "value": 1800000000,
        "confirmations": 103006
    }
]

Get Wallet UTXOS

GET /api/BTC/mainnet/wallet/:pubKey/utxos

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/wallet/02870d8366cf8e50f383e38e5fafc01d956b67f25fbf5c1dd4e3766cf85acbc400/addresses/missing
[
    {
        "_id": "5c34b36069d5562c2fc45b09",
        "chain": "BTC",
        "network": "mainnet",
        "coinbase": false,
        "mintIndex": 1,
        "spentTxid": "",
        "mintTxid": "828ef3b079f9c23829c56fe86e85b4a69d9e06e5b54ea597eef5fb3ffef509fe",
        "mintHeight": 248,
        "spentHeight": -2,
        "address": "12cbQLTFMXRnSzktFkuoG3eHoMeFtpTu3S",
        "script": "410411db93e1dcdb8a016b49840f8c53bc1eb68a382e97b1482ecad7b148a6909a5cb2e0eaddfb84ccf9744464f82e160bfa9b8b64f9d4c03f999b8643f656b412a3ac",
        "value": 1800000000,
        "confirmations": 103006
    }
]

Fee

Get Fee estimate for within N blocks

GET /api/BTC/mainnet/fee/:target

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/fee/22
{
    "blocks": "22",
    "feerate": "0.00002003"
}

Get Priority Fee estimate at a percentile level (type 2 EVM transactions)

GET /api/ETH/mainnet/priorityFee/:percentile

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/ETH/mainnet/priorityFee/15
{
    "feerate": "0.02003"
}

Stats

Get Daily Transactions

GET /api/BTC/mainnet/stats/daily-transactions

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/BTC/mainnet/stats/daily-transactions
{
    "chain": "BTC",
    "network": "mainnet",
    "results":
    [
        {
            "date": "2009-01-09",
            "transactionCount": 14
        },
        {
            "date": "2009-01-10",
            "transactionCount": 61
        },
        ...
    ]
}

Status

Get Enabled Chains

GET /api/status/enabled-chains

Response

Use Curl command in terminal to get a response

curl -v localhost:3000/api/status/enabled-chains
[
    {
        "chain": "BTC",
        "network": "mainnet"
    },
    {
        "chain": "BTC",
        "network": "testnet"
    },
    {
        "chain": "BCH",
        "network": "mainnet"
    },
    {
        "chain": "BCH",
        "network": "testnet"
    }
]