Struct near_workspaces::Contract
source · pub struct Contract { /* private fields */ }Expand description
Contract is directly associated to a contract 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
sourceimpl Contract
impl Contract
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 as_account(&self) -> &Account
pub fn as_account(&self) -> &Account
sourcepub fn as_account_mut(&mut self) -> &mut Account
pub fn as_account_mut(&mut self) -> &mut Account
sourcepub fn call<'a>(&self, function: &'a str) -> CallTransaction<'_, 'a>
pub fn call<'a>(&self, function: &'a str) -> CallTransaction<'_, 'a>
Call the current contract’s function using the contract’s own account
secret key to do the signing. Returns a CallTransaction object that
we will make use to populate the rest of the call details.
If we want to make use of the contract’s secret key as a signer to call
into another contract, use contract.as_account().call instead.
sourcepub async fn view(
&self,
function: &str,
args: Vec<u8>
) -> Result<ViewResultDetails>
pub async fn view(
&self,
function: &str,
args: Vec<u8>
) -> Result<ViewResultDetails>
Call a view function into the current contract. Returns a result which can be deserialized into borsh or JSON.
sourcepub async fn view_state(
&self,
prefix: Option<&[u8]>
) -> Result<HashMap<Vec<u8>, Vec<u8>>>
pub async fn view_state(
&self,
prefix: Option<&[u8]>
) -> Result<HashMap<Vec<u8>, Vec<u8>>>
View a contract’s state map of key value pairs.
sourcepub async fn view_account(&self) -> Result<AccountDetails>
pub async fn view_account(&self) -> Result<AccountDetails>
Views the current contract’s details such as balance and storage usage.
sourcepub async fn delete_contract(
self,
beneficiary_id: &AccountId
) -> Result<ExecutionFinalResult>
pub async fn delete_contract(
self,
beneficiary_id: &AccountId
) -> Result<ExecutionFinalResult>
Deletes the current contract, and returns the execution details of this transaction. The beneciary will receive the funds of the account deleted
sourcepub fn batch(&self) -> Transaction<'_>
pub fn batch(&self) -> Transaction<'_>
Start a batch transaction, using the current contract’s secret key as the
signer, making calls into itself. 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.