Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public class EsploraClient

  1. Object
  2. EsploraClient

A Bitcoin client for the Esplora REST API, which Blockstream and mempool.space run in public and anyone can self-host: unspent outputs, balances, fee estimates and broadcasting.

EsploraClient btc = new EsploraClient(new NetworkTransport(), EsploraClient.MEMPOOL_TESTNET);
BitcoinAddress address = BitcoinAddress.parse("tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx",
        BitcoinNetwork.TESTNET);
List<EsploraClient.Utxo> coins = btc.getUtxos(address);
double satPerVbyte = btc.getFeeEstimates().get("6");
BitcoinTransaction signed = new BitcoinTransaction();   // signed through a Psbt
String txid = btc.broadcast(signed);

Nested types

class EsploraClient.UtxoAn unspent output.

Fields

public static final String MEMPOOL_MAINNET = "https://mempool.space/api"mempool.space, mainnet.
public static final String MEMPOOL_TESTNET = "https://mempool.space/testnet4/api"mempool.space, testnet4.
public static final String MEMPOOL_SIGNET = "https://mempool.space/signet/api"mempool.space, signet.
public static final String BLOCKSTREAM_MAINNET = "https://blockstream.info/api"Blockstream, mainnet.

Constructors

public EsploraClient(RpcTransport transport, String baseUrl)A client for an Esplora base URL, such as MEMPOOL_MAINNET.

Methods

public List<EsploraClient.Utxo> getUtxos(BitcoinAddress address) throws IOExceptionThe unspent outputs paying an address, confirmed and in the mempool.
public long[] getBalance(BitcoinAddress address) throws IOExceptionThe balance of an address in satoshis: {confirmed, unconfirmed}, the second the net effect of mempool transactions and possibly negative.
public Map<String, Double> getFeeEstimates() throws IOExceptionFee estimates in sat/vB keyed by confirmation target in blocks ("1", "3", "6", "144" and the others the server answers).
public long getTipHeight() throws IOExceptionThe height of the chain tip.
public BitcoinTransaction getTransaction(String txid) throws IOExceptionA transaction by id.
public long getConfirmationHeight(String txid) throws IOExceptionWhether a transaction is confirmed, and at what height: -1 while it is in the mempool.
public String broadcast(BitcoinTransaction signed) throws IOExceptionBroadcasts a signed transaction, answering its txid.

Inherited methods

Field details

MEMPOOL_MAINNET

public static final String MEMPOOL_MAINNET = "https://mempool.space/api"
mempool.space, mainnet.

MEMPOOL_TESTNET

public static final String MEMPOOL_TESTNET = "https://mempool.space/testnet4/api"
mempool.space, testnet4.

MEMPOOL_SIGNET

public static final String MEMPOOL_SIGNET = "https://mempool.space/signet/api"
mempool.space, signet.

BLOCKSTREAM_MAINNET

public static final String BLOCKSTREAM_MAINNET = "https://blockstream.info/api"
Blockstream, mainnet.

Constructor details

EsploraClient

public EsploraClient(RpcTransport transport, String baseUrl)
A client for an Esplora base URL, such as MEMPOOL_MAINNET.

Method details

getUtxos

public List<EsploraClient.Utxo> getUtxos(BitcoinAddress address) throws IOException
The unspent outputs paying an address, confirmed and in the mempool.

getBalance

public long[] getBalance(BitcoinAddress address) throws IOException
The balance of an address in satoshis: {confirmed, unconfirmed}, the second the net effect of mempool transactions and possibly negative.

getFeeEstimates

public Map<String, Double> getFeeEstimates() throws IOException
Fee estimates in sat/vB keyed by confirmation target in blocks ("1", "3", "6", "144" and the others the server answers).

getTipHeight

public long getTipHeight() throws IOException
The height of the chain tip.

getTransaction

public BitcoinTransaction getTransaction(String txid) throws IOException
A transaction by id.

getConfirmationHeight

public long getConfirmationHeight(String txid) throws IOException
Whether a transaction is confirmed, and at what height: -1 while it is in the mempool.

broadcast

public String broadcast(BitcoinTransaction signed) throws IOException
Broadcasts a signed transaction, answering its txid.