pub struct StorageDeposit(AccountId);Expand description
A wrapper struct that simplifies interactions with the Storage Management standard
Contracts on NEAR Protocol often implement a NEP-145 for managing storage deposits, which are required for storing data on the blockchain. This struct provides convenient methods to interact with these storage-related functions on the contract.
§Example
use near_api::*;
let storage = StorageDeposit::on_contract("contract.testnet".parse()?);
// Check storage balance
let balance = storage.view_account_storage("alice.testnet".parse()?)?.fetch_from_testnet().await?;
println!("Storage balance: {:?}", balance);
// Bob pays for Alice's storage on the contract contract.testnet
let deposit_tx = storage.deposit("alice.testnet".parse()?, NearToken::from_near(1))?
.with_signer("bob.testnet".parse()?, Signer::new(Signer::from_ledger())?)
.send_to_testnet()
.await
.unwrap();Tuple Fields§
§0: AccountIdImplementations§
Source§impl StorageDeposit
impl StorageDeposit
pub const fn on_contract(contract_id: AccountId) -> Self
Sourcepub const fn contract_id(&self) -> &AccountId
pub const fn contract_id(&self) -> &AccountId
Returns the underlying contract account ID for this storage deposit wrapper.
§Example
use near_api::*;
let storage = StorageDeposit::on_contract("contract.testnet".parse()?);
let contract_id = storage.contract_id();
println!("Contract ID: {}", contract_id);Sourcepub fn as_contract(&self) -> Contract
pub fn as_contract(&self) -> Contract
Converts this storage deposit wrapper to a Contract for other contract operations.
§Example
use near_api::*;
let storage = StorageDeposit::on_contract("usdt.tether-token.near".parse()?);
let contract = storage.as_contract();
// Now you can call other contract methods
let metadata: serde_json::Value = contract.call_function("ft_metadata", ())?.read_only().fetch_from_mainnet().await?.data;
println!("Token metadata: {:?}", metadata);Sourcepub fn view_account_storage(
&self,
account_id: AccountId,
) -> Result<RequestBuilder<PostprocessHandler<Data<Option<StorageBalance>>, CallResultHandler<Option<StorageBalanceInternal>>>>, BuilderError>
pub fn view_account_storage( &self, account_id: AccountId, ) -> Result<RequestBuilder<PostprocessHandler<Data<Option<StorageBalance>>, CallResultHandler<Option<StorageBalanceInternal>>>>, BuilderError>
Prepares a new contract query (storage_balance_of) for fetching the storage balance (Option<StorageBalance>) of the account on the contract.
§Example
use near_api::*;
let balance = StorageDeposit::on_contract("contract.testnet".parse()?)
.view_account_storage("alice.testnet".parse()?)?
.fetch_from_testnet()
.await?;
println!("Storage balance: {:?}", balance);Sourcepub fn deposit(
&self,
receiver_account_id: AccountId,
amount: NearToken,
) -> Result<ContractTransactBuilder, BuilderError>
pub fn deposit( &self, receiver_account_id: AccountId, amount: NearToken, ) -> Result<ContractTransactBuilder, BuilderError>
Prepares a new transaction contract call (storage_deposit) for depositing storage on the contract.
§Example
use near_api::*;
let tx = StorageDeposit::on_contract("contract.testnet".parse()?)
.deposit("alice.testnet".parse()?, NearToken::from_near(1))?
.with_signer("bob.testnet".parse()?, Signer::new(Signer::from_ledger())?)
.send_to_testnet()
.await?;Sourcepub fn withdraw(
&self,
account_id: AccountId,
amount: NearToken,
) -> Result<ConstructTransaction, BuilderError>
pub fn withdraw( &self, account_id: AccountId, amount: NearToken, ) -> Result<ConstructTransaction, BuilderError>
Prepares a new transaction contract call (storage_withdraw) for withdrawing storage from the contract.
§Example
use near_api::*;
let tx = StorageDeposit::on_contract("contract.testnet".parse()?)
.withdraw("alice.testnet".parse()?, NearToken::from_near(1))?
.with_signer(Signer::new(Signer::from_ledger())?)
.send_to_testnet()
.await?;Trait Implementations§
Source§impl Clone for StorageDeposit
impl Clone for StorageDeposit
Source§fn clone(&self) -> StorageDeposit
fn clone(&self) -> StorageDeposit
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more