Struct workspaces::Account
source · pub struct Account { /* private fields */ }
Expand description
Account
is directly associated to an account in the network provided by the
Worker
that creates it. This type offers methods to interact with any
network, such as creating transactions and calling into contract functions.
Implementations§
source§impl Account
impl Account
sourcepub fn from_file(
path: impl AsRef<Path>,
worker: &Worker<impl Network + 'static>
) -> Result<Self>
pub fn from_file(
path: impl AsRef<Path>,
worker: &Worker<impl Network + 'static>
) -> Result<Self>
Create a new account with the given path to the credentials JSON file
sourcepub fn from_secret_key(
id: AccountId,
sk: SecretKey,
worker: &Worker<impl Network + 'static>
) -> Self
pub fn from_secret_key(
id: AccountId,
sk: SecretKey,
worker: &Worker<impl Network + 'static>
) -> Self
sourcepub fn signer(&self) -> &InMemorySigner
pub fn signer(&self) -> &InMemorySigner
Grab the signer of the account. This signer is used to sign all transactions sent to the network.
sourcepub fn call(&self, contract_id: &AccountId, function: &str) -> CallTransaction<'_>
pub fn call(&self, contract_id: &AccountId, function: &str) -> CallTransaction<'_>
Call a contract on the network specified within worker
, and return
a CallTransaction
object that we will make use to populate the
rest of the call details. Note that the current Account
’s secret
key is used as the signer of the transaction.
sourcepub fn view(
&self,
contract_id: &AccountId,
function: &str
) -> Query<'_, ViewFunction>
pub fn view(
&self,
contract_id: &AccountId,
function: &str
) -> Query<'_, ViewFunction>
View call to a specified contract function. Returns a result which can be deserialized into borsh or JSON.
sourcepub async fn transfer_near(
&self,
receiver_id: &AccountId,
amount: Balance
) -> Result<ExecutionFinalResult>
pub async fn transfer_near(
&self,
receiver_id: &AccountId,
amount: Balance
) -> Result<ExecutionFinalResult>
Transfer NEAR to an account specified by receiver_id
with the amount
specified by amount
. Returns the execution details of this transaction
sourcepub async fn delete_account(
self,
beneficiary_id: &AccountId
) -> Result<ExecutionFinalResult>
pub async fn delete_account(
self,
beneficiary_id: &AccountId
) -> Result<ExecutionFinalResult>
Deletes the current account, and returns the execution details of this transaction. The beneficiary will receive the funds of the account deleted
sourcepub fn view_account(&self) -> Query<'_, ViewAccount>
pub fn view_account(&self) -> Query<'_, ViewAccount>
Views the current account’s details such as balance and storage usage.
sourcepub fn view_access_key(&self, pk: &PublicKey) -> Query<'_, ViewAccessKey>
pub fn view_access_key(&self, pk: &PublicKey) -> Query<'_, ViewAccessKey>
Views the current accounts’s access key, given the PublicKey
associated to it.
sourcepub fn view_access_keys(&self) -> Query<'_, ViewAccessKeyList>
pub fn view_access_keys(&self) -> Query<'_, ViewAccessKeyList>
sourcepub fn create_subaccount<'a, 'b>(
&'a self,
new_account_id: &'b str
) -> CreateAccountTransaction<'a, 'b>
pub fn create_subaccount<'a, 'b>(
&'a self,
new_account_id: &'b str
) -> CreateAccountTransaction<'a, 'b>
Create a new sub account. Returns a CreateAccountTransaction
object
that we can make use of to fill out the rest of the details. The subaccount
id will be in the form of: “{new_account_id}.{parent_account_id}”
sourcepub async fn deploy(&self, wasm: &[u8]) -> Result<Execution<Contract>>
pub async fn deploy(&self, wasm: &[u8]) -> Result<Execution<Contract>>
Deploy contract code or WASM bytes to the account, and return us a new
Contract
object that we can use to interact with the contract.
sourcepub fn batch(&self, contract_id: &AccountId) -> Transaction<'_>
pub fn batch(&self, contract_id: &AccountId) -> Transaction<'_>
Start a batch transaction, using the current account as the signer and
making calls into the contract provided by contract_id
. Returns a
Transaction
object that we can use to add Actions to the batched
transaction. Call transact
to send the batched transaction to the
network.
sourcepub async fn store_credentials(&self, save_dir: impl AsRef<Path>) -> Result<()>
pub async fn store_credentials(&self, save_dir: impl AsRef<Path>) -> Result<()>
Store the credentials of this account locally in the directory provided.
sourcepub fn secret_key(&self) -> &SecretKey
pub fn secret_key(&self) -> &SecretKey
Get the keys of this account. The public key can be retrieved from the secret key.
sourcepub fn set_secret_key(&mut self, sk: SecretKey)
pub fn set_secret_key(&mut self, sk: SecretKey)
Sets the SecretKey
of this account. Future transactions will be signed
using this newly provided key.