๐ฏ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.โ
- Request
- Response
- ...
//Sample Request ๐
var blockCount = await _blockChainService!.GetBlockCountAsc();
//will return a current blockCount: ๐
var blockCount = 733366;
๐ For more information Check out Blockchain - Get Block Count
๐ฐGet Chain Tipsโ
Return information about all known tips in the block tree, including the main chain as well as orphaned branches.โ
- Request
- Response
- ...
//Sample Request ๐
var chainTips = await _blockChainService!.GetChainTipsAsc();
//will return a new object List of ChainTip with values: ๐
var chainTips = new List<ChainTip>
{
new()
{
Height = 733367,
Hash = "0000000000000000042b60032e34fe13c82ca56aad660469b859ea122aa1d14c",
BranchLen = 0,
Status = "active"
},
new()
{
Height = 699255,
Hash = "00000000000000000414796698752eec1e9d71133c41e85af67c15c1e2c8c90d",
BranchLen = 1,
Status = "valid-headers"
}...
};
๐ For more information Check out Get Chain Tips
๐ฐGet Tx Out (GET)โ
Returns details about an unspent transaction output.โ
- Request
- Response
- ...
//Sample Request ๐
var txOut = await _blockChainService!.GetTxOutAsync(
"fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
0, false);
//will return a new object TransactionOutput with values: ๐
var txOut = new TransactionOutput
{
BestBlock = "000000000000000004e19c1b14333cf75838cf92dfac8f29fcc3f64c2d5c6506",
Confirmations = 732406,
Value = 50,
ScriptPubKey = new ScriptPubKey
{
Asm =
"04f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446a OP_CHECKSIG",
Hex =
"4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac",
ReqSigs = 1,
Type = "pubkey",
Addresses = new List<string>
{
"bitcoincash:qpej6mkrwca4tvy2snq4crhrf88v4ljspysx0ueetk"
}
},
Coinbase = true
};
๐ For more information Check out Blockchain - Get Tx Out
๐ฐGet Tx Out (POST)โ
Returns details about an unspent transaction output.โ
- Request
- Response
- ...
//Sample Request ๐
var txOut = await _blockChainService!.GetTxOutAsync(
new TransactionOutputRequest
{
Mempool = false,
TxId = "fe28050b93faea61fa88c4c630f0e1f0a1c24d0082dd0e10d369e13212128f33",
Vout = 0
});
//will return a new object TransactionOutput with values: ๐
var txOut = new TransactionOutput
{
BestBlock = "000000000000000004e19c1b14333cf75838cf92dfac8f29fcc3f64c2d5c6506",
Confirmations = 732406,
Value = 50,
ScriptPubKey = new ScriptPubKey
{
Asm =
"04f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446a OP_CHECKSIG",
Hex =
"4104f5eeb2b10c944c6b9fbcfff94c35bdeecd93df977882babc7f3a2cf7f5c81d3b09a68db7f0e04f21de5d4230e75e6dbe7ad16eefe0d4325a62067dc6f369446aac",
ReqSigs = 1,
Type = "pubkey",
Addresses = new List<string>
{
"bitcoincash:qpej6mkrwca4tvy2snq4crhrf88v4ljspysx0ueetk"
}
},
Coinbase = true
};
๐ For more information Check out Blockchain - Get Tx Out
๐ฐGet best block hashโ
Returns the hash of the best (tip) block in the longest block chain.โ
- Request
- Response
- ...
//Sample Request ๐
var blockHash = await _blockChainService!.GetBestBlockHashAsync();
//will return a new object String with value: ๐
var blockHash = "000000000000000004e19c1b14333cf75838cf92dfac8f29fcc3f64c2d5c6506";
๐ For more information Check out Get best block hash
๐ฐGet block details (hex)โ
Returns block detailsโ
- Request
- Response
- ...
//Sample Request ๐
var block = await _blockChainService!.GetBlockAsync(
"000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b");
//will return a hex data: ๐
var block = "0000402094cfefee0c1ae491db43b324cb001ed4eba31235694481050000000000000000961b6c91c604c5dcc7
f92f5bc49ea2d5cfbdd463a923f3f6baeb3680894875c77ddd5c6073dd05186cd90e8ffdf00802000000010000000
000000000000000000000000000000000000000000000000000000000ffffffff51037f610a045e44c28c65752f425
4432e636f6d2f4243484e2ffabe6d6d4c71e53ab707c33aa891c17d9a5be93d78bfac5070733745ae9beb997ff668bc0
20000008e9b20aa1efed95ab4a500000000000....."
๐ For more information Check out Get block details
๐ฐGet block details (verbose 1)โ
Returns block detailsโ
- Request
- Response
- ...
//Sample Request ๐
var block = await _blockChainService!.GetBlockVerbosity1Async(
"000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b");
//will return a BlockInfo: ๐
var block = new BlockInfo
{
Hash = "000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b",
Confirmations = 53175,
Size = 1791085,
Height = 680319,
Version = 541065216,
VersionHex = "20400000",
Merkleroot = "c77548898036ebbaf6f323a963d4bdcfd5a29ec45b2ff9c7dcc504c6916c1b96",
Tx = new List<string>
{
"461b942756fe15c29a6f12f8dddf43a252545576384423cc40356a79334503a3",
"0009236270fbf86fe3d0ca4cb96bb9de212c8e5f5836a03239fccbe843c33843",
"00272489414f8265c12e66c2f28537472f18d4922ae5974bb01dc6ccf24e2ce1",
"00627b161e2199304fc04c856a9b154f981fecefaca187937ea8fe80bd0d4e74",
"ffb2dae51ee98f9a8655b0e3c54294de4d6e9c065a0305626f2cdf5843f4ee9e",
"ffc481803620d08a0e0825ed940405771b47d5f28d9e2539347907eabcd10adb"
},
Time = 1616698749,
Mediantime = 1616696565,
Nonce = 2400115052,
Bits = "1805dd73",
Difficulty = 187466001665.8389,
Chainwork = "000000000000000000000000000000000000000001627d68a55a9240dc6985dc",
NTx = 2288,
Previousblockhash = "0000000000000000058144693512a3ebd41e00cb24b343db91e41a0ceeefcf94",
Nextblockhash = "0000000000000000036538eebb64f032eafb29ea45f3f4ea550d9593e82bc2b6"
};
๐ For more information Check out Get block details
๐ฐGet block details (verbose 2)โ
Returns block detailsโ
- Request
- Response
- ...
//Sample Request ๐
var block = await _blockChainService!.GetBlockVerbosity2Async(
"000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b");
//will return a BlockAndTransactionInfo: ๐
var block = new BlockAndTransactionInfo
{
Hash = "000000000000000002a5fe0bdd6e3f04342a975c0f55e57f97e73bb90041676b",
Confirmations = 53175,
Size = 1791085,
Height = 680319,
Version = 541065216,
VersionHex = "20400000",
Merkleroot = "c77548898036ebbaf6f323a963d4bdcfd5a29ec45b2ff9c7dcc504c6916c1b96",
Tx = new List<BlockTransactionInfo>
{
new()
{
Txid = "0009236270fbf86fe3d0ca4cb96bb9de212c8e5f5836a03239fccbe843c33843",
Hash = "0009236270fbf86fe3d0ca4cb96bb9de212c8e5f5836a03239fccbe843c33843",
Version = 2,
Size = 219,
Locktime = 0,
Vin = new List<BlockTransactionInputInfo>
{
new()
{
Txid = "5702d86870a3988ae60da9d440e154d00dda4e23f262092f2fa3f8a8f7a997f4",
Vout = 1,
ScriptSig = new BlockTransactionInputScriptSigInfo
{
Asm =
"aec1f6aadbde697b9cfbd84e7b2b93f86e0031019f463b23cce29092dfe056e60421c8d5f6cc44c0f1f07626f8f64b4ca8faaecf4754fe9c99be500b90a76b95[ALL|FORKID] 02719a7031742b71a93c082ac943fe42a1e12ae9868770216ad16fed1f2e46960a",
Hex =
"41aec1f6aadbde697b9cfbd84e7b2b93f86e0031019f463b23cce29092dfe056e60421c8d5f6cc44c0f1f07626f8f64b4ca8faaecf4754fe9c99be500b90a76b95412102719a7031742b71a93c082ac943fe42a1e12ae9868770216ad16fed1f2e46960a"
},
Sequence = 0
}
},
Vout = new List<BlockTransactionOutputInfo>
{
new()
{
Value = (decimal) 0.00008316,
N = 0,
ScriptPubKey = new BlockTransactionOutputScriptPubKeyInfo
{
Asm =
"OP_DUP OP_HASH160 ae4eb12324368fdc93fd44196a7238afbb6b74a8 OP_EQUALVERIFY OP_CHECKSIG",
Hex = "76a914ae4eb12324368fdc93fd44196a7238afbb6b74a888ac",
ReqSigs = 1,
Type = "pubkeyhash",
Addresses = new List<string>
{
"bitcoincash:qzhyavfrysmglhynl4zpj6nj8zhmk6m54q53mggtej"
}
}
},
new()
{
Value = (decimal) 0.09344132,
N = 1,
ScriptPubKey = new BlockTransactionOutputScriptPubKeyInfo
{
Asm =
"OP_DUP OP_HASH160 2815129632d4ce37831269e03c0e2dacd8123403 OP_EQUALVERIFY OP_CHECKSIG",
Hex = "76a9142815129632d4ce37831269e03c0e2dacd812340388ac",
ReqSigs = 1,
Type = "pubkeyhash",
Addresses = new List<string>
{
"bitcoincash:qq5p2y5kxt2vudurzf57q0qw9kkdsy35qv77w2ss9z"
}
}
}
},
Hex =
"0200000001f497a9f7a8f8a32f2f0962f2234eda0dd054e140d4a90de68a98a37068d80257010000006441aec1f6aadbde697b9cfbd84e7b2b93f86e0031019f463b23cce29092dfe056e60421c8d5f6cc44c0f1f07626f8f64b4ca8faaecf4754fe9c99be500b90a76b95412102719a7031742b71a93c082ac943fe42a1e12ae9868770216ad16fed1f2e46960a00000000027c200000000000001976a914ae4eb12324368fdc93fd44196a7238afbb6b74a888ac84948e00000000001976a9142815129632d4ce37831269e03c0e2dacd812340388ac00000000"
}
}
};
๐ For more information Check out Get block details
๐ฐGet block hashโ
Returns the hash of a block, given its block height.โ
- Request
- Response
- ...
//Sample Request ๐
var hash = await _blockChainService!.GetBlockHashAsync("544444");
//will return a new string value: ๐
var hash = "0000000000000000019763fa832192b476b1665728520d05468f0510068e116c";
๐ For more information Check out Get block hash
๐ฐGet blockchain infoโ
Returns an object containing various state info regarding blockchain processing.โ
- Request
- Response
- ...
//Sample Request ๐
var blockChainInfo = await _blockChainService!.GetBlockChainInfoAsync();
//will return a new object BlockChainInfo: ๐
var blockChainInfo = new BlockChainInfo
{
Chain = "main",
Blocks = 733493,
Headers = 733493,
BestBlockHash = "000000000000000000ceaa574ae44c327f6752313480317485f803071541a646",
Difficulty = 216278704324.5844,
MedianTime = 1648564783,
VerificationProgress =0.9999768649036239,
Initialblockdownload = false,
ChainWork = "000000000000000000000000000000000000000001904042e3350fd37a060abb",
SizeOnDisk = 203399747530,
Pruned = false,
Warnings = ""
};
๐ For more information Check out Get blockchain info
๐ฐGet bulk mempool entryโ
Returns mempool data for multiple transactions.โ
- Request
- Response
- ...
//Sample Request ๐
var memPool = await _blockChainService!.GetMempoolEntryAsync(new[]
{
"4e991ad6d80813a2b868598143b88165d4482fcdb7fb94774603fd1e248e058d",
"b3b5d627b4d692154fb9ccc58639522d09418f3349bd49ed6c3f52c86f7128b4",
"4d87e62ada41ab9f99e64b010c2a09c6773dc64f2eabfdfdfd1fce353953c304"
});
//will return a Collection of MempoolEntry: ๐
var memPool = new List<MempoolEntry>
{
new()
{
Fees = new Fees
{
Base = 0.0000022,
Modified =0.0000022
},
Size = 219,
Time = 1648603325,
Height = 733547,
Depends = new List<string>
{
"403513ba5ff16b669d988a7b26c00a71ec210f941efc48a8e657868f694c8c6a"
},
SpentBy = new List<string>
{
"58564fe80f07b38b96311d6335c33cd15c0f109a968405e6913a3b7c14138630"
}
},
new()
{
Fees = new Fees
{
Base = 0.0000022,
Modified = 0.0000022
},
Size = 219,
Time = 1648603334,
Height = 733547,
Depends =null,
SpentBy = new List<string>
{
"bb6bc3b4b45e8ca771bab82b3461973d00f45bc6abe3e17731a3c2434019c88f"
}
},
new()
{
Fees = new Fees
{
Base = 0.00000228,
Modified = 0.00000228
},
Size = 224,
Time = 1648603335,
Height = 733547,
Depends =new List<string>
{
"a605dbaa9520bddf989c54c6a121ac3def5b9adaf4bee89adc0810bb48ca3c71"
},
SpentBy =null
}
};
๐ For more information Check out Get bulk mempool entry
๐ฐGet single mempool entryโ
Returns mempool data for given transaction. TXID must be in mempool (unconfirmed)โ
- Request
- Response
- ...
//Sample Request ๐
var memPool = await _blockChainService!.GetMempoolEntryAsync(
"4d87e62ada41ab9f99e64b010c2a09c6773dc64f2eabfdfdfd1fce353953c304");
//will return a new object MempoolEntry with values: ๐
var memPool = new MempoolEntry
{
Fees = new Fees
{
Base = 0.00000228,
Modified = 0.00000228
},
Size = 224,
Time = 1648603335,
Height = 733547,
Depends = new List<string>
{
"403513ba5ff16b669d988a7b26c00a71ec210f941efc48a8e657868f694c8c6a"
},
SpentBy = new List<string>
{
"58564fe80f07b38b96311d6335c33cd15c0f109a968405e6913a3b7c14138630"
}
};
๐ For more information Check out Get single mempool entry
๐ฐGet difficultyโ
Get the current difficulty value, used to regulate mining power on the network.โ
- Request
- Response
- ...
//Sample Request ๐
var difficulty = await _blockChainService!.GetDifficultyAsync();
//will return: ๐
var difficulty = 212878174128.6967;
๐ For more information Check out Get difficulty
๐ฐGet mempool infoโ
Returns details on the active state of the TX memory pool.โ
- Request
- Response
- ...
//Sample Request ๐
var memPoolInfo = await _blockChainService!.GetMempoolInfoAsync();
//will return: ๐
var memPoolInfo = new MempoolInfo
{
Loaded = true,
Size = 430,
MempoolBytes = 186389,
Usage = 602688,
MaxMempoolBytes = 320000000,
Mempoolminfee = 0.00001,
Minrelaytxfee = 0.00001
};
๐ For more information Check out Get mempool info
๐ฐ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.โ
- Request
- Response
- ...
//Sample Request ๐
var blockHeaders = await _blockChainService!.GetBlockHeadersAsync(new[]
{
"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201",
"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3"
});
//will return: ๐
var blockHeaders = new List<string>
{
"0000002023e5e672edd0277e68e5e57e2880056f7113b0ebd631380400000000000000009190c16e9e1eddde7ab26afa1eb08ef509cac26f28e35a657e331b5e6479f24a60c1f6591ab909185070d8d6",
"0000002001b2328355f4a4dc9efa5c610687304507b7df9f3f4de105000000000000000096a61a8599a2e392438f391bdfbd20ab7b91e7775c005293454058b2f4c7fc010dc7f6591ab909189aa0768f"
};
๐ For more information Check out Get multiple block headers
๐ฐ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.โ
- Request
- Response
- ...
//Sample Request ๐
var blockHeaders = await _blockChainService!.GetBlockHeadersVerboseAsync(new[]
{
"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201",
"00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3"
});
//will return: ๐
var blockHeaders = new List<BlockHeader>
{
new()
{
Hash = "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201",
Confirmations = 233553,
Height = 500000,
Version = 536870912,
VersionHex = "20000000",
Merkleroot = "4af279645e1b337e655ae3286fc2ca09f58eb01efa6ab27adedd1e9e6ec19091",
Time = 1509343584,
Mediantime = 1509336533,
Nonce = 3604508752,
Bits = "1809b91a",
Difficulty = 113081236211.4533,
Chainwork = "0000000000000000000000000000000000000000007ae48aca46e3b449ad9714",
NTx = 150,
Previousblockhash = "0000000000000000043831d6ebb013716f0580287ee5e5687e27d0ed72e6e523",
Nextblockhash = "00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3"
},
new()
{
Hash = "00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3",
Confirmations = 233552,
Height = 500001,
Version = 536870912,
VersionHex = "20000000",
Merkleroot = "01fcc7f4b25840459352005c77e7917bab20bddf1b398f4392e3a299851aa696",
Time = 1509345037,
Mediantime = 1509336585,
Nonce = 2406916250,
Bits = "1809b91a",
Difficulty = 113081236211.4533,
Chainwork = "0000000000000000000000000000000000000000007ae4a51e8bf2ecccf1d9a1",
NTx = 196,
Previousblockhash = "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201",
Nextblockhash = "00000000000000000797607b2b69d1561027dbaf28545a33d6ec3adb89f8e564"
}
};
๐ For more information Check out Get multiple block headers
๐ฐ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.โ
- Request
- Response
- ...
//Sample Request ๐
var blockHeader = await _blockChainService!.GetBlockHeaderAsync(
"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201");
//will return: ๐
var blockHeader = "0000002023e5e672edd0277e68e5e57e2880056f7113b0ebd631380400000000000000009190c16e9e1eddde7ab26afa1eb08ef509cac26f28e35a657e331b5e6479f24a60c1f6591ab909185070d8d6";
๐ For more information Check out Get single block header
๐ฐ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.โ
- Request
- Response
- ...
//Sample Request ๐
var blockHeader = await _blockChainService!.GetBlockHeaderVerboseAsync(
"000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201");
//will return: ๐
var blockHeader = new BlockHeader
{
Hash = "000000000000000005e14d3f9fdfb70745308706615cfa9edca4f4558332b201",
Confirmations = 233553,
Height = 500000,
Version = 536870912,
VersionHex = "20000000",
Merkleroot = "4af279645e1b337e655ae3286fc2ca09f58eb01efa6ab27adedd1e9e6ec19091",
Time = 1509343584,
Mediantime = 1509336533,
Nonce = 3604508752,
Bits = "1809b91a",
Difficulty = 113081236211.4533,
Chainwork = "0000000000000000000000000000000000000000007ae48aca46e3b449ad9714",
NTx = 150,
Previousblockhash = "0000000000000000043831d6ebb013716f0580287ee5e5687e27d0ed72e6e523",
Nextblockhash = "00000000000000000568f0a96bf4348847bc84e455cbfec389f27311037a20f3"
};
๐ For more information Check out Get single block header