Struct fuels_signers::provider::Provider
source · pub struct Provider {
pub client: FuelClient,
}
Expand description
Encapsulates common client operations in the SDK.
Note that you may also use client
, which is an instance
of FuelClient
, directly, which provides a broader API.
Fields§
§client: FuelClient
Implementations§
source§impl Provider
impl Provider
pub fn new(client: FuelClient) -> Self
sourcepub async fn send_transaction<Tx>(&self, tx: &Tx) -> Result<Vec<Receipt>, Error>where
Tx: ExecutableTransaction + GasLimit + GasPrice + Into<Transaction>,
pub async fn send_transaction<Tx>(&self, tx: &Tx) -> Result<Vec<Receipt>, Error>where
Tx: ExecutableTransaction + GasLimit + GasPrice + Into<Transaction>,
Sends a transaction to the underlying Provider’s client.
Examples
Sending a transaction
use fuels::tx::Script;
use fuels::prelude::*;
async fn foo() -> Result<(), Box<dyn std::error::Error>> {
// Setup local test node
let (provider, _) = setup_test_provider(vec![], vec![], None, None).await;
let tx = Script::default();
let receipts = provider.send_transaction(&tx).await?;
dbg!(receipts);
Ok(())
}
sourcepub async fn connect(url: impl AsRef<str>) -> Result<Provider, Error>
pub async fn connect(url: impl AsRef<str>) -> Result<Provider, Error>
Connects to an existing node at the given address.
Examples
Connect to a node
async fn connect_to_fuel_node() {
use fuels::prelude::*;
// This is the address of a running node.
let server_address = "127.0.0.1:4000";
// Create the provider using the client.
let provider = Provider::connect(server_address).await.unwrap();
// Create the wallet.
let _wallet = WalletUnlocked::new_random(Some(provider));
}
pub async fn chain_info(&self) -> Result<ChainInfo, ProviderError>
pub async fn consensus_parameters(
&self
) -> Result<ConsensusParameters, ProviderError>
pub async fn node_info(&self) -> Result<NodeInfo, ProviderError>
pub async fn dry_run(
&self,
tx: &Transaction
) -> Result<Vec<Receipt>, ProviderError>
pub async fn dry_run_no_validation(
&self,
tx: &Transaction
) -> Result<Vec<Receipt>, ProviderError>
sourcepub async fn get_coins(
&self,
from: &Bech32Address,
asset_id: AssetId
) -> Result<Vec<Coin>, ProviderError>
pub async fn get_coins(
&self,
from: &Bech32Address,
asset_id: AssetId
) -> Result<Vec<Coin>, ProviderError>
Gets all coins owned by address from
, with asset ID asset_id
, even spent ones. This
returns actual coins (UTXOs).
sourcepub async fn get_spendable_resources(
&self,
from: &Bech32Address,
asset_id: AssetId,
amount: u64
) -> Result<Vec<Resource>, ProviderError>
pub async fn get_spendable_resources(
&self,
from: &Bech32Address,
asset_id: AssetId,
amount: u64
) -> Result<Vec<Resource>, ProviderError>
Get some spendable coins of asset asset_id
for address from
that add up at least to
amount amount
. The returned coins (UTXOs) are actual coins that can be spent. The number
of coins (UXTOs) is optimized to prevent dust accumulation.
sourcepub async fn get_asset_balance(
&self,
address: &Bech32Address,
asset_id: AssetId
) -> Result<u64, ProviderError>
pub async fn get_asset_balance(
&self,
address: &Bech32Address,
asset_id: AssetId
) -> Result<u64, ProviderError>
Get the balance of all spendable coins asset_id
for address address
. This is different
from getting coins because we are just returning a number (the sum of UTXOs amount) instead
of the UTXOs.
sourcepub async fn get_contract_asset_balance(
&self,
contract_id: &Bech32ContractId,
asset_id: AssetId
) -> Result<u64, ProviderError>
pub async fn get_contract_asset_balance(
&self,
contract_id: &Bech32ContractId,
asset_id: AssetId
) -> Result<u64, ProviderError>
Get the balance of all spendable coins asset_id
for contract with id contract_id
.
sourcepub async fn get_balances(
&self,
address: &Bech32Address
) -> Result<HashMap<String, u64>, ProviderError>
pub async fn get_balances(
&self,
address: &Bech32Address
) -> Result<HashMap<String, u64>, ProviderError>
Get all the spendable balances of all assets for address address
. This is different from
getting the coins because we are only returning the numbers (the sum of UTXOs coins amount
for each asset id) and not the UTXOs coins themselves
sourcepub async fn get_contract_balances(
&self,
contract_id: &Bech32ContractId
) -> Result<HashMap<String, u64>, ProviderError>
pub async fn get_contract_balances(
&self,
contract_id: &Bech32ContractId
) -> Result<HashMap<String, u64>, ProviderError>
Get all balances of all assets for the contract with id contract_id
.
pub async fn get_transaction_by_id(
&self,
tx_id: &str
) -> Result<Option<TransactionResponse>, ProviderError>
pub async fn get_transactions(
&self,
request: PaginationRequest<String>
) -> Result<PaginatedResult<TransactionResponse, String>, ProviderError>
pub async fn get_transactions_by_owner(
&self,
owner: &Bech32Address,
request: PaginationRequest<String>
) -> Result<PaginatedResult<TransactionResponse, String>, ProviderError>
pub async fn latest_block_height(&self) -> Result<u64, ProviderError>
pub async fn produce_blocks(
&self,
amount: u64,
time: Option<TimeParameters>
) -> Result<u64>
sourcepub async fn block(&self, block_id: &str) -> Result<Option<Block>, ProviderError>
pub async fn block(&self, block_id: &str) -> Result<Option<Block>, ProviderError>
Get block by id.