Inputs

substreams_bitcoin_main
Package ref
substreams-bitcoin-main@v0.1.1Run package
CLI
Run map_block_meta from the command line.
substreams run substreams-bitcoin-main@v0.1.1 map_block_meta -e btc-mainnet --start-block -1substreams auth or directly on thegraph.market (see docs).README
bitcoin_mainnet substreams modules
This package was initialized via substreams init and is being updated with custom modules to support the Bitcoin Mainnet blockchain streaming service using substreams.
Nodes available for streaming:
https://docs.substreams.dev/reference-material/chains-and-endpoints
Usage
substreams build
substreams auth
substreams gui # Get streaming!
Optionally, the substreams package can be published to the Substreams Registry
substreams registry login # Login to substreams.dev
substreams registry publish # Publish your Substreams to substreams.dev
Modules
The modules in this repository answer some interesting questions when developing a blockchain application:
How Can You Get the Basic Information of a Block?
For every block, the map_block_meta module retrieves the most relevant information of the block (number, hash, and parent hash).
How Can You Retrieve Transactions
For every block, the map_transactions modules summaries transaction number of vin and vout, the total valut of btc sent
Running the Substreams
First, generate the Protobuf code, which are the outputs of the Substreams:
> make protogen
Then, build the Rust code using the cargo command-line tool:
> make build
Now, you are ready to run the Substreams. The Substreams contained in this project are independent of each other, so you must specify which Substreams module you want to run.
Running Modules
map_block_meta
In the following command, you retrieve the metadata of the block with number 819113. You specify the starting block by using the --start-block parameter.
> substreams run -e bitcoin.substreams.pinax.network:443 substreams.yaml map_block_meta --start-block 819113 --stop-block +1
----------- BLOCK #819,113 (00000000000000000003aefe02ab07a4a7c5a27bb674b062732286a71ab1ab51) age=14887h34m15.239171s ---------------
{
"@module": "map_block_meta",
"@block": 819113,
"@type": "btc.block_meta.v1.BlockMeta",
"@data": {
"number": "819113",
"hash": "00000000000000000003aefe02ab07a4a7c5a27bb674b062732286a71ab1ab51",
"parentHash": "000000000000000000001be3e5929be506d4e2c8cd1b7ba4fa9422032434368f"
}
}
Total Read Bytes (server-side consumption): 18468136
all done
map_transactions
In the following command, you retrieve the transactions of the block with number 819113. You specify the starting block by using the --start-block parameter.
> substreams run -e bitcoin.substreams.pinax.network:443 substreams.yaml map_transactions --start-block 819113 --stop-block +1
----------- BLOCK #819,113 (00000000000000000003aefe02ab07a4a7c5a27bb674b062732286a71ab1ab51) age=14887h34m58.667977s ---------------
{
"@module": "map_transactions",
"@block": 819113,
"@type": "btc.transaction.v1.Transactions",
"@data": {
"transactions": [
{
"hash": "7fd5fc5b33bcc1ad1a8b4ec41f6e629cfecf56c59dd7ccd1ddc89a25794eadaa",
"vinCount": "1",
"voutCount": "3",
"btcValue": 6.68892541
},
{
"hash": "18400008ffffbab7c20dd958a3728b27835d829ad20281253f282d3c988c67c3",
"vinCount": "1",
"voutCount": "2",
"btcValue": 0.00271144
},
{
"hash": "b4bca993feef5317fe49c7b80ae338a21848dad92880511899c3c44ec94de9db",
"vinCount": "2",
"voutCount": "2",
"btcValue": 11.77902854
},
...
]
}
}
Total Read Bytes (server-side consumption): 18468136
all done
map_block_full
In the following command, you retrieve the full block with number 819113. You specify the starting block by using the --start-block parameter.
> substreams run -e mainnet.btc.streamingfast.io:443 substreams.yaml map_block_full --start-block 819113 --stop-block +1
----------- BLOCK #819,113 (00000000000000000003aefe02ab07a4a7c5a27bb674b062732286a71ab1ab51) age=14887h35m39.133286s ---------------
{
"@module": "map_block_full",
"@block": 819113,
"@type": "sf.bitcoin.type.v1.Block",
"@data": {
"hash": "00000000000000000003aefe02ab07a4a7c5a27bb674b062732286a71ab1ab51",
"size": 1657488,
"strippedSize": 778518,
"weight": 3993042,
"height": "819113",
"version": 549453824,
"versionHex": "20c00000",
"merkleRoot": "2bfcbd4b2c0a65cb6dca81be051585e4472b897118230421cd825048988bd9da",
"tx": [
{
"hex": "010000000001010000000000000000000000000000000000000000000000000000000000000000ffffffff4d03a97f0c1062696e616e63652f4f01810484759750fabe6d6d60ea3fe9c408ae6720935cfe1e6f27760e1b6ac15bc480a570fa0a1f57d55bbf10000000000000000000324275c2310000000000ffffffff037d7dde270000000017a914ca35b1f4d02907314852f09935b9604507f8d700870000000000000000266a24aa21a9ed03ece2a729b585010ccc51683b78d4c1fa9fb9c2962bea9e7ca52391a01f3e4a00000000000000002b6a2952534b424c4f434b3a48b0a986da46abf8c290ca66802e0bb6adb91ac2da9662a3d3973828005961910120000000000000000000000000000000000000000000000000000000000000000000000000",
"txid": "7fd5fc5b33bcc1ad1a8b4ec41f6e629cfecf56c59dd7ccd1ddc89a25794eadaa",
"hash": "02449bf72568202119ed1d46064232d6ac2138a6bb4e6751dfdccfa62ed567c1",
"size": 295,
"vsize": 268,
"weight": 1072,
"version": 1,
"vin": [
{
"sequence": 4294967295,
"txinwitness": [
"0000000000000000000000000000000000000000000000000000000000000000"
],
"coinbase": "03a97f0c1062696e616e63652f4f01810484759750fabe6d6d60ea3fe9c408ae6720935cfe1e6f27760e1b6ac15bc480a570fa0a1f57d55bbf10000000000000000000324275c2310000000000"
}
],
"vout": [
{
"value": 6.68892541,
"scriptPubKey": {
"asm": "OP_HASH160 ca35b1f4d02907314852f09935b9604507f8d700 OP_EQUAL",
"hex": "a914ca35b1f4d02907314852f09935b9604507f8d70087",
"type": "scripthash"
}
},
{
"n": 1,
"scriptPubKey": {
"asm": "OP_RETURN aa21a9ed03ece2a729b585010ccc51683b78d4c1fa9fb9c2962bea9e7ca52391a01f3e4a",
"hex": "6a24aa21a9ed03ece2a729b585010ccc51683b78d4c1fa9fb9c2962bea9e7ca52391a01f3e4a",
"type": "nulldata"
}
},
{
"n": 2,
"scriptPubKey": {
"asm": "OP_RETURN 52534b424c4f434b3a48b0a986da46abf8c290ca66802e0bb6adb91ac2da9662a3d397382800596191",
"hex": "6a2952534b424c4f434b3a48b0a986da46abf8c290ca66802e0bb6adb91ac2da9662a3d397382800596191",
"type": "nulldata"
}
}
]
},
...
]
}
}
Total Read Bytes (server-side consumption): 18468136
all done
Modules
