pub struct Client { /* private fields */ }
Implementations§
source§impl Client
impl Client
pub fn new(url: Url) -> Client
pub fn new_with_credentials( url: Url, username: String, password: String ) -> Client
sourcepub async fn block_number(&self) -> Result<u32, Error>
pub async fn block_number(&self) -> Result<u32, Error>
sourcepub async fn consensus(&self) -> Result<String, Error>
pub async fn consensus(&self) -> Result<String, Error>
Returns information on the current consensus state.
§Arguments
none
§Returns
String describing the consensus state. "established"
is the value for a good state, other values indicate bad state.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.consensus().await;
sourcepub async fn create_account(&self) -> Result<Wallet, Error>
pub async fn create_account(&self) -> Result<Wallet, Error>
Creates a new account and stores its private key in the client store.
§Arguments
none
§Returns
Information on the wallet that was created using the command.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.create_account().await;
sourcepub async fn create_raw_transaction(
&self,
raw_transaction: &OutgoingTransaction
) -> Result<String, Error>
pub async fn create_raw_transaction( &self, raw_transaction: &OutgoingTransaction ) -> Result<String, Error>
Creates and signs a transaction without sending it. The transaction can then be send via sendRawTransaction
without accidentally replaying it.
§Arguments
raw_transaction
:&primitives::OutgoingTransaction
§Returns
The Hex-encoded transaction.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let tx = nimiq_rpc::primitives::OutgoingTransaction {
from: "NQ32 R6DB VFM5 M931 7X4E 0N5Q LJ56 9QCR 4T42".to_string(),
to: "NQ74 61S8 2FD3 RVPG HU09 1Y57 77E6 BL38 TQH3".to_string(),
value: 100, //Lunas
fee: 0
};
let result = client.create_raw_transaction(&tx).await;
sourcepub async fn get_account(&self, id: &str) -> Result<Account, Error>
pub async fn get_account(&self, id: &str) -> Result<Account, Error>
Returns details for the account of given address.
§Arguments
String
: Address to check for balance.
§Returns
Details about the account. Returns the default empty basic account for non-existing accounts.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_account("ad25610feb43d75307763d3f010822a757027429").await;
sourcepub async fn get_accounts_tree_chunk(
&self,
block_hash: &str,
start_prefix: &str
) -> Result<AccountsTreeChunk, Error>
pub async fn get_accounts_tree_chunk( &self, block_hash: &str, start_prefix: &str ) -> Result<AccountsTreeChunk, Error>
Returns an Accounts tree chunk.
§Arguments
String
: Block hash on which the accounts tree chunk is going to be retrieved.String
: Start prefix for the accounts tree chunk to retrieve.
§Returns
An Accounts tree chunk containing the tail prefix and the length of the chunk.
§Example
use nimiq_rpc::Client;
let client = Client::new("http://seed-host.com:8648".to_string());
let result = client.get_accounts_tree_chunk("14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87", "").await;
sourcepub async fn get_balance(&self, id: &str) -> Result<u64, Error>
pub async fn get_balance(&self, id: &str) -> Result<u64, Error>
Returns the balance of the account of given address.
§Arguments
String
: Address to check for balance.
§Returns
Details about the account. The current balance at the specified address (in smallest unit).
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_balance("ad25610feb43d75307763d3f010822a757027429").await;
sourcepub async fn get_block_by_hash(
&self,
block_hash: &str,
full_transactions: bool
) -> Result<Block, Error>
pub async fn get_block_by_hash( &self, block_hash: &str, full_transactions: bool ) -> Result<Block, Error>
Returns information about a block by hash.
§Arguments
String
: Hash of the block to gather information on.Boolean
: Iftrue
it returns the full transaction objects, iffalse
only the hashes of the transactions.
§Returns
A block object or null
when no block was found.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_block_by_hash("14c91f6d6f3a0b62271e546bb09461231ab7e4d1ddc2c3e1b93de52d48a1da87", false).await;
sourcepub async fn get_block_by_number(
&self,
block_number: u32,
full_transactions: bool
) -> Result<Block, Error>
pub async fn get_block_by_number( &self, block_number: u32, full_transactions: bool ) -> Result<Block, Error>
Returns information about a block by block number.
§Arguments
Int
: The height of the block to gather information on.Boolean
: Iftrue
it returns the full transaction objects, iffalse
only the hashes of the transactions.
§Returns
A block object or null
when no block was found.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_block_by_number(1234, false).await;
sourcepub async fn get_block_template(&self) -> Result<FullBlock, Error>
pub async fn get_block_template(&self) -> Result<FullBlock, Error>
Returns a template to build the next block for mining. This will consider pool instructions when connected to a pool.
§Arguments
none
§Returns
A block template object.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_block_template().await;
sourcepub async fn get_block_transaction_count_by_hash(
&self,
block_hash: &str
) -> Result<u16, Error>
pub async fn get_block_transaction_count_by_hash( &self, block_hash: &str ) -> Result<u16, Error>
Returns the number of transactions in a block from a block matching the given block hash.
§Arguments
String
: Hash of the block.
§Returns
Number of transactions in the block found, or null
, when no block was found.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_block_transaction_count_by_hash("dfe7d166f2c86bd10fa4b1f29cd06c13228f893167ce9826137c85758645572f").await;
sourcepub async fn get_block_transaction_count_by_number(
&self,
block_number: u32
) -> Result<u16, Error>
pub async fn get_block_transaction_count_by_number( &self, block_number: u32 ) -> Result<u16, Error>
Returns the number of transactions in a block matching the given block number.
§Arguments
Int
: Height of the block.
§Returns
Number of transactions in the block found, or null
, when no block was found.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_block_transaction_count_by_number(76415).await;
sourcepub async fn get_transaction_by_block_hash_and_index(
&self,
block_hash: &str,
index: u16
) -> Result<Transaction, Error>
pub async fn get_transaction_by_block_hash_and_index( &self, block_hash: &str, index: u16 ) -> Result<Transaction, Error>
Returns information about a transaction by block hash and transaction index position.
§Arguments
String
: Hash of the block containing the transactionInt
: Index of the transaction in the block
§Returns
A transaction object or null
when no transaction was found.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_transaction_by_block_hash_and_index("dfe7d166f2c86bd10fa4b1f29cd06c13228f893167ce9826137c85758645572f", 20).await;
sourcepub async fn get_transaction_by_block_number_and_index(
&self,
block_number: u32,
index: u16
) -> Result<Transaction, Error>
pub async fn get_transaction_by_block_number_and_index( &self, block_number: u32, index: u16 ) -> Result<Transaction, Error>
Returns information about a transaction by block number and transaction index position.
§Arguments
Int
: Height of the block containing the transactionInt
: Index of the transaction in the block
§Returns
A transaction object or null
when no transaction was found.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_transaction_by_block_number_and_index(76415, 20).await;
sourcepub async fn get_transaction_by_hash(
&self,
transaction_hash: &str
) -> Result<TransactionDetails, Error>
pub async fn get_transaction_by_hash( &self, transaction_hash: &str ) -> Result<TransactionDetails, Error>
Returns the information about a transaction requested by transaction hash.
§Arguments
String
: Hash of a transaction
§Returns
A transaction object or null
when no transaction was found.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_transaction_by_hash("465a63b73aa0b9b54b777be9a585ea00b367a17898ad520e1f22cb2c986ff554").await;
sourcepub async fn get_transaction_by_hash_2(
&self,
transaction_hash: &str
) -> Result<TransactionDetails2, Error>
pub async fn get_transaction_by_hash_2( &self, transaction_hash: &str ) -> Result<TransactionDetails2, Error>
Returns the information about a transaction requested by transaction hash.
§Arguments
String
: Hash of a transaction
§Returns
A transaction object or null
when no transaction was found.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_transaction_by_hash_2("465a63b73aa0b9b54b777be9a585ea00b367a17898ad520e1f22cb2c986ff554").await;
sourcepub async fn get_transaction_receipt(
&self,
transaction_hash: &str
) -> Result<TransactionReceipt, Error>
pub async fn get_transaction_receipt( &self, transaction_hash: &str ) -> Result<TransactionReceipt, Error>
Returns the receipt of a transaction by transaction hash.
Note
That the receipt is not available for pending transactions.
§Arguments
String
: Hash of a transaction
§Returns
A transaction receipt object, or null
when no receipt was found
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_transaction_receipt("465a63b73aa0b9b54b777be9a585ea00b367a17898ad520e1f22cb2c986ff554").await;
sourcepub async fn get_transactions_by_address(
&self,
address: &str,
amount: u16
) -> Result<Vec<TransactionDetails>, Error>
pub async fn get_transactions_by_address( &self, address: &str, amount: u16 ) -> Result<Vec<TransactionDetails>, Error>
Returns the latest transactions successfully performed by or for an address.
Note
That this information might change when blocks are rewinded on the local state due to forks.
§Arguments
String
: Address of which transactions should be gathered.Int
: Number of transactions that shall be returned.
§Returns
Vector of transactions linked to the requested address.
Note
The array will not contain more than the requested amount of transactions, but might contain less, even when more transactions happened. Any interpretation of the length of this array might result in worng assumptions.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_transactions_by_address("NQ69 9A4A MB83 HXDQ 4J46 BH5R 4JFF QMA9 C3GN", 10).await;
sourcepub async fn get_work(&self) -> Result<GetWork, Error>
pub async fn get_work(&self) -> Result<GetWork, Error>
Returns instructions to mine the next block. This will consider pool instructions when connected to a pool.
§Arguments
none
§Returns
Mining work instructions
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_work().await;
sourcepub async fn log(&self, tag: &str, level: &str) -> Result<bool, Error>
pub async fn log(&self, tag: &str, level: &str) -> Result<bool, Error>
Sets the log level of the node.
§Arguments
String
: Tag: If'*'
the log level is set globally, otherwise the log level is applied only on this tag.String
: Minimum log level to display. (Valid options:trace
,verbose
,debug
,info
,warn
,error
,assert
)
§Returns
true
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.log("*", "log").await;
pub async fn mempool_content(&self) -> Result<Vec<String>, Error>
pub async fn miner_address(&self) -> Result<String, Error>
pub async fn miner_threads(&self) -> Result<u8, Error>
pub async fn miner_threads_with_update( &self, threads: u16 ) -> Result<u16, Error>
pub async fn min_fee_per_byte(&self) -> Result<u32, Error>
pub async fn min_fee_per_byte_with_update(&self, fee: u32) -> Result<u32, Error>
sourcepub async fn peer_count(&self) -> Result<i8, Error>
pub async fn peer_count(&self) -> Result<i8, Error>
pub async fn peer_list(&self) -> Result<Vec<PeerList>, Error>
pub async fn peer_state(&self, peer_address: &str) -> Result<PeerState, Error>
pub async fn peer_state_with_update( &self, peer_address: &str, set: &str ) -> Result<PeerState, Error>
pub async fn pool_confirmed_balance(&self) -> Result<u64, Error>
pub async fn pool_connection_state(&self) -> Result<u8, Error>
sourcepub async fn send_raw_transaction(
&self,
transaction_hash: &str
) -> Result<String, Error>
pub async fn send_raw_transaction( &self, transaction_hash: &str ) -> Result<String, Error>
Sends a signed message call transaction or a contract creation, if the data field contains code.
§Arguments
String
: The hex encoded signed transaction
§Returns
The Hex-encoded transaction hash.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let tx = nimiq_rpc::primitives::OutgoingTransaction {
from: "NQ32 R6DB VFM5 M931 7X4E 0N5Q LJ56 9QCR 4T42".to_string(),
to: "NQ74 61S8 2FD3 RVPG HU09 1Y57 77E6 BL38 TQH3".to_string(),
value: 100, //Lunas
fee: 0
};
let result = client.create_raw_transaction(&tx).await;
let hash = client.send_raw_transaction(&result.unwrap()).await;
sourcepub async fn send_transaction(
&self,
transaction: &OutgoingTransaction
) -> Result<String, Error>
pub async fn send_transaction( &self, transaction: &OutgoingTransaction ) -> Result<String, Error>
Creates new message call transaction or a contract creation, if the data field contains code.
§Arguments
OutgoingTransaction
: The transaction object
§Returns
The Hex-encoded transaction hash.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let tx = nimiq_rpc::primitives::OutgoingTransaction {
from: "NQ32 R6DB VFM5 M931 7X4E 0N5Q LJ56 9QCR 4T42".to_string(),
to: "NQ74 61S8 2FD3 RVPG HU09 1Y57 77E6 BL38 TQH3".to_string(),
value: 100, //Lunas
fee: 0
};
let result = client.send_transaction(&tx).await;
sourcepub async fn submit_block(&self, full_block: &str) -> Result<(), Error>
pub async fn submit_block(&self, full_block: &str) -> Result<(), Error>
Submits a block to the node. When the block is valid, the node will forward it to other nodes in the network.
§Arguments
String
: Hex-encoded full block (including header, interlink and body). When submitting work fromgetWork
, remember to include thesuffix
.
§Returns
Nothing
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.submit_block("0da1....234").await;
sourcepub async fn syncing(&self) -> Result<Syncing, Error>
pub async fn syncing(&self) -> Result<Syncing, Error>
Returns an object with data about the sync status or false
.
§Arguments
none
§Returns
An object with sync status data or false
, when not syncing
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.syncing().await;
sourcepub async fn get_constant(&self, constant: &str) -> Result<u64, Error>
pub async fn get_constant(&self, constant: &str) -> Result<u64, Error>
Returns a constant
§Arguments
String
: Name of the constant to be obtained.
§Returns
An integer with the value of the constant.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.get_constant("BaseMiniConsensusAgent.MEMPOOL_DELAY_MIN").await;
sourcepub async fn set_constant(
&self,
constant: &str,
value: u64
) -> Result<u64, Error>
pub async fn set_constant( &self, constant: &str, value: u64 ) -> Result<u64, Error>
Sets a constant with the value provided and returns the new value on success
§Arguments
String
: Name of the constant to be set.Int
: The value to be set to the constant.
§Returns
An integer with the new value of the constant.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.set_constant("BaseMiniConsensusAgent.MEMPOOL_DELAY_MIN", 6).await;
sourcepub async fn reset_constant(&self, constant: &str) -> Result<u64, Error>
pub async fn reset_constant(&self, constant: &str) -> Result<u64, Error>
Resets a constant and returns the new value on success
§Arguments
String
: Name of the constant to be reset.
§Returns
An integer with the new value of the constant.
§Example
use nimiq_rpc::Client;
use url::Url;
let client = Client::new(Url::parse("http://seed-host.com:8648").unwrap());
let result = client.reset_constant("BaseMiniConsensusAgent.MEMPOOL_DELAY_MIN").await;