Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. BitcoinSecret nicoSecret = new BitcoinSecret("cPY2XauRnLnruVQyEfgzB7Wpoxhsc94e4S3DDYecz3dMcoEDEKYm");
  2. BitcoinSecret yourSecret = new BitcoinSecret("xxxxx");
  3. Money toSend = Money.Coins(0.01m);
  4. Money miningFee = Money.Coins(0.001m);
  5.  
  6.  
  7. List<Coin> coinsToSpend = new List<Coin>();
  8. Money current = Money.Zero;
  9.  
  10. QBitNinjaClient client = new QBitNinjaClient(Network.TestNet);
  11. var balance = client.GetBalance(nicoSecret.GetAddress(), true).Result;
  12. foreach(var entry in balance.Operations)
  13. {
  14.     foreach(var coin in entry.ReceivedCoins)
  15.     {
  16.         if(current < miningFee + toSend)
  17.         {
  18.             coinsToSpend.Add((Coin)coin);
  19.             current += (Money)coin.Amount;
  20.         }
  21.     }
  22. }
  23.  
  24. Transaction tx = new Transaction();
  25. foreach(var coin in coinsToSpend)
  26. {
  27.     tx.AddInput(new TxIn(coin.Outpoint));
  28. }
  29.  
  30. tx.AddOutput(new TxOut(toSend, yourSecret.GetAddress()));
  31. tx.AddOutput(new TxOut(current - miningFee - toSend, nicoSecret.GetAddress()));
  32.  
  33. tx.Sign(nicoSecret, coinsToSpend.ToArray());
  34. client.Broadcast(tx).Wait();
  35.  
  36. System.Console.WriteLine(tx);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement