View Contract Call

Sends a view contract request to NEAR Protocol

Overview

The "View Contract Call" node allows you to perform a read-only (view) method call on a smart contract deployed on the NEAR Protocol blockchain. This is useful for retrieving data from NEAR smart contracts without making any state changes or requiring transaction fees. Common scenarios include querying account balances, fetching stored values, or reading contract metadata.

Practical examples:

  • Retrieve a user's profile information stored in a NEAR smart contract.
  • Query the current value of a counter or other on-chain variable.
  • Fetch configuration or status data from a decentralized application built on NEAR.

Properties

Name Type Meaning
Network ID String The NEAR network to connect to (e.g., "mainnet" or "testnet").
Contract Account ID String The account ID of the NEAR smart contract you want to interact with (e.g., "example.near").
Method Name String The name of the view method to call on the contract (e.g., "get_value_by_key").
Arguments JSON String A JSON string representing the arguments to pass to the contract method (e.g., {"key": "value"}).

Output

The node outputs an array of items, each containing a json field with the following structure:

{
  "result": <Result of the contract's view method>
}
  • The result field contains the data returned by the specified view method of the NEAR contract. Its structure depends on the contract and method called.

If an error occurs and "Continue On Fail" is enabled, the output item will also include an error field describing the issue.

Dependencies

  • External Services: Requires access to the NEAR blockchain via public RPC endpoints for either mainnet or testnet.
  • npm Packages: Uses near-api-js for blockchain interaction.
  • n8n Configuration: No special environment variables or API keys are required for view calls, as they do not require authentication.

Troubleshooting

Common Issues:

  • Invalid Network ID: If you provide an unsupported network ID, the node will fail to connect.
  • Malformed Arguments JSON: If the "Arguments JSON" property is not valid JSON, parsing will fail.
  • Incorrect Contract Account ID or Method Name: If the contract or method does not exist, the node will throw an error.

Error Messages:

  • "Unexpected token ... in JSON at position ...": Indicates invalid JSON in the "Arguments JSON" field. Double-check your input.
  • "Method not found" or similar: The specified method does not exist on the contract. Verify the method name.
  • "Contract does not exist": The contract account ID is incorrect or the contract is not deployed.

How to resolve:

  • Ensure all input fields are filled correctly and match the target contract's requirements.
  • Validate your JSON before submitting.
  • Check that the contract and method exist on the selected network.

Links and References

Discussion