REST API for Pine to interact with the bitcoin blockchain and network.
-
Install btcd
-
Start the btcd node with transaction and address indexing turned on:
$ btcd --txindex --addrindex
-
Clone this repo:
$ git clone https://github.com/blockfirm/pine-api.git $ cd pine-api
-
Install dependencies:
$ npm install
-
Open
src/config.js
and enter your btcd RPC username and password -
Start the API server in development mode:
$ npm run dev
-
Or build it and run in production mode:
$ npm run build $ npm start
Endpoints for retrieving and submitting information to the bitcoin blockchain and network.
Method | Endpoint | Description |
---|---|---|
GET | /v1/info | Get information about the server |
GET | /v1/bitcoin/transactions | Get transactions by address |
POST | /v1/bitcoin/transactions | Broadcast a signed transaction |
GET | /v1/bitcoin/transactions/:txid | Get a specific transaction by its ID |
GET | /v1/bitcoin/fees/estimate | Get the current estimated transaction fee rate |
GET | /v1/bitcoin/fiatrates | Not implemented yet |
POST | /v1/bitcoin/pushnotifications | Not implemented yet |
DELETE | /v1/bitcoin/pushnotifications | Not implemented yet |
Returns information about the server.
{
"isConnected": true, (boolean) Whether or not the server is connected to a bitcoin node
"network": "testnet", (string) "mainnet" or "testnet"
"blocks": n (integer) The number of blocks processed
}
Scans the bitcoin blockchain for transactions matching a set of addresses.
Name | Type | Description |
---|---|---|
addresses | string | Comma-separated list of addresses to get transactions for. Maximum 20 addresses are allowed per request. |
page | integer | What page to get transactions for. The number of transactions depends on the page_size parameter. |
page_size | integer | Number of transactions to return per address for each page. Must be between 1 and 100 (defaults to 100). |
reverse | boolean | 1 specifies that the transactions should be returned in reverse chronological order. Defaults to 0 (false). |
Returns the transactions together with extra vin data and other useful information about each transaction, e.g. whether it is pending or not. Here's an example return copied from https://github.com/btcsuite/btcd/blob/master/docs/json_rpc_api.md#searchrawtransactions:
[
{
"hex": "data", (string) hex-encoded transaction
"txid": "hash", (string) the hash of the transaction
"version": n, (numeric) the transaction version
"locktime": n, (numeric) the transaction lock time
"vin": [ the transaction inputs as json objects
For coinbase transactions:
{
"coinbase": "data", (string) the hex-encoded bytes of the signature script
"txinwitness": “data", (string) the witness stack for the input
"sequence": n, (numeric) the script sequence number
}
For non-coinbase transactions:
{
"txid": "hash", (string) the hash of the origin transaction
"vout": n, (numeric) the index of the output being redeemed from the origin transaction
"scriptSig": { the signature script used to redeem the origin transaction
"asm": "asm", (string) disassembly of the script
"hex": "data", (string) hex-encoded bytes of the script
}
"prevOut": { data from the origin transaction output with index vout
"addresses": ["value",...], (array of string) previous output addresses
"value": n.nnn, (numeric) previous output value
}
"txinwitness": “data", (string) the witness stack for the input
"sequence": n, (numeric) the script sequence number
}, ...
],
"vout": [ the transaction outputs as json objects
{
"value": n, (numeric) the value in BTC
"n": n, (numeric) the index of this transaction output
"scriptPubKey": { the public key script used to pay coins
"asm": "asm", (string) disassembly of the script
"hex": "data", (string) hex-encoded bytes of the script
"reqSigs": n, (numeric) the number of required signatures
"type": "scripttype" (string) the type of the script (e.g. 'pubkeyhash')
"addresses": [ the bitcoin addresses associated with this output
"address", (string) the bitcoin address
...
]
}
}, ...
],
"blockhash": "hash" hash of the block the transaction is part of
"confirmations": n, number of numeric confirmations of block
"time": t, transaction time in seconds since the epoch
"blocktime": t, block time in seconds since the epoch
}, ...
]
Broadcasts a transaction to the Bitcoin network. The transaction must be serialized in raw format (https://bitcoin.org/en/developer-reference#raw-transaction-format).
Encoded as JSON.
Name | Type | Description |
---|---|---|
transaction | string | Serialized and signed transaction in raw format. |
{
"txid": "data" (string) The hash of the transaction
}
Returns a specific transaction based on its id.
Name | Type | Description |
---|---|---|
txid | string | Transaction hash for the transaction to get. |
Returns the transaction together with extra vin data and other useful information, e.g. whether it is pending or not. Here's an example return copied from https://github.com/btcsuite/btcd/blob/master/docs/json_rpc_api.md#getrawtransaction:
{
"hex": "data", (string) hex-encoded transaction
"txid": "hash", (string) the hash of the transaction
"version": n, (numeric) the transaction version
"locktime": n, (numeric) the transaction lock time
"vin": [ the transaction inputs as json objects
For coinbase transactions:
{
"coinbase": "data", (string) the hex-encoded bytes of the signature script
"txinwitness": “data", (string) the witness stack for the input
"sequence": n, (numeric) the script sequence number
}
For non-coinbase transactions:
{
"txid": "hash", (string) the hash of the origin transaction
"vout": n, (numeric) the index of the output being redeemed from the origin transaction
"scriptSig": { the signature script used to redeem the origin transaction
"asm": "asm", (string) disassembly of the script
"hex": "data", (string) hex-encoded bytes of the script
}
"prevOut": { data from the origin transaction output with index vout
"addresses": ["value",...], (array of string) previous output addresses
"value": n.nnn, (numeric) previous output value
}
"txinwitness": “data", (string) the witness stack for the input
"sequence": n, (numeric) the script sequence number
}, ...
],
"vout": [ the transaction outputs as json objects
{
"value": n, (numeric) the value in BTC
"n": n, (numeric) the index of this transaction output
"scriptPubKey": { the public key script used to pay coins
"asm": "asm", (string) disassembly of the script
"hex": "data", (string) hex-encoded bytes of the script
"reqSigs": n, (numeric) the number of required signatures
"type": "scripttype" (string) the type of the script (e.g. 'pubkeyhash')
"addresses": [ the bitcoin addresses associated with this output
"address", (string) the bitcoin address
...
]
}
}, ...
],
"blockhash": "hash" hash of the block the transaction is part of
"confirmations": n, number of numeric confirmations of block
"time": t, transaction time in seconds since the epoch
"blocktime": t, block time in seconds since the epoch
}
Estimates the transaction fee to be confirmed in the next number of blocks specified by numberOfBlocks
.
Name | Type | Description |
---|---|---|
numberOfBlocks | integer | Number of blocks the transaction can wait until being confirmed. Defaults to 1. |
{
"satoshisPerByte": 4.7 (number) The estimated fee per byte in satoshis
}
Not yet implemented. Gets the current exchange rates for bitcoin in different fiat currencies.
Name | Type | Description |
---|---|---|
currencies | string | Comma-separated list of ISO 4217 codes. |
Array of fiat exchange rates for the specified currencies.
Not yet implemented. An endpoint for subscribing to push notifications when new payments are received or confirmed.
Not yet implemented. An endpoint for unsubscribing to push notifications.
Errors are returned as JSON in the following format:
{
"error": "<error message>"
}
During development and testing it is recommended to use the testnet network. By doing so you can use testnet coins and don't risk losing any real money. Running a testnet node is also much lighter than running a mainnet node.
-
Run btcd with testnet
$ btcd --txindex --addrindex --testnet
-
Configure the API server to use testnet
Open
src/config.js
and setnetwork
totestnet
instead ofmainnet
. -
Configure the Pine app to use testnet
You need to configure the app to use testnet and point it to your testnet API. This requires you to build and run the app yourself. Follow the instructions in the Pine app repo.
Want to help us making Pine better? Great, but first read the CONTRIBUTING.md file for instructions.
Pine is licensed under the Apache License, Version 2.0. See LICENSE for full license text.