Skip to main content
Glama

contract_call_raw_function

Execute a raw function call on a NEAR contract, creating a transaction with gas and NEAR costs. Specify account IDs, method name, arguments, gas, and deposit for precise execution on testnet or mainnet.

Instructions

Call a function of a contract as a raw function call action. This tool creates a function call as a transaction which costs gas and NEAR.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYesThe account id of the signer.
argsYesThe arguments to pass to the method.
attachedDepositNoThe amount to attach to the function call (default to 1 yoctoNEAR). Can be specified as a number (in NEAR) or as a bigint (in yoctoNEAR).
contractAccountIdYesThe account id of the contract.
gasNoThe amount of gas to use for the function call in yoctoNEAR (default to 30TGas).
methodNameYesThe name of the method to call.
networkIdNomainnet

Implementation Reference

  • Handler function that performs a raw function call to a NEAR smart contract using the signer account's key from the keystore. It connects to the network, validates the contract account, executes the function call with specified args, gas, and deposit, and returns the transaction result.
    async (args, _) => { const connection = await connect({ networkId: args.networkId, keyStore: keystore, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const contractAccountResult: Result<Account, Error> = await getAccount( args.contractAccountId, connection, ); if (!contractAccountResult.ok) { return { content: [ { type: 'text', text: `Error: ${contractAccountResult.error}`, }, ], }; } const contractAccount = contractAccountResult.value; const functionCallResult: Result<unknown, Error> = await (async () => { try { const deposit = typeof args.attachedDeposit === 'number' ? NearToken.parse_near( args.attachedDeposit.toString(), ).as_yocto_near() : args.attachedDeposit; const signerAccount = await connection.account(args.accountId); return { ok: true, value: await signerAccount.functionCall({ contractId: contractAccount.accountId, methodName: args.methodName, args: args.args, gas: args.gas || DEFAULT_GAS, attachedDeposit: deposit, }), }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!functionCallResult.ok) { return { content: [ { type: 'text', text: `Error: ${functionCallResult.error}`, }, ], }; } return { content: [ { type: 'text', text: `Function call result: ${stringify_bigint(functionCallResult.value)}`, }, ], }; },
  • Zod schema defining the input parameters for the contract_call_raw_function tool: accountId (signer), contractAccountId, methodName, networkId, args (record), optional gas (bigint), attachedDeposit (number or bigint).
    accountId: z.string().describe('The account id of the signer.'), contractAccountId: 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.'), gas: z .bigint() .optional() .describe( 'The amount of gas to use for the function call in yoctoNEAR (default to 30TGas).', ), attachedDeposit: z .union([ z.number().describe('The amount of NEAR tokens (in NEAR)'), z.bigint().describe('The amount in yoctoNEAR'), ]) .default(NearToken.parse_yocto_near('1').as_near()) .describe( 'The amount to attach to the function call (default to 1 yoctoNEAR). Can be specified as a number (in NEAR) or as a bigint (in yoctoNEAR).', ), },
  • MCP tool registration using mcp.tool() with name 'contract_call_raw_function', description, input schema, and handler callback.
    'contract_call_raw_function', noLeadingWhitespace` Call a function of a contract as a raw function call action. This tool creates a function call as a transaction which costs gas and NEAR.`, { accountId: z.string().describe('The account id of the signer.'), contractAccountId: 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.'), gas: z .bigint() .optional() .describe( 'The amount of gas to use for the function call in yoctoNEAR (default to 30TGas).', ), attachedDeposit: z .union([ z.number().describe('The amount of NEAR tokens (in NEAR)'), z.bigint().describe('The amount in yoctoNEAR'), ]) .default(NearToken.parse_yocto_near('1').as_near()) .describe( 'The amount to attach to the function call (default to 1 yoctoNEAR). Can be specified as a number (in NEAR) or as a bigint (in yoctoNEAR).', ), }, async (args, _) => { const connection = await connect({ networkId: args.networkId, keyStore: keystore, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const contractAccountResult: Result<Account, Error> = await getAccount( args.contractAccountId, connection, ); if (!contractAccountResult.ok) { return { content: [ { type: 'text', text: `Error: ${contractAccountResult.error}`, }, ], }; } const contractAccount = contractAccountResult.value; const functionCallResult: Result<unknown, Error> = await (async () => { try { const deposit = typeof args.attachedDeposit === 'number' ? NearToken.parse_near( args.attachedDeposit.toString(), ).as_yocto_near() : args.attachedDeposit; const signerAccount = await connection.account(args.accountId); return { ok: true, value: await signerAccount.functionCall({ contractId: contractAccount.accountId, methodName: args.methodName, args: args.args, gas: args.gas || DEFAULT_GAS, attachedDeposit: deposit, }), }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!functionCallResult.ok) { return { content: [ { type: 'text', text: `Error: ${functionCallResult.error}`, }, ], }; } return { content: [ { type: 'text', text: `Function call result: ${stringify_bigint(functionCallResult.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