Skip to main content
Glama

contract_call_raw_function_as_read_only

Execute a read-only function call on a NEAR smart contract to retrieve data without modifying its state. Specify contract ID, method name, and arguments.

Instructions

Call a function of a contract as a read-only call. This is equivalent to saying we are calling a view method of the contract.

Input Schema

NameRequiredDescriptionDefault
argsYesThe arguments to pass to the method.
contractIdYesThe account id of the contract.
methodNameYesThe name of the method to call.
networkIdNomainnet

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "args": { "additionalProperties": {}, "description": "The arguments to pass to the method.", "type": "object" }, "contractId": { "description": "The account id of the contract.", "type": "string" }, "methodName": { "description": "The name of the method to call.", "type": "string" }, "networkId": { "default": "mainnet", "enum": [ "testnet", "mainnet" ], "type": "string" } }, "required": [ "contractId", "methodName", "args" ], "type": "object" }

Implementation Reference

  • Executes a read-only (view) function call on a NEAR smart contract. Connects to the network, verifies the contract account, calls viewFunction with provided method and args, handles errors, and returns the result.
    const connection = await connect({ networkId: args.networkId, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const accountResult: Result<Account, Error> = await getAccount( args.contractId, connection, ); if (!accountResult.ok) { return { content: [{ type: 'text', text: `Error: ${accountResult.error}` }], }; } const account = accountResult.value; const viewCallResult: Result<unknown, Error> = await (async () => { try { return { ok: true, value: await account.viewFunction({ contractId: args.contractId, methodName: args.methodName, args: args.args, }), }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!viewCallResult.ok) { return { content: [{ type: 'text', text: `Error: ${viewCallResult.error}` }], }; } return { content: [ { type: 'text', text: `View call result: ${stringify_bigint(viewCallResult.value)}`, }, ], }; },
  • Zod schema defining input parameters: contractId (string), methodName (string), networkId (enum: testnet/mainnet, default mainnet), args (record of string to any).
    contractId: z.string().describe('The account id of the contract.'), methodName: z.string().describe('The name of the method to call.'), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), args: z .record(z.string(), z.any()) .describe('The arguments to pass to the method.'), },
  • Registers the MCP tool 'contract_call_raw_function_as_read_only' with description, input schema, and handler function.
    'contract_call_raw_function_as_read_only', noLeadingWhitespace` Call a function of a contract as a read-only call. This is equivalent to saying we are calling a view method of the contract.`, { contractId: z.string().describe('The account id of the contract.'), methodName: z.string().describe('The name of the method to call.'), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), args: z .record(z.string(), z.any()) .describe('The arguments to pass to the method.'), }, async (args, _) => { const connection = await connect({ networkId: args.networkId, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const accountResult: Result<Account, Error> = await getAccount( args.contractId, connection, ); if (!accountResult.ok) { return { content: [{ type: 'text', text: `Error: ${accountResult.error}` }], }; } const account = accountResult.value; const viewCallResult: Result<unknown, Error> = await (async () => { try { return { ok: true, value: await account.viewFunction({ contractId: args.contractId, methodName: args.methodName, args: args.args, }), }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!viewCallResult.ok) { return { content: [{ type: 'text', text: `Error: ${viewCallResult.error}` }], }; } return { content: [ { type: 'text', text: `View call result: ${stringify_bigint(viewCallResult.value)}`, }, ], }; }, );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nearai/near-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server