On NEAR, an account is not a key pair. It's a named on-chain object, such as alice.near, or an implicit account derived from a public key, and it can hold many access keys. Each key is either FullAccess (can do anything, including transfers and deploying code) or FunctionCall (can only call methods on one named contract, can't attach NEAR, and can have a gas allowance). NEAR scales by Nightshade sharding: accounts are split across shards, every block carries one chunk per shard, and calls between accounts on different shards travel as receipts that execute asynchronously in later blocks. Since Nightshade 2.0 in 2024, chunks are checked by stateless validators that verify a state witness instead of storing the shard's state.
What kinds of NEAR accounts are there?
| Type | Example | How it's created | Notes |
|---|---|---|---|
| Named | alice.near, app.alice.near | By a parent account (or the near registrar contract for top-level names) | Only alice.near can create *.alice.near |
| Implicit | 64 hex characters | Send NEAR to it | The ID is the hex of an ed25519 public key |
| Ethereum-style | 0x plus 40 hex characters | First use from an Ethereum wallet | Derived from a secp256k1 key like an Ethereum address, and comes with a wallet contract that verifies Ethereum signatures (NEP-518) |
Account IDs are 2 to 64 characters of lowercase letters, digits, - and _, separated by dots. Sub-account names don't grant any power: app.alice.near is a separate account with its own keys, and alice.near has no control over it after creating it. NEAR's docs have also added newer account types derived from a contract's code and initial state, so expect the list above to grow.
Every account holds a balance (in yoctoNEAR, 10^24 per NEAR), optionally a single contract, and its storage. Storage isn't paid for once; it's staked: an account must keep 1 NEAR locked for every 100 KB it uses (10^19 yoctoNEAR per byte). Deleting data releases the stake. That's why many contracts, including fungible tokens, make users call storage_deposit before they can hold a balance.
This model is closer to Ethereum's account model than to Bitcoin's coins (the UTXO vs account model comparison explains the difference), but with naming and key management built into the protocol.
How do access keys work?
| FullAccess key | FunctionCall key | |
|---|---|---|
| Transfer NEAR | Yes | No |
| Deploy contract, add or delete keys, delete account | Yes | No |
| Call contract methods | Any contract | Only receiver_id, optionally limited to listed method_names |
| Attach a deposit | Yes | No (deposit must be zero) |
| Spending limit | None | Optional allowance covering gas fees only |
Each key also has its own nonce. A transaction's nonce must be higher than the last one used with that key, and a newly added key starts with a nonce based on the current block height, so a deleted and re-added key can't replay old transactions. Because nonces are per key, a backend can send transactions in parallel by giving one account several keys, which avoids the nonce collisions that plague single-key senders on Ethereum.
FunctionCall keys are how NEAR apps avoid a wallet pop-up on every action. When you log in, the wallet adds a FunctionCall key for the app's contract to your account and gives the private key to the app. The app can then sign game moves or posts on your behalf, but it can't move your NEAR, call other contracts or exceed its gas allowance. This is the kind of session-key behaviour Ethereum gets through smart accounts and ERC-4337 or EIP-7702 delegation; on NEAR it's part of the protocol.
With near-cli-rs (check near account add-key --help for your version):
# Add a key that can only call two methods on app.testnet, with 0.25 NEAR of gas allowance
near account add-key alice.testnet \
grant-function-call-access \
--allowance '0.25 NEAR' \
--contract-account-id app.testnet \
--function-names 'set_status, add_message' \
autogenerate-new-keypair save-to-keychain \
network-config testnet sign-with-keychain send
# List the keys on an account
near account list-keys alice.testnet network-config testnet now
Or straight from JSON-RPC, against any NEAR RPC provider:
curl -s "$NEAR_RPC_URL" -H 'Content-Type: application/json' -d '{
"jsonrpc": "2.0", "id": "1", "method": "query",
"params": {"request_type": "view_access_key_list", "finality": "final", "account_id": "alice.near"}
}'
Protecting sensitive methods
Because FunctionCall keys can't attach a deposit, contracts use a 1 yoctoNEAR deposit as proof that a full-access key signed the call, which normally means the user confirmed it in their wallet. Fungible token ft_transfer uses this pattern. In a contract written with near-sdk 5:
use near_sdk::{env, near, require, AccountId, NearToken, PanicOnDefault, Promise};
#[near(contract_state)]
#[derive(PanicOnDefault)]
pub struct Treasury {
owner: AccountId,
}
#[near]
impl Treasury {
#[init]
pub fn new(owner: AccountId) -> Self {
Self { owner }
}
// A FunctionCall key can't attach 1 yoctoNEAR, so an app's session key
// can never call this, even if it was granted access to this contract.
#[payable]
pub fn send(&mut self, to: AccountId, amount: NearToken) -> Promise {
near_sdk::assert_one_yocto();
require!(env::predecessor_account_id() == self.owner, "only owner");
Promise::new(to).transfer(amount)
}
}
Use env::predecessor_account_id() (the immediate caller) for authorisation, not env::signer_account_id() (the account that signed the original transaction). A malicious contract can be called by a user and then call yours, and the signer would still be the user.
How does Nightshade sharding work?
NEAR keeps one chain of blocks, but the state is partitioned. The shard layout assigns ranges of account IDs to shards, so every account, with its contract and storage, lives on exactly one shard. Each block contains one chunk per shard: the transactions and receipts processed on that shard in that block. Chunk producers build chunks only for the shards they track, and block producers combine chunk headers into the block.
Nightshade 2.0, launched on mainnet in August 2024, added stateless validation. The chunk producer, which holds the shard's state, publishes a state witness: the state the chunk touched plus Merkle proofs against the previous state root, the same idea as the Merkle proofs used by light clients. Chunk validators re-execute the chunk from the witness without storing the shard, and their endorsements are required for the chunk to be included. This keeps most validators' hardware requirements low while letting the network add shards. It's a different design from Polkadot's parachains with shared security, where each shard is its own chain with its own runtime; NEAR's shards all run the same runtime and are invisible to users.
Mainnet ran with six shards at the launch of Nightshade 2.0 and grew to nine during 2025, the same year blocks were cut to about 600 milliseconds with finality around 1.2 seconds. The protocol supports resharding, so treat any shard count as a snapshot and read the current layout from the RPC method EXPERIMENTAL_protocol_config.
Why are cross-contract calls asynchronous?
A transaction is first converted into a receipt on the signer's shard, where gas is prepaid. The receipt is then routed to the receiver's shard and executed, usually in the next block. If that contract calls another contract, it creates a new receipt, which executes later still. Results come back through callback receipts.
This has consequences that surprise Ethereum developers:
- No cross-contract atomicity. If your contract updates its state and then calls a token contract that fails, your state change has already been committed. You must undo it in a callback.
- Callbacks must be protected. Mark them
#[private]so only your contract can call them, and handle the failed-promise case explicitly. - Calls take blocks, not microseconds. A chain of three calls and a callback spans several blocks. State can change between the call and the callback, so re-read anything you depend on.
- Gas is prepaid and refunded. Unused gas is returned to the signer. Of the gas burned by a contract call, 30% goes to the called contract's account as a rebate and the rest is burned.
Checklist
- Choose named accounts for users and contracts; implicit accounts work for exchanges and programmatic wallets.
- Give apps FunctionCall keys scoped to one contract and specific methods, with an allowance, and delete keys you no longer use.
- Require 1 yoctoNEAR (
assert_one_yocto) on any method that moves value or changes ownership. - Authorise with
predecessor_account_id, neversigner_account_id. - Budget storage staking at 1 NEAR per 100 KB and use
storage_depositfor per-user storage. - Write every cross-contract call with a
#[private]callback that handles failure and rolls back local state. - Use several keys per account for parallel transaction sending.
- Don't hard-code shard counts or block times; query protocol config from a dedicated RPC provider.
Get the weekly commit
New blockchain deep dives every week.