Last active
June 7, 2017 02:16
-
-
Save nopara73/dfd50db5b41931b472110357c79a4ea0 to your computer and use it in GitHub Desktop.
BasicTransaction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static readonly Network _network = Network.TestNet; | |
private static readonly BitcoinExtKey _seed = new BitcoinExtKey("tprv8ZgxMBicQKsPeGSjHbcTdpBxmVvRmySiUkQFBLruRTrn2dXAtn2rqApjVUgqsFkhfJZLYy8kXgRaEgZh7M3zdxyabF1TcwoxZsgpmAnHYyH"); | |
private static readonly ExtKey _fundingExtKey = _seed.ExtKey.Derive(0, false); | |
private static readonly BitcoinAddress _fundingAddress = _fundingExtKey.ScriptPubKey.GetDestinationAddress(_network); // mkvRuHAv3qek4mP3ipjqFnaFXj4d2kKit3 | |
private static readonly QBitNinjaClient _qBitClient = new QBitNinjaClient(_network); | |
static void Main(string[] args) | |
{ | |
SpendBasicTransaction(); | |
ReadKey(); | |
} | |
private static void SpendBasicTransaction() | |
{ | |
uint256 txIdToSpend = _qBitClient.GetBalance(_fundingAddress, unspentOnly: false).Result.Operations.First().TransactionId; // f1e0865d087e3aeee1124e07c32b5cd7dda342c3d8dc691e54b9094f1f939df8 | |
Transaction txToSpend = _qBitClient.GetTransaction(txIdToSpend).Result.Transaction; | |
Money fee = new Money(0.001m, MoneyUnit.BTC); | |
var builder = new TransactionBuilder(); | |
var txThatSpends = builder | |
.AddCoins(txToSpend) | |
.AddKeys(_fundingExtKey) | |
.SendFees(fee) | |
.Send(_fundingAddress, txToSpend.Outputs.First().Value - fee) | |
.BuildTransaction(true); | |
var errors = builder.Check(txThatSpends); | |
if (errors.Count() != 0) | |
{ | |
WriteLine("Check failed. Errors:"); | |
foreach (var err in errors) | |
{ | |
WriteLine(err); | |
} | |
} | |
else | |
{ | |
WriteLine(txThatSpends); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment