Near
Chapter 54: NEAR Protocol Nodes
Section titled “Chapter 54: NEAR Protocol Nodes”Overview
Section titled “Overview”NEAR Protocol is a developer-friendly, sharded blockchain platform that aims to solve scalability issues through its unique Nightshade technology. NEAR is designed to be highly accessible, with a focus on usability and low barriers to entry for both developers and end-users. The protocol uses a novel sharding approach called “Nightshade” that allows parallel processing of transactions across multiple shards.
54.1 NEAR Protocol Basics
Section titled “54.1 NEAR Protocol Basics”Key Technical Features
Section titled “Key Technical Features”| Feature | Value | Description |
|---|---|---|
| Consensus | Nightshade | Custom sharding mechanism with Doomslug consensus |
| Block Time | ~1 second | Fast block production |
| TPS | 100,000+ | Theoretical max across all shards |
| Finality | 1-2 blocks | Near-instant finality |
| Sharding | Dynamic | Adaptive number of shards |
| Token | NEAR | Native cryptocurrency |
Nightshade Architecture
Section titled “Nightshade Architecture”┌─────────────────────────────────────────────────────────────┐│ NEAR NIGHTSHADE │├─────────────────────────────────────────────────────────────┤│ ││ ┌─────────────────────────────────────────────────────┐ ││ │ Beacon Chain │ ││ │ (Phase 0 - Later) │ ││ └─────────────────────────────────────────────────────┘ ││ ││ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ┌─────┐ ││ │Shard│ │Shard│ │Shard│ │Shard│ │Shard│ ││ │ 0 │ │ 1 │ │ 2 │ │ 3 │ │ 4 │ ││ └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘ └──┬──┘ ││ │ │ │ │ │ ││ ▼ ▼ ▼ ▼ ▼ ││ ┌─────────────────────────────────────────────────────┐ ││ │ Chunk Producers (One per shard) │ ││ └─────────────────────────────────────────────────────┘ ││ ││ ┌─────────────────────────────────────────────────────┐ ││ │ Block Producers (Chunk Only) │ ││ └─────────────────────────────────────────────────────┘ ││ │└─────────────────────────────────────────────────────────────┘NEAR Token Economics
Section titled “NEAR Token Economics”| Parameter | Value |
|---|---|
| Total Supply | 1 billion NEAR |
| Inflation | 5% initially, decreasing over time |
| Staking Reward | ~4% APY for validators |
| Transaction Fees | Burned (deflationary) |
54.2 Node Types
Section titled “54.2 Node Types”Types of Nodes on NEAR
Section titled “Types of Nodes on NEAR”| Node Type | Description | Storage | Requirements |
|---|---|---|---|
| Validator | Participates in consensus | ~500GB+ | High (staked) |
| RPC Node | Provides API services | ~500GB+ | Medium-High |
| Archive Node | Full history storage | ~2TB+ | Very High |
| Chunk Producer | Produces shards | ~500GB+ | High |
| Light Client | Verifies proofs only | Minimal | Low |
54.3 Running a Node
Section titled “54.3 Running a Node”Prerequisites
Section titled “Prerequisites”# Hardware Requirements (Validator/RPC)- CPU: 16+ cores (AMD Zen 2+ or Intel Ice Lake+)- RAM: 32-64 GB- Storage: 1 TB NVMe SSD- Network: 100 Mbps minimum
# Install Dependenciessudo apt-get updatesudo apt-get install -y \ build-essential \ git \ curl \ wget \ tar \ cmake \ clang \ libssl-dev \ pkg-config \ libncurses5Method 1: Using nearup (Recommended)
Section titled “Method 1: Using nearup (Recommended)”# Install nearuppip3 install nearup
# Or use standalone binarywget https://github.com/near/nearcore/releases/download/2.1.0/nearcore-2.1.0-x86_64-unknown-linux-gnu.tar.gztar -xzf nearcore-2.1.0-x86_64-unknown-linux-gnu.tar.gz
# Initialize nearcorecd nearcore./target/release/neard init --chain-id mainnetMethod 2: Building from Source
Section titled “Method 2: Building from Source”# Install Rustcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | shsource ~/.cargo/env
# Install protobufsudo apt-get install -y protobuf-compiler
# Clone nearcoregit clone https://github.com/near/nearcore.gitcd nearcore
# Checkout stable versiongit checkout 2.1.0
# Buildcargo build --release -p neard
# This may take 30+ minutesMethod 3: Using Docker
Section titled “Method 3: Using Docker”# Pull official imagedocker pull nearprotocol/nearcore:v2.1.0
# Run RPC nodedocker run -d \ --name near-node \ -v ~/.near-data:/near/data \ -p 3030:3030 \ -p 2456:2456 \ nearprotocol/nearcore:v2.1.0 \ neard run
# Run with custom configdocker run -d \ --name near-node \ -v ~/.near-data:/near/data \ -p 3030:3030 \ -p 2456:2456 \ nearprotocol/nearcore:v2.1.0 \ neard run \ --chain-id mainnet \ --bootnodes ed25519:AA34680d569f37a0...54.4 Configuration
Section titled “54.4 Configuration”Basic Configuration
Section titled “Basic Configuration”{ "genesis_file": "genesis.json", "genesis_records_file": "genesis_records.json", "validator_key_file": "validator_key.json", "node_key_file": "node_key.json", "rpc": { "addr": "0.0.0.0:3030", "allowed_origins": ["*"], "cors": ["*"], "rate_limit": { "enabled": true, "requests_per_minute": 1000 } }, "network": { "addr": "0.0.0.0:2456", "boot_nodes": "ed25519:AA34680d569f37a0...", "max_num_peers": 40, "handshake_timeout": 20, "reconnect_delay": 5, "tsunami_mode": false }, "consensus": { "min_num_peers": 3, "epoch_length": 43200, "aggregate_signature": true }, "tracked_shards": [0, 1, 2, 3, 4, 5, 6, 7], "archive": false, "save_trie_changes": false}Environment Variables
Section titled “Environment Variables”export NEAR_ENV=mainnetexport RUST_LOG=infoexport RUST_BACKTRACE=1
# For high performanceexport NEARCLERK_DIR=/data/nearexport OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=http://localhost:4317Starting the Node
Section titled “Starting the Node”# Create systemd servicesudo nano /etc/systemd/system/near.service[Unit]Description=NEAR Protocol NodeAfter=network.target
[Service]Type=simpleUser=nearWorkingDirectory=/home/nearExecStart=/home/near/nearcore/target/release/neard run --chain-id mainnetRestart=alwaysRestartSec=10StandardOutput=append:/home/near/near.logStandardError=append:/home/near/near.log
[Install]WantedBy=multi-user.target# Enable and startsudo systemctl daemon-reloadsudo systemctl enable nearsudo systemctl start near
# Check statussudo systemctl status near
# View logsjournalctl -fu near54.5 RPC API
Section titled “54.5 RPC API”Default RPC Endpoints
Section titled “Default RPC Endpoints”| Endpoint | Port | Description |
|---|---|---|
| HTTP RPC | 3030 | Main RPC interface |
| WebSocket | 3030 | Subscription interface |
| Prometheus | 20001 | Metrics |
Public RPC Providers
Section titled “Public RPC Providers”# Mainnethttps://rpc.mainnet.near.orghttps://rpc.mainnet.near.wallet.geyser(apps.ctafarm.io/...)https://rpc.playnet.pikespeak(dao.pikespeak.io/...)
# Testnethttps://rpc.testnet.near.orgCommon RPC Methods
Section titled “Common RPC Methods”# Check node statuscurl -s https://rpc.mainnet.near.org/status | jq
# Get current blockcurl -s https://rpc.mainnet.near.org/block | jq
# Get block by heightcurl -s https://rpc.mainnet.near.org/block?block_id=100 | jq
# Get chunkcurl -s https://rpc.mainnet.near.org/chunk?chunk_id=123456 | jq
# Get transactioncurl -s https://rpc.mainnet.near.org/tx/<TX_HASH> | jq
# Get accountcurl -s https://rpc.mainnet.near.org/account/<ACCOUNT_ID> | jq
# Get account balancecurl -s https://rpc.mainnet.near.org/balance/<ACCOUNT_ID> | jq
# Get validatorscurl -s https://rpc.mainnet.near.org/validators | jq
# Get gas pricecurl -s https://rpc.mainnet.near.org/gas_price | jq
# Get protocol configcurl -s https://rpc.mainnet.near.org/experimental_protocol_config | jqRPC Call Examples
Section titled “RPC Call Examples”Query Account Balance
Section titled “Query Account Balance”# Using near-api-jsconst { connect, keyStores } = require('near-api-js');const config = require('./config');
async function getBalance() { const near = await connect({ ...config, keyStore: new keyStores.BrowserLocalStorageKeyStore() });
const account = await near.account('example.near'); const balance = await account.getAccountBalance(); console.log(balance);}View Transaction
Section titled “View Transaction”# Using CLInear view <account_id> <method_name> <args>
# Example: View lockup contractnear view lockupxxxxx.tnear get_ownerCall Contract
Section titled “Call Contract”# Change method (requires signing)near call <contract_id> <method_name> <args> --accountId <your_account>
# View method (read-only)near view <contract_id> <method_name> <args>54.6 Staking & Validators
Section titled “54.6 Staking & Validators”Becoming a Validator
Section titled “Becoming a Validator”NEAR uses a delegated Proof of Stake system. Validators are selected based on stake.
Requirements
Section titled “Requirements”| Requirement | Value |
|---|---|
| Minimum Stake | Determined by seat price (varies) |
| Hardware | See validator requirements |
| Uptime | >95% required |
Creating Validator Account
Section titled “Creating Validator Account”# Create accountnear create-account <account_id> --useFaucet
# Generate validator keynear generate-key <account_id>
# Copy to working directorycp ~/.near-credentials/testnet/<account_id>.json ~/.near/validator_key.jsonStake NEAR
Section titled “Stake NEAR”# Stake via CLInear stake <account_id> <staking_key> <amount>
# Example: Stake 1000 NEARnear stake my-validator --amount 1000Validator Commands
Section titled “Validator Commands”# Check validator infocurl -s https://rpc.mainnet.near.org/validators | jq '.current_validators[] | select(.account_id | contains("myvalidator"))'
# View staking pool infonear view <pool_account> get_accounts_delegated_balance_of {"account_id": "your_account"}
# Delegate to poolnear call <pool_account> deposit "{}" --accountId <your_account> --amount 10054.7 Development with NEAR
Section titled “54.7 Development with NEAR”Installing NEAR CLI
Section titled “Installing NEAR CLI”# Install near-clinpm install -g near-cli
# Or use nearupnearupCreating a NEAR Project
Section titled “Creating a NEAR Project”# Install create-near-appnpm install -g create-near-app
# Create new projectcreate-near-app my-near-dapp
cd my-near-dapp
# Install dependenciesnpm install
# Start local blockchainnpm run devWriting a Smart Contract
Section titled “Writing a Smart Contract”// lib.rs - Example Rust contractuse near_sdk::borsh::{self, BorshDeserialize, BorshSerialize};use near_sdk::{env, near_bindgen};
#[near_bindgen]#[derive(BorshDeserialize, BorshSerialize)]pub struct Counter { count: u32,}
impl Default for Counter { fn default() -> Self { Self { count: 0 } }}
#[near_bindgen]impl Counter { pub fn get_count(&self) -> u32 { self.count }
pub fn increment(&mut self) { self.count += 1; env::log(format!("Count: {}", self.count).as_bytes()); }
pub fn decrement(&mut self) { self.count -= 1; env::log(format!("Count: {}", self.count).as_bytes()); }
pub fn reset(&mut self) { self.count = 0; }}Deploying Contract
Section titled “Deploying Contract”# Build contractcd contractcargo build --target wasm32-unknown-unknown --release
# Deploynear deploy <contract_id> --wasmFile path/to/contract.wasm
# Initializenear call <contract_id> new '{}' --accountId <account_id>54.8 Monitoring
Section titled “54.8 Monitoring”Prometheus Metrics
Section titled “Prometheus Metrics”scrape_configs: - job_name: 'near' static_configs: - targets: ['localhost:20001']Key Metrics
Section titled “Key Metrics”| Metric | Description | Alert |
|---|---|---|
near_block_production_delay | Block production delay | > 1s |
near_chunk_production_delay | Chunk production delay | > 2s |
near_validator_uptime | Validator uptime | < 95% |
near_gas_used | Gas used per block | - |
near_transactions_count | Transactions per block | - |
Health Checks
Section titled “Health Checks”# Check node healthcurl -s http://localhost:3030/health | jq
# Check network infocurl -s http://localhost:3030/network_info | jq
# Check sync statuscurl -s http://localhost:3030/status | jq '.sync_info'54.9 Troubleshooting
Section titled “54.9 Troubleshooting”Common Issues
Section titled “Common Issues”1. Out of Disk Space
Section titled “1. Out of Disk Space”# Check disk usagedf -h
# Clear old data (if not validator)rm -rf ~/.near/data
# Restart to reinitializesystemctl restart near2. Validator Not Producing Blocks
Section titled “2. Validator Not Producing Blocks”# Check if you're in validator setcurl -s https://rpc.mainnet.near.org/validators | jq '.current_validators[] | select(.account_id == "your_account")'
# Check your stakenear view <pool_account> get_accounts_delegated_balance_of {"account_id": "your_account"}3. Syncing Issues
Section titled “3. Syncing Issues”# Clear database and resyncpkill -f neardrm -rf ~/.near/datasystemctl restart near
# Check logstail -f ~/.near/near.log4. Memory Issues
Section titled “4. Memory Issues”# Increase swapsudo fallocate -l 16G /swapfilesudo chmod 600 /swapfilesudo mkswap /swapfilesudo swapon /swapfile54.10 NEAR Testnet & Devnet
Section titled “54.10 NEAR Testnet & Devnet”Testnet
Section titled “Testnet”# Connect to testnetnearup testnet
# Or manuallycd nearcore./target/release/neard init --chain-id testnet./target release/neard run --chain-id testnetLocalnet (Development)
Section titled “Localnet (Development)”# Start local networkcd nearcorecargo build --release./target/release/neard init./target/release/neard run
# Or use multiple nodes./target/release/neard localnetSummary
Section titled “Summary”- NEAR Protocol uses Nightshade sharding for high scalability
- Block time is ~1 second with theoretical TPS of 100,000+
- Node setup requires building from source or using nearup tool
- RPC runs on port 3030, metrics on port 20001
- Validators must meet minimum stake requirements (seat price)
- NEAR CLI provides easy interaction with the network
- Smart contracts can be written in Rust or AssemblyScript
- Public RPC endpoints are available for testing without running a node
End of Guide
Section titled “End of Guide”This completes the comprehensive Blockchain Node Guide! You now have detailed knowledge of:
- Ethereum nodes (Geth, Erigon, Besu, Reth)
- Cosmos/Tendermint chains
- Solana nodes
- Avalanche, Polkadot, Bitcoin, and NEAR
- RPC APIs, security, monitoring, and troubleshooting
Practice the hands-on exercises and review the interview questions in Chapter 55 to prepare for your blockchain engineering interviews!
Last Updated: 2026-02-22