Bitcoin Forum
December 11, 2017, 07:54:54 PM *
News: Latest stable version of Bitcoin Core: 0.15.1  [Torrent].
 
   Home   Help Search Donate Login Register  
Pages: [1]
  Print  
Author Topic: NBitcoin C# Transaction Problem  (Read 217 times)
ts__
Newbie
*
Offline Offline

Activity: 1


View Profile
September 13, 2017, 01:20:36 PM
 #1

Hello. I can't make a transaction in testnet between two wallet. Any idea? Thanks. Here is my code :

Code:
           // wallet 1
            BitcoinSecret alice = new BitcoinSecret("cVRq7YR616m5Ae98khjDRrzU29i93HPMgiftDB5m5avti4z21A5x", Network.TestNet);
            //wallet2
            BitcoinSecret satoshi = new BitcoinSecret("93GTrdzRTMzEUa5E3ZAhdQgQweM6dJhnZqGztHRzH8TMmPE9vXF", Network.TestNet);
            //transaction
            Console.WriteLine(alice.GetAddress());
            Console.WriteLine(satoshi.GetAddress());
            var txRepo = new NoSqlTransactionRepository();
            Transaction aliceFunding = new Transaction()
            {
                Outputs =
                {
                    new TxOut("0.0009", alice.GetAddress()),
                      new TxOut("0.0003", alice.PubKey)
                }
            };
            Coin[] aliceCoins = aliceFunding
                         .Outputs
                         .Select((o, i) => new Coin(new OutPoint(aliceFunding.GetHash(), i), o))
                         .ToArray();
            var txBuilder = new TransactionBuilder();
            var tx = txBuilder
                .AddCoins(aliceCoins)
                .AddKeys(alice.PrivateKey)
                .Send(satoshi.GetAddress(), "0.0009")
                .SendFees("0.0003")
                .SetChange(alice.GetAddress())
                .BuildTransaction(true);
            txRepo.Put(tx.GetHash(), tx);
            Console.WriteLine(txBuilder.Verify(tx));
            Console.WriteLine(tx.GetHash().ToString());
            var client = new QBitNinjaClient(Network.TestNet);
            BroadcastResponse broadcastResponse = client.Broadcast(tx).Result;
            if (!broadcastResponse.Success)
            {
                Console.WriteLine("ErrorCode: {0}", broadcastResponse.Error.ErrorCode);
            }
            else
            {
                Console.WriteLine("Success! You can check out the hash of the transaciton in any block explorer:");
            }
            var node = Node.Connect(Network.TestNet);
            node.VersionHandshake();
            node.SendMessage(new InvPayload(InventoryType.MSG_TX, tx.GetHash()));
            node.SendMessage(new TxPayload(tx));
            Console.ReadKey();
Pages: [1]
  Print  
 
Jump to:  

Sponsored by , a Bitcoin-accepting VPN.
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!