Skip to main content

๐ŸŽฏBlockchain API

Notes

For more details visit BCH APIs page.

//imports
using Cash.NetCore.Contracts;
using Cash.NetCore.Models.Request.BlockChain;
using Cash.NetCore.Models.Response.BlockChain;
//inject
private readonly IBlockChainService _blockChainService;

๐Ÿ’ฐGet Block Countโ€‹

Returns the number of blocks in the longest blockchain.โ€‹

//Sample Request ๐ŸŽ
var blockCount = await _blockChainService!.GetBlockCountAsc();

๐Ÿ’ฐGet Chain Tipsโ€‹

Return information about all known tips in the block tree, including the main chain as well as orphaned branches.โ€‹

//Sample Request ๐ŸŽ
var chainTips = await _blockChainService!.GetChainTipsAsc();

๐Ÿ’ฐGet Tx Out (GET)โ€‹

Returns details about an unspent transaction output.โ€‹

//Sample Request ๐ŸŽ

var txOut = await _blockChainService!.GetTxOutAsync(
"fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
0, false);

๐Ÿ’ฐGet Tx Out (POST)โ€‹

Returns details about an unspent transaction output.โ€‹

//Sample Request ๐ŸŽ
var txOut = await _blockChainService!.GetTxOutAsync(
new TransactionOutputRequest
{
Mempool = false,
TxId = "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
Vout = 0
});

๐Ÿ’ฐGet best block hashโ€‹

Returns the hash of the best (tip) block in the longest block chain.โ€‹

//Sample Request ๐ŸŽ

var blockHash = await _blockChainService!.GetBestBlockHashAsync();

๐Ÿ’ฐGet block details (hex)โ€‹

Returns block detailsโ€‹

//Sample Request ๐ŸŽ
var block = await _blockChainService!.GetBlockAsync(
"000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b");

๐Ÿ’ฐGet block details (verbose 1)โ€‹

Returns block detailsโ€‹

//Sample Request ๐ŸŽ
var block = await _blockChainService!.GetBlockVerbosity1Async(
"000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b");

๐Ÿ’ฐGet block details (verbose 2)โ€‹

Returns block detailsโ€‹

//Sample Request ๐ŸŽ
var block = await _blockChainService!.GetBlockVerbosity2Async(
"000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b");

๐Ÿ’ฐGet block hashโ€‹

Returns the hash of a block, given its block height.โ€‹

//Sample Request ๐ŸŽ

var hash = await _blockChainService!.GetBlockHashAsync("544444");

๐Ÿ’ฐGet blockchain infoโ€‹

Returns an object containing various state info regarding blockchain processing.โ€‹

//Sample Request ๐ŸŽ

var blockChainInfo = await _blockChainService!.GetBlockChainInfoAsync();

๐Ÿ’ฐGet bulk mempool entryโ€‹

Returns mempool data for multiple transactions.โ€‹

//Sample Request ๐ŸŽ

var memPool = await _blockChainService!.GetMempoolEntryAsync(new[]
{
"4e991ad6d80813a2b868598143b88165d4482fcdb7fb94774603fd1e248e058d",
"b3b5d627b4d692154fb9ccc58639522d09418f3349bd49ed6c3f52c86f7128b4",
"4d87e62ada41ab9f99e64b010c2a09c6773dc64f2eabfdfdfd1fce353953c304"
});

๐Ÿ’ฐGet single mempool entryโ€‹

Returns mempool data for given transaction. TXID must be in mempool (unconfirmed)โ€‹

//Sample Request ๐ŸŽ

var memPool = await _blockChainService!.GetMempoolEntryAsync(
"4d87e62ada41ab9f99e64b010c2a09c6773dc64f2eabfdfdfd1fce353953c304");

๐Ÿ’ฐGet difficultyโ€‹

Get the current difficulty value, used to regulate mining power on the network.โ€‹

//Sample Request ๐ŸŽ

var difficulty = await _blockChainService!.GetDifficultyAsync();

๐Ÿ’ฐGet mempool infoโ€‹

Returns details on the active state of the TX memory pool.โ€‹

//Sample Request ๐ŸŽ

var memPoolInfo = await _blockChainService!.GetMempoolInfoAsync();

๐Ÿ’ฐGet multiple block headers (Default)โ€‹

If verbose is false (default), returns a string that is serialized, hex-encoded data for blockheader 'hash'. If verbose is true, returns an Object with information about blockheader hash.โ€‹

//Sample Request ๐ŸŽ

var blockHeaders = await _blockChainService!.GetBlockHeadersAsync(new[]
{
"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201",
"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3"
});

๐Ÿ’ฐGet multiple block headers (Verbose)โ€‹

If verbose is false (default), returns a string that is serialized, hex-encoded data for blockheader 'hash'. If verbose is true, returns an Object with information about blockheader hash.โ€‹

//Sample Request ๐ŸŽ

var blockHeaders = await _blockChainService!.GetBlockHeadersVerboseAsync(new[]
{
"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201",
"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3"
});

๐Ÿ’ฐGet single block header (Default)โ€‹

If verbose is false (default), returns a string that is serialized, hex-encoded data for blockheader 'hash'. If verbose is true, returns an Object with information about blockheader hash.โ€‹

//Sample Request ๐ŸŽ
var blockHeader = await _blockChainService!.GetBlockHeaderAsync(
"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201");

๐Ÿ’ฐGet single block header (Verbose)โ€‹

If verbose is false (default), returns a string that is serialized, hex-encoded data for blockheader 'hash'. If verbose is true, returns an Object with information about blockheader hash.โ€‹

//Sample Request ๐ŸŽ
var blockHeader = await _blockChainService!.GetBlockHeaderVerboseAsync(
"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201");