0

我想从我的钱包中进行发送付款。

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;
    }

或试图使

 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);

他们俩都回来了

Exception in thread "main" org.bitcoinj.core.InsufficientMoneyException: Insufficient money,  missing 0.0004729 BTC

如何正确发送付款到另一个 BTC 地址?

4

1 回答 1

1

问题实际上在于输入和输出。在新版本的 bitcoinj 中,您应该设置 unput 和 output 以进行交易。不幸的是,它没有在官方页面上更新。下面是我的问题的答案:

            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);
于 2018-08-17T09:50:41.240 回答