Struct fuels_signers::wallet::Wallet
source · pub struct Wallet { /* private fields */ }
Expand description
A FuelVM-compatible wallet that can be used to list assets, balances and more.
Note that instances of the Wallet
type only know their public address, and as a result can
only perform read-only operations.
In order to sign messages or send transactions, a Wallet
must first call Wallet::unlock
with a valid private key to produce a WalletUnlocked
.
Implementations§
source§impl Wallet
impl Wallet
sourcepub fn from_address(address: Bech32Address, provider: Option<Provider>) -> Self
pub fn from_address(address: Bech32Address, provider: Option<Provider>) -> Self
Construct a Wallet from its given public address.
pub fn get_provider(&self) -> Result<&Provider, WalletError>
pub fn set_provider(&mut self, provider: Provider)
pub fn address(&self) -> &Bech32Address
pub async fn get_transactions(
&self,
request: PaginationRequest<String>
) -> Result<PaginatedResult<TransactionResponse, String>, Error>
sourcepub async fn get_asset_inputs_for_amount(
&self,
asset_id: AssetId,
amount: u64,
witness_index: u8
) -> Result<Vec<Input>, Error>
pub async fn get_asset_inputs_for_amount(
&self,
asset_id: AssetId,
amount: u64,
witness_index: u8
) -> Result<Vec<Input>, Error>
Returns a proper vector of Input::Coin
s for the given asset ID, amount, and witness index.
The witness_index
is the position of the witness
(signature) in the transaction’s list of witnesses.
Meaning that, in the validation process, the node will
use the witness at this index to validate the coins returned
by this method.
sourcepub fn get_asset_outputs_for_amount(
&self,
to: &Bech32Address,
asset_id: AssetId,
amount: u64
) -> Vec<Output> ⓘ
pub fn get_asset_outputs_for_amount(
&self,
to: &Bech32Address,
asset_id: AssetId,
amount: u64
) -> Vec<Output> ⓘ
Returns a vector containing the output coin and change output given an asset and amount
sourcepub async fn get_coins(&self, asset_id: AssetId) -> Result<Vec<Coin>, Error>
pub async fn get_coins(&self, asset_id: AssetId) -> Result<Vec<Coin>, Error>
Gets all coins of asset asset_id
owned by the wallet, even spent ones (this is useful
for some particular cases, but in general, you should use get_spendable_coins
). This
returns actual coins (UTXOs).
sourcepub async fn get_spendable_resources(
&self,
asset_id: AssetId,
amount: u64
) -> Result<Vec<Resource>, Error>
pub async fn get_spendable_resources(
&self,
asset_id: AssetId,
amount: u64
) -> Result<Vec<Resource>, Error>
Get some spendable resources (coins and messages) of asset asset_id
owned by the wallet
that add up at least to amount amount
. The returned coins (UTXOs) are actual coins that
can be spent. The number of UXTOs is optimized to prevent dust accumulation.
sourcepub async fn get_asset_balance(&self, asset_id: &AssetId) -> Result<u64, Error>
pub async fn get_asset_balance(&self, asset_id: &AssetId) -> Result<u64, Error>
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_balances(&self) -> Result<HashMap<String, u64>, Error>
pub async fn get_balances(&self) -> Result<HashMap<String, u64>, Error>
Get all the spendable balances of all assets for the wallet. This is different from getting the coins because we are only returning the sum of UTXOs coins amount and not the UTXOs coins themselves.
pub async fn get_messages(&self) -> Result<Vec<InputMessage>, Error>
sourcepub fn unlock(self, private_key: SecretKey) -> WalletUnlocked
pub fn unlock(self, private_key: SecretKey) -> WalletUnlocked
Unlock the wallet with the given private_key
.
The private key will be stored in memory until wallet.lock()
is called or until the
wallet is drop
ped.
sourcepub fn build_transfer_tx(
inputs: &[Input],
outputs: &[Output],
params: TxParameters
) -> Script
pub fn build_transfer_tx(
inputs: &[Input],
outputs: &[Output],
params: TxParameters
) -> Script
Craft a transaction used to transfer funds between two addresses.
sourcepub fn build_contract_transfer_tx(
to: ContractId,
amount: u64,
asset_id: AssetId,
inputs: &[Input],
outputs: &[Output],
params: TxParameters
) -> Script
pub fn build_contract_transfer_tx(
to: ContractId,
amount: u64,
asset_id: AssetId,
inputs: &[Input],
outputs: &[Output],
params: TxParameters
) -> Script
Craft a transaction used to transfer funds to a contract.
sourcepub fn build_message_to_output_tx(
to: Address,
amount: u64,
inputs: &[Input],
params: TxParameters
) -> Script
pub fn build_message_to_output_tx(
to: Address,
amount: u64,
inputs: &[Input],
params: TxParameters
) -> Script
Craft a transaction used to transfer funds to the base chain.