Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- BitcoinSecret nicoSecret = new BitcoinSecret("cPY2XauRnLnruVQyEfgzB7Wpoxhsc94e4S3DDYecz3dMcoEDEKYm");
- BitcoinSecret yourSecret = new BitcoinSecret("xxxxx");
- Money toSend = Money.Coins(0.01m);
- Money miningFee = Money.Coins(0.001m);
- List<Coin> coinsToSpend = new List<Coin>();
- Money current = Money.Zero;
- QBitNinjaClient client = new QBitNinjaClient(Network.TestNet);
- var balance = client.GetBalance(nicoSecret.GetAddress(), true).Result;
- foreach(var entry in balance.Operations)
- {
- foreach(var coin in entry.ReceivedCoins)
- {
- if(current < miningFee + toSend)
- {
- coinsToSpend.Add((Coin)coin);
- current += (Money)coin.Amount;
- }
- }
- }
- Transaction tx = new Transaction();
- foreach(var coin in coinsToSpend)
- {
- tx.AddInput(new TxIn(coin.Outpoint));
- }
- tx.AddOutput(new TxOut(toSend, yourSecret.GetAddress()));
- tx.AddOutput(new TxOut(current - miningFee - toSend, nicoSecret.GetAddress()));
- tx.Sign(nicoSecret, coinsToSpend.ToArray());
- client.Broadcast(tx).Wait();
- System.Console.WriteLine(tx);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement