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 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
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for StorageDeposit
impl RefUnwindSafe for StorageDeposit
impl Send for StorageDeposit
impl Sync for StorageDeposit
impl Unpin for StorageDeposit
impl UnwindSafe for StorageDeposit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more