Skip to main content

Action

Enum Action 

Source
pub enum Action {
Show 14 variants CreateAccount(CreateAccountAction), DeployContract(DeployContractAction), FunctionCall(FunctionCallAction), Transfer(TransferAction), Stake(StakeAction), AddKey(AddKeyAction), DeleteKey(DeleteKeyAction), DeleteAccount(DeleteAccountAction), Delegate(Box<SignedDelegateAction>), DeployGlobalContract(DeployGlobalContractAction), UseGlobalContract(UseGlobalContractAction), DeterministicStateInit(DeterministicStateInitAction), TransferToGasKey(TransferToGasKeyAction), WithdrawFromGasKey(WithdrawFromGasKeyAction),
}
Expand description

A transaction action.

IMPORTANT: Variant order matters for Borsh serialization! The discriminants match NEAR Protocol specification: 0 = CreateAccount, 1 = DeployContract, 2 = FunctionCall, 3 = Transfer, 4 = Stake, 5 = AddKey, 6 = DeleteKey, 7 = DeleteAccount, 8 = Delegate, 9 = DeployGlobalContract, 10 = UseGlobalContract, 11 = DeterministicStateInit, 12 = TransferToGasKey, 13 = WithdrawFromGasKey

Variants§

§

CreateAccount(CreateAccountAction)

Create a new account. (discriminant = 0)

§

DeployContract(DeployContractAction)

Deploy contract code. (discriminant = 1)

§

FunctionCall(FunctionCallAction)

Call a contract function. (discriminant = 2)

§

Transfer(TransferAction)

Transfer NEAR tokens. (discriminant = 3)

§

Stake(StakeAction)

Stake NEAR for validation. (discriminant = 4)

§

AddKey(AddKeyAction)

Add an access key. (discriminant = 5)

§

DeleteKey(DeleteKeyAction)

Delete an access key. (discriminant = 6)

§

DeleteAccount(DeleteAccountAction)

Delete the account. (discriminant = 7)

§

Delegate(Box<SignedDelegateAction>)

Delegate action (for meta-transactions). (discriminant = 8)

§

DeployGlobalContract(DeployGlobalContractAction)

Publish a contract to global registry. (discriminant = 9)

§

UseGlobalContract(UseGlobalContractAction)

Deploy from a previously published global contract. (discriminant = 10)

§

DeterministicStateInit(DeterministicStateInitAction)

NEP-616: Deploy with deterministically derived account ID. (discriminant = 11)

§

TransferToGasKey(TransferToGasKeyAction)

Transfer NEAR to a gas key. (discriminant = 12)

§

WithdrawFromGasKey(WithdrawFromGasKeyAction)

Withdraw NEAR from a gas key. (discriminant = 13)

Implementations§

Source§

impl Action

Source

pub fn create_account() -> Self

Create a CreateAccount action.

Source

pub fn deploy_contract(code: Vec<u8>) -> Self

Create a DeployContract action.

Source

pub fn function_call( method_name: impl Into<String>, args: Vec<u8>, gas: Gas, deposit: NearToken, ) -> Self

Create a FunctionCall action.

Source

pub fn transfer(deposit: NearToken) -> Self

Create a Transfer action.

Source

pub fn stake(stake: NearToken, public_key: PublicKey) -> Self

Create a Stake action.

Source

pub fn add_full_access_key(public_key: PublicKey) -> Self

Create an AddKey action for full access.

Source

pub fn add_function_call_key( public_key: PublicKey, receiver_id: AccountId, method_names: Vec<String>, allowance: Option<NearToken>, ) -> Self

Create an AddKey action for function call access.

Source

pub fn delete_key(public_key: PublicKey) -> Self

Create a DeleteKey action.

Source

pub fn delete_account(beneficiary_id: AccountId) -> Self

Create a DeleteAccount action.

Source

pub fn delegate(signed_delegate: SignedDelegateAction) -> Self

Create a Delegate action from a signed delegate action.

Source

pub fn publish_contract(code: Vec<u8>, by_hash: bool) -> Self

Publish a contract to the global registry.

Global contracts are deployed once and can be referenced by multiple accounts, saving storage costs.

§Arguments
  • code - The WASM code to publish
  • by_hash - If true, contract is identified by its code hash (immutable). If false (default), contract is identified by the signer’s account ID (updatable).
§Example
// Publish updatable contract (identified by your account)
near.transaction("alice.near")
    .publish_contract(wasm_code, false)
    .send()
    .await?;

// Publish immutable contract (identified by its hash)
near.transaction("alice.near")
    .publish_contract(wasm_code, true)
    .send()
    .await?;
Source

pub fn deploy_from_hash(code_hash: CryptoHash) -> Self

Deploy a contract from the global registry by code hash.

References a previously published immutable contract.

Source

pub fn deploy_from_account(account_id: AccountId) -> Self

Deploy a contract from the global registry by account ID.

References a contract published by the given account. The contract can be updated by the publisher.

Source

pub fn state_init( state_init: DeterministicAccountStateInit, deposit: NearToken, ) -> Self

Create a NEP-616 deterministic state init action.

The account ID is derived from the state init data: "0s" + hex(keccak256(borsh(state_init))[12..32])

Source

pub fn state_init_by_hash( code_hash: CryptoHash, data: BTreeMap<Vec<u8>, Vec<u8>>, deposit: NearToken, ) -> Self

Create a NEP-616 deterministic state init action with code hash reference.

Source

pub fn state_init_by_account( account_id: AccountId, data: BTreeMap<Vec<u8>, Vec<u8>>, deposit: NearToken, ) -> Self

Create a NEP-616 deterministic state init action with account reference.

Source

pub fn transfer_to_gas_key(public_key: PublicKey, deposit: NearToken) -> Self

Transfer NEAR to a gas key.

Source

pub fn withdraw_from_gas_key(public_key: PublicKey, amount: NearToken) -> Self

Withdraw NEAR from a gas key.

Trait Implementations§

Source§

impl BorshDeserialize for Action

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for Action

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl Clone for Action

Source§

fn clone(&self) -> Action

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Action

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl EnumExt for Action

Source§

fn deserialize_variant<__R: Read>( reader: &mut __R, variant_tag: u8, ) -> Result<Self, Error>

Deserialises given variant of an enum from the reader. Read more
Source§

impl From<NonDelegateAction> for Action

Source§

fn from(action: NonDelegateAction) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Action

Source§

fn eq(&self, other: &Action) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Action> for NonDelegateAction

Source§

type Error = ()

The type returned in the event of a conversion error.
Source§

fn try_from(action: Action) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Action

Source§

impl StructuralPartialEq for Action

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more