Actions

There are a several action types in Near:


#![allow(unused_variables)]
fn main() {
pub enum Action {
    CreateAccount(CreateAccountAction),
    DeployContract(DeployContractAction),
    FunctionCall(FunctionCallAction),
    Transfer(TransferAction),
    Stake(StakeAction),
    AddKey(AddKeyAction),
    DeleteKey(DeleteKeyAction),
    DeleteAccount(DeleteAccountAction),
}
}

Each transaction consists a list of actions to be performed on the receiver_id side. Sometimes the singer_id equals to receiver_id. There is a set of action types when signer_id and receiver_id are required to be equal. Actions requires arguments and use data from the Transaction itself.

// TODO: how to introduce the concept of sender_id

CreateAccountAction

Requirements:

  • unique tx.receiver_id
  • public_key to be AccessKeyPermission::FullAccess for the singer_id

CreateAccountAction doesn't take any additional arguments, it uses receiver_id from Transaction. receiver_id is an ID for an account to be created. Account ID should be valid and unique throughout the system.

Outcome:

  • creates an account with id = receiver_id
  • sets Account storage_usage to account_cost (genesis config)
  • sets Account storage_paid_at to the current block height

NOTE: for the all subsequent actions in the transaction the signer_id becomes receiver_id until DeleteAccountAction. It allows to execute actions on behalf of the just created account.


#![allow(unused_variables)]
fn main() {
pub struct CreateAccountAction {}
}

DeployContractAction

Requirements:

  • tx.signer_id to be equal to receiver_id
  • tx.public_key to be AccessKeyPermission::FullAccess for the singer_id

Outcome:

  • sets a code for account

#![allow(unused_variables)]
fn main() {
pub struct DeployContractAction {
    pub code: Vec<u8>, // a valid WebAssembly code
}
}

FunctionCallAction

Requirements:

  • tx.public_key to be AccessKeyPermission::FullAccess or AccessKeyPermission::FunctionCall

Calls a method of a particular contract. See details.


#![allow(unused_variables)]
fn main() {
pub struct FunctionCallAction {
    /// Name of exported Wasm function
    pub method_name: String,
    /// Serialized arguments
    pub args: Vec<u8>,
    /// Prepaid gas (gas_limit) for a function call
    pub gas: Gas,
    /// Amount of tokens to transfer to a receiver_id
    pub deposit: Balance,
}
}

TransferAction

Requirements:

  • tx.public_key to be AccessKeyPermission::FullAccess for the singer_id

Outcome:

  • transfers amount specified in deposit from tx.signer to a tx.receiver_id account

#![allow(unused_variables)]
fn main() {
pub struct TransferAction {
    /// Amount of tokens to transfer to a receiver_id
    pub deposit: Balance,
}
}

StakeAction

Requirements:

  • tx.signer_id to be equal to receiver_id
  • tx.public_key to be AccessKeyPermission::FullAccess for the singer_id

#![allow(unused_variables)]
fn main() {
pub struct StakeAction {
    // Amount of tokens to stake
    pub stake: Balance,
    // This public key is a public key of the validator node
    pub public_key: PublicKey,
}
}

Outcome:

// TODO: cover staking

AddKeyAction

Requirements:

  • tx.signer_id to be equal to receiver_id
  • tx.public_key to be AccessKeyPermission::FullAccess for the singer_id

Associates an AccessKey with a public_key provided.


#![allow(unused_variables)]
fn main() {
pub struct AddKeyAction {
    pub public_key: PublicKey,
    pub access_key: AccessKey,
}
}

DeleteKeyAction

Requirements:

  • tx.signer_id to be equal to receiver_id
  • tx.public_key to be AccessKeyPermission::FullAccess for the singer_id

#![allow(unused_variables)]
fn main() {
pub struct DeleteKeyAction {
    pub public_key: PublicKey,
}
}

DeleteAccountAction

Requirements:

  • tx.signer_id to be equal to receiver_id
  • tx.public_key to be AccessKeyPermission::FullAccess for the singer_id
  • tx.account shouldn't have any locked balance

#![allow(unused_variables)]
fn main() {
pub struct DeleteAccountAction {
    /// The remaining account balance will be transferred to the AccountId below
    pub beneficiary_id: AccountId,
}
}