1. Calling View Methods
Usenear.view() to query smart contracts. This connects to the RPC and fetches the state directly.
Basic Usage
Arguments are automatically JSON-serialized for you.Typed Return Values
By default,near.view returns any. You can pass a generic type to get a strongly-typed response.
Pro Tip: For even better type safety (including arguments), check out Type-Safe Contracts.
2. Reading Historical Data (Time Travel)
By default, you read from the “Optimistic” head of the chain (the absolute latest state). Sometimes you need to read from a specific point in the past, or ensure you are reading fully finalized data. Most read methods accept an options object as the last argument.3. Checking Balances
Available Balance
Usenear.getBalance() to get the available (spendable) balance. This accounts for storage costs and staked tokens.
Full Account State
Usenear.getAccount() when you need all balance details:
Why is available different from balance?NEAR accounts must reserve tokens to pay for on-chain storage. However, staked tokens count towards this requirement. So:
- If staked ≥ storage cost → all liquid balance is available
- If staked < storage cost → some liquid balance is reserved
getBalance() returns available, not balance — it’s what you can actually spend.4. Listing Access Keys
Usenear.getAccessKeys() to list all access keys for an account.
near.getAccessKey():
5. Batching Requests
If you need to make multiple read calls at once, usenear.batch(). This runs them in parallel (like Promise.all) but preserves the types of the results in the returned tuple.
6. Network Status
Usenear.getStatus() to check the health of the node and the latest block height.