Overview
ThecallContractReadFunction method allows you to call view/read-only functions on NEAR smart contracts. These functions don’t modify state and don’t require transaction fees.
Method Signature
packages/near-api-ts/universal/src/client/methods/contract/callContractReadFunction/callContractReadFunction.ts:31
Parameters
The account ID of the contract to call
The name of the contract function to call
Arguments to pass to the contract function. Must be JSON-serializable unless using a custom serializer.
Block reference to query the contract state at a specific point in time. Can be:
{ blockId: string }- Block hash{ blockHeight: number }- Block height{ finality: 'optimistic' | 'final' }- Finality level (default: ‘final’)
Response
Indicates if the call was successful
Hash of the block at which the function was executed
Height of the block at which the function was executed
Deserialized result of the contract function call
Raw bytes of the result as returned by the contract
Array of log messages emitted during function execution
Error object if the call failed. Possible error kinds:
Client.CallContractReadFunction.Args.InvalidSchema- Invalid argumentsClient.CallContractReadFunction.SerializeArgs.Failed- Argument serialization failedClient.CallContractReadFunction.Rpc.Execution.Failed- Contract execution failedClient.CallContractReadFunction.ResultDeserialization.JsonParseFailed- Result parsing failed- And more (see type definitions)
Serialization & Deserialization
Default JSON Serialization
By default, arguments are serialized to JSON and results are deserialized from JSON:Custom Serialization
You can provide custom serialization functions for non-JSON data:packages/near-api-ts/universal/src/client/methods/contract/callContractReadFunction/serializeFunctionArgs.ts:17-41
Examples
Basic Usage
Query at Specific Block
With Custom Deserializer
With Abort Signal
Error Handling
The method returns aResult type that can be either success or error:
Notes
- Read functions don’t modify blockchain state
- No transaction fees are required
- Execution happens on the RPC node, not on-chain
- Results are deterministic for a given block height
- Use
withStateAtto query historical state
Related Methods
- Get Contract State - Get raw contract storage state
- Send Signed Transaction - Execute state-changing transactions