Anatomy of a Transaction
A transaction is a request from a user to the network to perform a set of actions. To create a transaction, the user must specify the following fields:
Signer
: the account that signs the transactionActions
: the set of actions to be performed (see below)Receiver
: the account on which to perform the actions
In addition, a transaction has the following fields to ensure its integrity and validity:
PublicKey
: the public key used to sign the transaction (so the network can verify the signature)Nonce
: a number that is incremented for each transaction sent by theSigner
BlockHash
: the hash of a recent block, to limit the time-validity of the transaction
Users create transactions and sign them with their private keys. Then, the transaction and its signature are broadcast together to the network, where they are validated and processed.
Each transaction has exactly one Signer
and Receiver
, but can have multiple Actions
Actions​
Each transaction can have one or multiple Actions
, which are the actual operations to be performed on the Receiver
account. There are 9 types of actions that can be performed:
FunctionCall
: to invoke a function on a contract (optionally attaching NEAR to the call)Transfer
: to transfer tokens to another accountDeployContract
: to deploy a contract in the accountCreateAccount
: to create a new sub-account (e.g.ana.near
can createsub.ana.near
)DeleteAccount
: to delete the account (transferring the remaining balance to a beneficiary)AddKey
: to add a new key to the account (eitherFullAccess
orFunctionCall
access)DeleteKey
: to delete an existing key from the accountDelegateActions
: to create a meta-transactionStake
: special action to express interest in becoming a network validator
For example, bob.near
can bundle the following actions in a single transaction:
- Create the account
contract.bob.near
- Transfer 5 NEAR to
contract.bob.near
- Deploy a contract in
contract.bob.near
- Call the function
init
incontract.bob.near
The Actions
are executed in the order they are specified in the transaction. If any of the actions fails, the transaction is discarded and none of the actions take effect.
Notice that all actions are performed on the same account. It is not possible to perform actions on multiple accounts in a single transaction, because transactions can have only one receiver