Blockchain
C# 解析比特幣區塊鏈以獲取地址餘額
有沒有辦法在不使用外部 API 的情況下在 C# 中掃描比特幣區塊鏈?我正在尋找比特幣地址的可消費金額。
我正在使用 NBitcoin。
// create new key pair based on private key NBitcoin.Key key = new NBitcoin.Key(privateKey, privateKey.Length, false); // parse blk*.dat // get balance for address key.PubKey.Hash // How to do that?
在本地執行QBitNinja伺服器怎麼樣?
var client = new QBitNinjaClient(baseAddress:"specify host here, you probably want localhost", Network.TestNet); var balanceModel = client.GetBalance(dest: [Add any IDestination here, like new BitcoinAddress("mivD5GHroixrzgjv6Ww73pV5R55PcL8JdM", Network.TestNet)], unspentOnly: true).Result; if (balanceModel.Operations.Count == 0) throw new Exception("No coins to spend"); var unspentCoins = new List<Coin>(); foreach (var operation in balanceModel.Operations) unspentCoins.AddRange(operation.ReceivedCoins.Select(coin => coin as Coin)); var balance = unspentCoins.Sum(x => x.Amount.ToDecimal(MoneyUnit.BTC));
您始終可以使用<http://blockchainsql.io>對比特幣區塊鏈進行 SQL 查詢。
免責聲明:我是開發人員。