pub struct ApiClient {
pub url: String,
pub reqwest: Client,
}
Expand description
Client to call esplora api, it use and Esplora Api Url. I can use custom reqwest Client build from reqwest client builder
Fields§
§url: String
§reqwest: Client
Implementations§
Source§impl ApiClient
impl ApiClient
Sourcepub fn new(
url: &str,
options: Option<ClientOptions>,
) -> Result<Self, Box<dyn Error>>
pub fn new( url: &str, options: Option<ClientOptions>, ) -> Result<Self, Box<dyn Error>>
new client from endpoint Esplora Api Url, and ClientOptions.
Example without options :
use esplora_api::async_impl::ApiClient;
fn main(){
let client = esplora_api::async_impl::ApiClient::new("https://some_esplora_url.com", None);
}
Example with custom authorization header :
use esplora_api::async_impl::{ApiClient, ClientOptions, HeadersOptions};
fn main(){
let options = ClientOptions { headers: Some( HeadersOptions { authorization: Some("secret".to_string())}),};
let client = esplora_api::async_impl::ApiClient::new("https://some_esplora_url.com", Some(options));
}
Sourcepub fn new_from_config(
url: &str,
client: Client,
) -> Result<Self, Box<dyn Error>>
pub fn new_from_config( url: &str, client: Client, ) -> Result<Self, Box<dyn Error>>
new_from_config new client from endpoint Esplora Api Url, and reqwest client.
Example without custom reqwest client :
use esplora_api::async_impl::ApiClient;
use reqwest;
use reqwest::header;
fn main(){
let mut headers = header::HeaderMap::new();
headers.insert(header::AUTHORIZATION,header::HeaderValue::from_static("secret"));
let reqwest_client = reqwest::Client::builder().default_headers(headers).build().unwrap();
let client = esplora_api::async_impl::ApiClient::new_from_config("https://some_esplora_url.com", reqwest_client);
}
Sourcepub async fn get_block(&self, hash: &str) -> Result<BlockFormat, Box<dyn Error>>
pub async fn get_block(&self, hash: &str) -> Result<BlockFormat, Box<dyn Error>>
get_block Returns information about a block.
Route : GET /block/:hash. Available fields:
Elements-based chains have an additional proof field. See block format for more details. The response from this endpoint can be cached indefinitely.
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_block("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_block_status(
&self,
hash: &str,
) -> Result<BlockStatus, Box<dyn Error>>
pub async fn get_block_status( &self, hash: &str, ) -> Result<BlockStatus, Box<dyn Error>>
get_block_status Returns the block status.
Route : GET /block/:hash/status. Available fields:
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_block_status("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_block_txs(
&self,
hash: &str,
start_index: Option<i32>,
) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
pub async fn get_block_txs( &self, hash: &str, start_index: Option<i32>, ) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
get_block_txs Returns a list of transactions in the block (up to 25 transactions beginning at start_index).
Route : GET /block/:hash/txs[/:start_index]
Transactions returned here do not have the status field, since all the transactions share the same block and confirmation status. The response from this endpoint can be cached indefinitely.
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_block_txs("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7", Some(25)).await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_block_txids(
&self,
hash: &str,
) -> Result<Vec<String>, Box<dyn Error>>
pub async fn get_block_txids( &self, hash: &str, ) -> Result<Vec<String>, Box<dyn Error>>
get_block_txids Returns a list of all txids in the block.
Route : GET /block/:hash/txids
The response from this endpoint can be cached indefinitely.
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_block_txids("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_block_txid_at_index(
&self,
hash: &str,
index: i32,
) -> Result<String, Box<dyn Error>>
pub async fn get_block_txid_at_index( &self, hash: &str, index: i32, ) -> Result<String, Box<dyn Error>>
get_block_txid_at_index Returns the transaction at index :index within the specified block.
Route : GET /block/:hash/txid/:index
The response from this endpoint can be cached indefinitely.
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_block_txid_at_index("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7",25).await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_block_raw_format(
&self,
hash: &str,
) -> Result<Vec<u8>, Box<dyn Error>>
pub async fn get_block_raw_format( &self, hash: &str, ) -> Result<Vec<u8>, Box<dyn Error>>
get_block_raw_format Returns the raw block representation in binary.
Route : GET /block/:hash/raw
The response from this endpoint can be cached indefinitely.
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_block_raw_format("000000000000003aaa3b99e31ed1cac4744b423f9e52ada4971461c81d4192f7").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_block_height(
&self,
height: i32,
) -> Result<String, Box<dyn Error>>
pub async fn get_block_height( &self, height: i32, ) -> Result<String, Box<dyn Error>>
get_block_height Returns the hash of the block currently at height.
Route : GET /block-height/:height
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_block_height(424242).await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_blocks(
&self,
start_height: i32,
) -> Result<Vec<BlockFormat>, Box<dyn Error>>
pub async fn get_blocks( &self, start_height: i32, ) -> Result<Vec<BlockFormat>, Box<dyn Error>>
get_blocks Returns the 10 newest blocks starting at the tip or at start_height if specified.
Route : GET /blocks[/:start_height]
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_blocks(1234).await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_blocks_tip_height(&self) -> Result<i32, Box<dyn Error>>
pub async fn get_blocks_tip_height(&self) -> Result<i32, Box<dyn Error>>
get_blocks_tip_height Returns the height of the last block.
Route : GET /blocks/tip/height
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_blocks_tip_height().await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_blocks_tip_hash(&self) -> Result<String, Box<dyn Error>>
pub async fn get_blocks_tip_hash(&self) -> Result<String, Box<dyn Error>>
get_blocks_tip_hash Returns the hash of the last block.
Route : GET /blocks/tip/hash
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_blocks_tip_height().await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_tx(
&self,
txid: &str,
) -> Result<TransactionFormat, Box<dyn Error>>
pub async fn get_tx( &self, txid: &str, ) -> Result<TransactionFormat, Box<dyn Error>>
get_tx Returns information about the transaction. Available fields: txid, version, locktime, size, weight, fee, vin, vout and status (see transaction format for details).
Route : GET /tx/:txid
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_tx("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_tx_status(
&self,
txid: &str,
) -> Result<TxStatusFormat, Box<dyn Error>>
pub async fn get_tx_status( &self, txid: &str, ) -> Result<TxStatusFormat, Box<dyn Error>>
get_tx_status Returns the transaction confirmation status. Available fields: confirmed (boolean), block_height (optional) and block_hash (optional).
Route : GET /tx/:txid/status
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_tx_status("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_tx_raw(&self, txid: &str) -> Result<Vec<u8>, Box<dyn Error>>
pub async fn get_tx_raw(&self, txid: &str) -> Result<Vec<u8>, Box<dyn Error>>
get_tx_raw Returns the raw transaction as binary data.
Route : GET /tx/:txid/raw
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_tx_raw("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_tx_hex(&self, txid: &str) -> Result<String, Box<dyn Error>>
pub async fn get_tx_hex(&self, txid: &str) -> Result<String, Box<dyn Error>>
get_tx_hex Returns the raw transaction in hex
Route : GET /tx/:txid/hex
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_tx_hex("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_tx_merkleblock_proof(
&self,
txid: &str,
) -> Result<String, Box<dyn Error>>
pub async fn get_tx_merkleblock_proof( &self, txid: &str, ) -> Result<String, Box<dyn Error>>
get_tx_merkleblock_proof Returns a merkle inclusion proof for the transaction using bitcoind’s merkleblock format. Note: This endpoint is not currently available for Liquid/Elements-based chains. Route : GET /tx/:txid/merkleblock-proof
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_tx_merkleblock_proof("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_tx_merkle_proof(
&self,
txid: &str,
) -> Result<MerkleProofFormat, Box<dyn Error>>
pub async fn get_tx_merkle_proof( &self, txid: &str, ) -> Result<MerkleProofFormat, Box<dyn Error>>
get_tx_merkle_proof Returns a merkle inclusion proof for the transaction using Electrum’s blockchain.transaction.get_merkle format.
Route : GET /tx/:txid/merkle-proof
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_tx_merkle_proof("c9ee6eff3d73d6cb92382125c3207f6447922b545d4d4e74c47bfeb56fff7d24").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_tx_outspend(
&self,
txid: &str,
vout: Option<i32>,
) -> Result<OutspentFormat, Box<dyn Error>>
pub async fn get_tx_outspend( &self, txid: &str, vout: Option<i32>, ) -> Result<OutspentFormat, Box<dyn Error>>
get_tx_outspend Returns the spending status of a transaction output. Available fields: spent (boolean), txid (optional), vin (optional) and status (optional, the status of the spending tx).
Route : GET /tx/:txid/outspend/:vout
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_tx_outspend("fac9af7f793330af3cc0bce4790d98499c59d47a125af7260edd61d647003316",Some(1)).await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_tx_outspends(
&self,
txid: &str,
) -> Result<Vec<OutspentFormat>, Box<dyn Error>>
pub async fn get_tx_outspends( &self, txid: &str, ) -> Result<Vec<OutspentFormat>, Box<dyn Error>>
get_tx_outspends Returns the spending status of all transaction outputs.
Route : GET /tx/:txid/outspends
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_tx_outspends("fac9af7f793330af3cc0bce4790d98499c59d47a125af7260edd61d647003316").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn post_tx(
&self,
hex_transaction: &str,
) -> Result<String, Box<dyn Error>>
pub async fn post_tx( &self, hex_transaction: &str, ) -> Result<String, Box<dyn Error>>
post_tx Broadcast a raw transaction to the network. The transaction should be provided as hex in the request body. The txid will be returned on success.
Route : POST /tx
Sourcepub async fn get_address(
&self,
address: &str,
) -> Result<AddressInfoFormat, Box<dyn Error>>
pub async fn get_address( &self, address: &str, ) -> Result<AddressInfoFormat, Box<dyn Error>>
get_address Get information about an address Available fields: address/scripthash, chain_stats and mempool_stats. {chain,mempool}_stats each contain an object with tx_count, funded_txo_count, funded_txo_sum, spent_txo_count and spent_txo_sum. Elements-based chains don’t have the {funded,spent}_txo_sum fields.
Route : GET /address/:address
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_address("2MvJVm11phGoxEekPB8Hw2Tksb57eVRGHC5").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_script_hash(
&self,
scripthash: &str,
) -> Result<AddressInfoFormat, Box<dyn Error>>
pub async fn get_script_hash( &self, scripthash: &str, ) -> Result<AddressInfoFormat, Box<dyn Error>>
get_script_hash Get information about an scripthash Available fields: scripthash, chain_stats and mempool_stats. {chain,mempool}_stats each contain an object with tx_count, funded_txo_count, funded_txo_sum, spent_txo_count and spent_txo_sum. Elements-based chains don’t have the {funded,spent}_txo_sum fields.
Route : GET /scripthash/:hash
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_script_hash("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_address_txs(
&self,
address: &str,
) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
pub async fn get_address_txs( &self, address: &str, ) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
get_address_txs Get transaction history for the specified address/scripthash, sorted with newest first. Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using :last_seen_txid(see below).
Route : GET /address/:address/txs
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_address_txs("2MvJVm11phGoxEekPB8Hw2Tksb57eVRGHC5").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_script_hash_txs(
&self,
scripthash: &str,
) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
pub async fn get_script_hash_txs( &self, scripthash: &str, ) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
get_script_hash_txs Get transaction history for the specified address/scripthash, sorted with newest first. Returns up to 50 mempool transactions plus the first 25 confirmed transactions. You can request more confirmed transactions using :last_seen_txid(see below).
Route : GET /scripthash/:hash/txs
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_script_hash_txs("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_address_txs_chain(
&self,
address: &str,
txid: Option<&str>,
) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
pub async fn get_address_txs_chain( &self, address: &str, txid: Option<&str>, ) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
get_address_txs_chain Get confirmed transaction history for the specified address/scripthash, sorted with newest first. Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query.
Route : GET /address/:address/txs/chain[/:last_seen_txid]
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_address_txs_chain("n1vgV8XmoggmRXzW3hGD8ZNTAgvhcwT4Gk",Some("d0075b62f8b3e464472b8edecf56083ca3e9e8424f5f332ed2f9045d7fcccddc")).await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_script_hash_txs_chain(
&self,
scripthash: &str,
txid: Option<&str>,
) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
pub async fn get_script_hash_txs_chain( &self, scripthash: &str, txid: Option<&str>, ) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
get_script_hash_txs_chain Get confirmed transaction history for the specified address/scripthash, sorted with newest first. Returns 25 transactions per page. More can be requested by specifying the last txid seen by the previous query.
Route : GET /scripthash/:hash/txs/chain[/:last_seen_txid]
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_script_hash_txs_chain("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c",None).await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_address_txs_mempool(
&self,
address: &str,
) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
pub async fn get_address_txs_mempool( &self, address: &str, ) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
get_address_txs_mempool Get unconfirmed transaction history for the specified address. Returns up to 50 transactions (no paging).
Route : GET /address/:address/txs/mempool
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_address_txs_mempool("2MvJVm11phGoxEekPB8Hw2Tksb57eVRGHC5").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_script_hash_txs_mempool(
&self,
scripthash: &str,
) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
pub async fn get_script_hash_txs_mempool( &self, scripthash: &str, ) -> Result<Vec<TransactionFormat>, Box<dyn Error>>
get_script_hash_txs_mempool Get unconfirmed transaction history for the specified scripthash. Returns up to 50 transactions (no paging).
Route : GET /scripthash/:hash/txs/mempool
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_script_hash_txs_mempool("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_address_utxo(
&self,
address: &str,
) -> Result<Vec<UtxoFormat>, Box<dyn Error>>
pub async fn get_address_utxo( &self, address: &str, ) -> Result<Vec<UtxoFormat>, Box<dyn Error>>
get_address_utxo Get the list of unspent transaction outputs associated with the address Available fields: txid, vout, value and status (with the status of the funding tx). Elements-based chains have a valuecommitment field that may appear in place of value, plus the following additional fields: asset/assetcommitment, nonce/noncecommitment, surjection_proof and range_proof.
Route : GET /address/:address/utxo
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_address_utxo("2NDcM3CGUTwqFL7y8BSBJTYJ9kToeXawkUF").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_script_hash_utxo(
&self,
scripthash: &str,
) -> Result<Vec<UtxoFormat>, Box<dyn Error>>
pub async fn get_script_hash_utxo( &self, scripthash: &str, ) -> Result<Vec<UtxoFormat>, Box<dyn Error>>
get_script_hash_utxo Get the list of unspent transaction outputs associated with the address Available fields: txid, vout, value and status (with the status of the funding tx). Elements-based chains have a valuecommitment field that may appear in place of value, plus the following additional fields: asset/assetcommitment, nonce/noncecommitment, surjection_proof and range_proof.
Route : GET /scripthash/:hash/utxo
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_script_hash_utxo("c6598a8e5728c744b9734facbf1e786c3ff5101268739d38b14ea475b60eba3c").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_address_prefix(
&self,
prefix: &str,
) -> Result<Vec<String>, Box<dyn Error>>
pub async fn get_address_prefix( &self, prefix: &str, ) -> Result<Vec<String>, Box<dyn Error>>
get_address_prefix This feature is disabled by default on custom api Search for addresses beginning with :prefix. Returns a JSON array with up to 10 results.
Route : GET /address-prefix/:prefix
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_address_prefix("2NDcM").await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_mempool(&self) -> Result<MemPoolFormat, Box<dyn Error>>
pub async fn get_mempool(&self) -> Result<MemPoolFormat, Box<dyn Error>>
get_mempool Get mempool backlog statistics. Returns an object with: count: the number of transactions in the mempool vsize: the total size of mempool transactions in virtual bytes total_fee: the total fee paid by mempool transactions in satoshis fee_histogram: mempool fee-rate distribution histogram An array of (feerate, vsize) tuples, where each entry’s vsize is the total vsize of transactions paying more than feerate but less than the previous entry’s feerate (except for the first entry, which has no upper bound). This matches the format used by the Electrum RPC protocol for mempool.get_fee_histogram.
Route : GET /mempool
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_mempool().await?;
println!("{:?}",response);
Ok(())
}
Example output:
{
"count": 8134,
"vsize": 3444604,
"total_fee":29204625,
"fee_histogram": [[53.01, 102131], [38.56, 110990], [34.12, 138976], [24.34, 112619], [3.16, 246346], [2.92, 239701], [1.1, 775272]]
}
In this example, there are transactions weighting a total of 102,131 vbytes that are paying more than 53 sat/vB, 110,990 vbytes of transactions paying between 38 and 53 sat/vB, 138,976 vbytes paying between 34 and 38, etc.
Sourcepub async fn get_mempool_txids(&self) -> Result<Vec<String>, Box<dyn Error>>
pub async fn get_mempool_txids(&self) -> Result<Vec<String>, Box<dyn Error>>
get_mempool_txids Get the full list of txids in the mempool as an array. The order of the txids is arbitrary and does not match bitcoind’s.
Route : GET /mempool/txids
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_mempool_txids().await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn get_mempool_recent(
&self,
) -> Result<Vec<MempoolTxFormat>, Box<dyn Error>>
pub async fn get_mempool_recent( &self, ) -> Result<Vec<MempoolTxFormat>, Box<dyn Error>>
get_mempool_recent Get a list of the last 10 transactions to enter the mempool. Each transaction object contains simplified overview data, with the following fields: txid, fee, vsize and value Fee estimates The order of the txids is arbitrary and does not match bitcoind’s.
Route : GET /mempool/recent
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.get_mempool_recent().await?;
println!("{:?}",response);
Ok(())
}
Sourcepub async fn fee_estimate(&self) -> Result<HashMap<String, f32>, Box<dyn Error>>
pub async fn fee_estimate(&self) -> Result<HashMap<String, f32>, Box<dyn Error>>
fee_estimate Get an object where the key is the confirmation target (in number of blocks) and the value is the estimated feerate (in sat/vB). The available confirmation targets are 1-25, 144, 504 and 1008 blocks. For example: { “1”: 87.882, “2”: 87.882, “3”: 87.882, “4”: 87.882, “5”: 81.129, “6”: 68.285, …, “144”: 1.027, “504”: 1.027, “1008”: 1.027 }
Route : GET /fee-estimates
Example :
use esplora_api;
#[tokio::main]
async fn run() -> Result<(), Box<dyn std::error::Error>> {
let client = esplora_api::async_impl::ApiClient::new("https://blockstream.info/testnet/api/", None).unwrap();
let response = client.fee_estimate().await?;
println!("{:?}",response);
Ok(())
}