Skip to main content

GetBlockHeader

GetBlockHeader returns a block header with a particular block hash.

Source: neutrinorpc/neutrino.proto

gRPC

rpc GetBlockHeader (GetBlockHeaderRequest) returns (GetBlockHeaderResponse);

REST

HTTP MethodPath
GET /v2/neutrino/blockheader/{hash}

Code Samples

const fs = require('fs');
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');

const GRPC_HOST = 'localhost:10009'
const MACAROON_PATH = 'LND_DIR/data/chain/bitcoin/regtest/admin.macaroon'
const TLS_PATH = 'LND_DIR/tls.cert'

const loaderOptions = {
keepCase: true,
longs: String,
enums: String,
defaults: true,
oneofs: true,
};
const packageDefinition = protoLoader.loadSync(['lightning.proto', 'neutrinorpc/neutrino.proto'], loaderOptions);
const neutrinorpc = grpc.loadPackageDefinition(packageDefinition).neutrinorpc;
process.env.GRPC_SSL_CIPHER_SUITES = 'HIGH+ECDSA';
const tlsCert = fs.readFileSync(TLS_PATH);
const sslCreds = grpc.credentials.createSsl(tlsCert);
const macaroon = fs.readFileSync(MACAROON_PATH).toString('hex');
const macaroonCreds = grpc.credentials.createFromMetadataGenerator(function(args, callback) {
let metadata = new grpc.Metadata();
metadata.add('macaroon', macaroon);
callback(null, metadata);
});
let creds = grpc.credentials.combineChannelCredentials(sslCreds, macaroonCreds);
let client = new neutrinorpc.NeutrinoKit(GRPC_HOST, creds);
let request = {
hash: <string>,
};
client.getBlockHeader(request, function(err, response) {
console.log(response);
});
// Console output:
// {
// "hash": <string>,
// "confirmations": <int64>,
// "stripped_size": <int64>,
// "size": <int64>,
// "weight": <int64>,
// "height": <int32>,
// "version": <int32>,
// "version_hex": <string>,
// "merkleroot": <string>,
// "time": <int64>,
// "nonce": <uint32>,
// "bits": <string>,
// "ntx": <int32>,
// "previous_block_hash": <string>,
// "raw_hex": <bytes>,
// }

Messages

neutrinorpc.GetBlockHeaderRequest

Source: neutrinorpc/neutrino.proto

FieldgRPC TypeREST TypeREST Placement
hash
stringstringpath

neutrinorpc.GetBlockHeaderResponse

Source: neutrinorpc/neutrino.proto

FieldgRPC TypeREST Type
hash
stringstring
confirmations
int64string
stripped_size
int64string
size
int64string
weight
int64string
height
int32integer
version
int32integer
version_hex
stringstring
merkleroot
stringstring
time
int64string
nonce
uint32integer
bits
stringstring
ntx
int32integer
previous_block_hash
stringstring
raw_hex
bytesstring