The most manual way to broadcast transactions is
PeerGroup.broadcastTransaction(). Transactions that are committed to the
wallet should be broadcast automatically though as soon as the PeerGroup
connects (assuming that your wallet and the PeerGroup are linked).
On 05/23/2018 09:44 PM, Tyga wrote:
> i am working on watching wallet and Offline wallet using bitcoinj
> i am receiving payment on watching wallet *Fine*
> now i want to spend coins from watching wallet
> what i am doing is creating rawTx from Watching Wallet then sign it with
> private key from Offline Wallet
> but when i broadcast it, its throw an exception InsufficientMoneyException.
> my wallet balance is 6.001 BTC
> My code snippet is
>
> *For creating Raw Transaction from Watching Wallet*
> *
> *
> *
> |
>
> privatestaticvoidbla()
> {
> Coincoin =Coin.parseCoin("0.01");
> Addressaddress
> =Address.fromBase58(params,"n4oLPFUGvohSdDxvJS3amXvfE1GEdZBddd");
> Transactiontx =newTransaction(params);
> System.out.println("Raw TX: "+tx.toString());
> byte[]bytes
> =Script.createInputScript("5ff01d61e67c706cb79653aa1e7ad2c7254b841167e0a34055504c35c7240469".getBytes());//
> tx hash
>
> TransactionInputinput =newTransactionInput(params,null,bytes);
>
> //Creates a scriptPubKey that encodes payment to the given address.
> ScriptscriptPubKey =ScriptBuilder.createOutputScript(address);
> // Signature Script
> ScriptscriptSig =input.getScriptSig();
>
> // Adding output that involves Amount and Script
> tx.addOutput(coin,scriptPubKey);
> System.out.println("Script pub key: "+scriptPubKey);
>
> //Adding input to the raw transaction
> tx.addInput(Sha256Hash.wrap(tx.getHashAsString()),0,scriptSig);
> System.out.println("After adding inputs: "+tx.toString());
> }
>
> |
> *
> *
> *
> *Signing Transaction from Offline Wallet Using Private Key*
> *
> *
> *Enter code here...
> |
>
> privatestaticStringsignTx()
> {
> // TX Hash from Watching wallet
> StringunSignHash
> ="f348ceadcb66e811799aa543107b63b9c92afebda5bc47d11222ba218df6638f";
> // Signing Hash with private key
> System.out.println("Signed Hash from prv key:
> "+DatatypeConverter.printHexBinary(prvKey().sign(Sha256Hash.wrap(unSignHash)).encodeToDER()));
> }
>
> |
>
> Now i don't know how to broadcast it what i am doing for broadcastin is
> *
> *
> *
> *
> |
>
> try
> {
> kit.wallet().sendCoins(SendRequest.forTx(tx));
> }
> catch(InsufficientMoneyExceptione)
> {
> System.err.println("Exception: "+e.toString());
> }
>
> |
>
> **i am clearly doing something wrong here, i am stuck in this for days
> *
> *any idea what i am doing wrong in here and how can i make this happen ?
> *
>
> --
> You received this message because you are subscribed to the Google
> Groups "bitcoinj" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"bitcoinj" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.