NEAR Account Model

This is my note for a sharing about the NEAR chain account model. Please visit the official website for the details.

NEAR Account Model

Account ID/Address

There are 2 methods to identify an NEAR account, and you can only pick one between:

Implicit Account

Implicit account is just a 64 character long identifier.

Named Account

Named account works like the DNS, with some restrictions like the top level names less than 32 characters are reserved by the foundation, but you can still create your own top level name if it is more than 32 characters... You can also create any sub accounts from your account name. e.g. demo852.testnet -> sub1.demo852.testnet , sub2.demo852.testnet

Access Key

Many chains use the public key for the account address and the private key for the update, but NEAR dose it another way. When you create an new account you will also need to assign a public key to it, or the account will be locked. The good thing is you can have multiple keys to access an account, and you can manage the keys anytime.

There are two types of key:

Full Access Key

The key has full access of the account, just like other chains.

FunctionCall Key

FuncationCall key is a key with some restrictions like receiver_id, method_name (of the smart contract) and allowance (the gas fee limit). With FunctionCall key you can limit the risk to certain resources only if the key were stolen.

State

An account needs some storage to hold the information for the account. A part of the native token will be locked for the storage they used.

Account's Metadata

The basic information about the account like token balance, block hash, storage used.s

Contract's State

The contracts deployed to an account also take some space, which include the contract binary itself and the data stored by the contract for later use.

Account Operation

You will need these tools:

Near account model https://docs.near.org/concepts/basics/accounts/model
Testnet explorer https://explorer.testnet.near.org/
Faucet https://near-faucet.io/
near-cli https://github.com/near/near-cli

Create Account

Visit https://wallet.testnet.near.org/create to create an named account. Please remember to save your seed phrase.

Some tokens will be airdropped to your new account. Let's check the balance

Some tokens will be airdropped to your new account. Let's check the balance:

Now we need to import the seed phrase into the near-cli credential:

Then we can create a sub-account sub1.demo852.testnet with some tokens as initial balance:

The default credential file location is ~/.near-credentials

Send token

Summary

Account Identifier

  • can only choose one at account creation

Implicit Account

  • 64 char string

Named Account

  • DNS-like style
  • can create sub account
  • top level names < 32 characters are reserved

Access Control

  • multiple keys
  • can be added/removed

FullAccess Key

  • can do any thing

FunctionCall Key

  • restricted
  • contract_id
  • method_names

State

  • accounts have to pay for the storage used

Account's Metadata

  • token balance
  • block hash
  • storage used

Contract's State

  • contract binary
  • contract data (state)