Reputation: 21
I want to make a send payment from my wallet.
public static Transaction send(Wallet wallet,String destinationAddress,long satoshis, NetworkParameters parameters)
throws Exception {
Address dest = Address.fromBase58(parameters, destinationAddress);
SendRequest request = SendRequest.to(dest, Coin.valueOf(satoshis));
Wallet.SendResult result = wallet.sendCoins(request);
Transaction endTransaction = result.broadcastComplete.get();
return endTransaction;
}
or tried to make
SendRequest req;
Transaction transaction = new Transaction(parameters);
Coin coinToSpend = Coin.valueOf(600);
//Address addressoSpend = new Address(parameters,"1PSq12YPRBCGwmb2cqqXaGpRrLfotsthPv");
transaction.addOutput(coinToSpend,Address.fromBase58(parameters,"18MQPpjbB5UUwZBT7DALE6Q55pKCtfPCK3"));
req = SendRequest.forTx(transaction);
Wallet.SendResult sendResult = restoredWallet.sendCoins(req);
both of them return
Exception in thread "main" org.bitcoinj.core.InsufficientMoneyException: Insufficient money, missing 0.0004729 BTC
How to make a proper send payment to another BTC address?
Upvotes: 0
Views: 1080
Reputation: 21
The problem actually was with the input and output. In new versions of bitcoinj you should set unput and output ot make transaction. Unfortuanetly, it was not updated on officail page. Here below is the answer for my question:
Coin value = Coin.valueOf(680l);
Address to = Address.fromBase58(parameters, addressTo);
Transaction transaction = new Transaction(parameters);
transaction.addInput(wallet.getUnspents().get(0));// important to add proper input
transaction.addOutput(value, to);
SendRequest request = SendRequest.forTx(transaction);
request.feePerKb = Coin.valueOf(1000);
Wallet.SendResult sendResult = wallet.sendCoins(peerGroup, request);
Upvotes: 1