Bitcoin-JSON-RPC-Client: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
Link to an updated fork with maven artifacts |
||
(7 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{ | '''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== | ||
Line 8: | Line 41: | ||
* [[Java Bitcoin Client]] | * [[Java Bitcoin Client]] | ||
* [[BitCoinJ]] | * [[BitCoinJ]] | ||
* [[API reference (JSON-RPC)]] | |||
==External links== | ==External links== | ||
*[http://search.maven.org/#search|ga|1|a%3A%22JavaBitcoindRpcClient%22 Maven artifact] | |||
*[https://bitbucket.org/azazar/bitcoin-json-rpc-client Bitcoin-JSON-RPC-Client project page] | *[https://github.com/Polve/JavaBitcoindRpcClient Source] (Updated release) | ||
*[https://bitbucket.org/azazar/bitcoin-json-rpc-client Bitcoin-JSON-RPC-Client project page] and [https://bitbucket.org/azazar/bitcoin-json-rpc-client/downloads downloads] (original release) | |||
[[Category:API Bindings]] | [[Category:API Bindings]] |
Latest revision as of 18:10, 9 November 2014
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
- Maven artifact
- Source (Updated release)
- Bitcoin-JSON-RPC-Client project page and downloads (original release)