Bitcoin-JSON-RPC-Client: Difference between revisions

From Bitcoin Wiki
Jump to navigation Jump to search
Azazar (talk | contribs)
Azazar (talk | contribs)
No edit summary
Line 1: Line 1:
{{stub}}
'''Bitcoin-JSON-RPC-Client''' is a lightweight Java bitcoin JSON-RPC client binding. It does not require any external dependencies.


'''Bitcoin-JSON-RPC-Client''' is a lightweight Java bitcoin JSON-RPC client binding. It does not require any external dependencies.
==Code example==
 
<source lang="java">
    private static final Bitcoin bitcoin = new BitcoinJSONRPCClient();
 
    public static void sendCoins() throws BitcoinException {
        bitcoin.sendToAddress("1EzGDMdqKW5ubTDNHSqCKciPkybGSvWgrj", 10);
    }
 
    public static void receiveCoins() throws BitcoinException {
        final BitcoinAcceptor acceptor = new BitcoinAcceptor(bitcoin);
 
        System.out.println("Send bitcoins to " + bitcoin.getNewAddress("NewAccount"));
 
        acceptor.addListener(new ConfirmedPaymentListener() {
            HashSet processed = new HashSet();
 
            @Override
            public void confirmed(Transaction transaction) {
                if (!processed.add(transaction.txId()))
                    return; // already processed
 
                System.out.println("Payment received, amount: " + transaction.amount() + "; account: " + transaction.account());
                try {
                    if (bitcoin.getBalance("NewAccount") >= 10)
                        acceptor.stopAccepting();
                } catch (BitcoinException ex) {
                    ex.printStackTrace();
                }
            }


        });
        acceptor.run();
    }
</source>


==See Also==
==See Also==

Revision as of 03:37, 28 March 2013

Bitcoin-JSON-RPC-Client is a lightweight Java bitcoin JSON-RPC client binding. It does not require any external dependencies.

Code example

    private static final Bitcoin bitcoin = new BitcoinJSONRPCClient();

    public static void sendCoins() throws BitcoinException {
        bitcoin.sendToAddress("1EzGDMdqKW5ubTDNHSqCKciPkybGSvWgrj", 10);
    }

    public static void receiveCoins() throws BitcoinException {
        final BitcoinAcceptor acceptor = new BitcoinAcceptor(bitcoin);

        System.out.println("Send bitcoins to " + bitcoin.getNewAddress("NewAccount"));

        acceptor.addListener(new ConfirmedPaymentListener() {
            HashSet processed = new HashSet();

            @Override
            public void confirmed(Transaction transaction) {
                if (!processed.add(transaction.txId()))
                    return; // already processed

                System.out.println("Payment received, amount: " + transaction.amount() + "; account: " + transaction.account());
                try {
                    if (bitcoin.getBalance("NewAccount") >= 10)
                        acceptor.stopAccepting();
                } catch (BitcoinException ex) {
                    ex.printStackTrace();
                }
            }

        });
        acceptor.run();
    }

See Also

External links