Actions such as transferring NEAR, or calling other contracts.
An important property of Actions is that they can be batched together when acting on the same contract. Batched actions act as a unit: they execute in the same receipt, and if any fails, then they all get reverted.
Actions can be batched only when they act on the same contract. You can batch calling two methods on a contract,
but cannot call two methods on different contracts.Transfer NEAR Ⓝ
You can send$NEAR from your contract to any other account on the network. The gas cost of a transfer is set by the protocol’s runtime parameters, and it depends on the type of the receiver:
For every receiver except a named account, the cost includes the fee for creating the account, even if the account already exists. For a 64-hex implicit account, it also includes the fee for adding its full access key.
Function Call
Your smart contract can call methods in another contract. In the snippet below we call a method in a deployed Hello NEAR contract, and check if everything went right in the callback.Create a Sub Account
Your contract can create direct sub accounts of itself, for example,user.near can create sub.user.near.
Accounts do NOT have control over their sub-accounts, since they have their own keys.
Sub-accounts are simply useful for organizing your accounts (e.g. dao.project.near, token.project.near).
Creating an account costs a fixed
0.007Ⓝ, or about 0.00707Ⓝ in total once the send fees are added. That 0.007Ⓝ already includes the gas burned while creating the account, and it is taken out of the transaction’s gas refund, not out of the deposit you attach for storage.Creating .testnet / .near Accounts
Accounts can only create immediate sub-accounts of themselves.
If your contract wants to create a .mainnet or .testnet account, then it needs to call
the create_account method of near or testnet root contracts.
Create deterministic accounts
Your contract can create a deterministic account whose0s address is derived from its initial code and storage. Use the DeterministicStateInit action instead of CreateAccount; the protocol validates that the supplied account ID matches the hash of the provided initial state.
Smart contracts can build this action using the following host functions:
promise_batch_action_state_init— creates aDeterministicStateInitaction referencing a code hashpromise_batch_action_state_init_by_account_id— creates the action referencing an existing account’s codeset_state_init_data_entry— adds a key-value entry to the account’s initial storagecurrent_contract_code— returns the calling contract’s own code hash, useful for deploying clones
Create universal accounts
Your contract can create a universal account whose0u address is derived from its initial code, storage, and access keys. Use the UniversalStateInit action instead of CreateAccount.
Smart contracts can build this action using two host functions:
universal_state_init_to_account_id— derives the0uaccount ID from a state init and reports whether the bytes are valid, with no side effectspromise_batch_action_universal_state_init— appends aUniversalStateInitaction to a promise, with an attached deposit that tops up the account’s storage stake if needed. Any unused amount is refunded; use a separateTransferaction to add to the account’s balance.
Deploy a Contract
When creating an account you can also batch the action of deploying a contract to it. Note that for this, you will need to pre-load the byte-code you want to deploy in your contract.Add Keys
When you use actions to create a new account, the created account does not have any access keys, meaning that it cannot sign transactions (e.g. to update its contract, delete itself, transfer money). There are two options for adding keys to the account:add_access_key: adds a key that can only call specific methods on a specified contract.add_full_access_key: adds a key that has full access to the account.
The
public_key can use any of NEAR’s signature schemes — ed25519, secp256k1, or the post-quantum ml-dsa-65. Adding an ml-dsa-65 key needs no code changes: pass an ml-dsa-65:... key exactly like the examples above.Delete Account
There are two scenarios in which you can use thedelete_account action:
- As the last action in a chain of batched actions.
- To make your smart contract delete its own account.