Quick Reference
| Method | Endpoint | Purpose |
|---|---|---|
view_account | Query account info | Get basic account information |
view_account_changes | Track account changes | Monitor account state changes |
view_code | Query contract code | Get deployed contract WASM code |
view_state | Query contract state | Get contract storage data |
data_changes | Track state changes | Monitor contract state changes |
contract_code_changes | Track code changes | Monitor contract deployments |
call_function | Call view functions | Execute read-only contract methods |
View account
Returns basic account information.queryview_accountBlock finality. See finality param.
Block height or hash. See block_id param.
Example:
"example.testnet"View account changes
Returns account changes from transactions in a given account.changesaccount_changesExample:
["example.testnet"]Block finality. See finality param.
Block height or hash. See block_id param.
View contract code
Returns the contract code (Wasm binary) deployed to the account. Please note that the returned code will be encoded in base64.queryview_codeBlock finality. See finality param.
Block height or hash. See block_id param.
Example:
"example.testnet"View contract state
Returns the state (key value pairs) of a contract based on the key prefix (base64 encoded). Pass an empty string forprefix_base64 if you would like to return the entire state. Please note that the returned state will be base64 encoded as well.
queryview_stateBlock finality. See finality param.
Block height or hash. See block_id param.
Example:
"example.testnet"Base64 encoded key prefix (empty string "" returns all state)
View contract state changes
Returns the state change details of a contract based on the key prefix (encoded to base64). Pass an empty string for this param if you would like to return all state changes.changesdata_changesExample:
["example.testnet"]Base64 encoded key value
Block finality. See finality param.
Block height or hash. See block_id param.
View contract code changes
Returns code changes made when deploying a contract. Change is returned is a base64 encoded WASM file.changescontract_code_changesExample:
["example.testnet"]Block finality. See finality param.
Block height or hash. See block_id param.
Call a contract function
Allows you to call a contract method as a view function.querycall_functionBlock finality. See finality param.
Block height or hash. See block_id param.
Example:
"example.testnet"The name of the contract method to call
Method arguments base64 encoded
The
result field contains an array of bytes representing ASCII code. For example, [34, 71, ..., 33, 34] is the ASCII code for "Greetings from NEAR Protocol!". The near-sdk-rs and near-sdk-js return JSON-serialized results.Error Handling
Common Error Types
| Error Code | Description | Solution |
|---|---|---|
UnknownAccount | Account does not exist | Check account ID spelling and existence |
InvalidAccount | Invalid account format | Use valid account ID format (e.g., account.near) |
UnknownBlock | Block not found | Use a valid block hash or height |
GarbageCollectedBlock | Block too old | Use archival node or more recent block |
TooManyInputs | Too many accounts in request | Reduce number of accounts per request |
NoContractCode | Account has no contract deployed | Verify the account has a deployed contract |
MethodNotFound | Contract method does not exist | Check method name and contract ABI |
InvalidArgs | Invalid method arguments | Verify args format and encoding |
Best Practices
- Use specific queries: Query only the data you need instead of broad state queries
- Validate inputs: Always validate method arguments before contract calls
- Cache contract code: Contract code rarely changes, consider caching
- Handle errors gracefully: Implement proper error handling for all API calls