Skip to main content
Glama

account_export_account

Export a NEAR account from the local keystore to a specified file path, enabling easy backup or transfer. Supports testnet and mainnet.

Instructions

Export a NEAR account from the local keystore to a file.

Input Schema

NameRequiredDescriptionDefault
accountIdYes
filePathNoThe path to the file to write the account to. If not provided, the account will be written to the current working directory.
networkIdNomainnet

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "accountId": { "type": "string" }, "filePath": { "description": "The path to the file to write the account to. If not provided, the account will be written to the current working directory.", "type": "string" }, "networkId": { "default": "mainnet", "enum": [ "testnet", "mainnet" ], "type": "string" } }, "required": [ "accountId" ], "type": "object" }

Implementation Reference

  • Handler function for 'account_export_account' tool. Retrieves the account and keypair from keystore, constructs a JSON payload with account_id, public_key, and private_key, and writes it to a file (default: <accountId>.<networkId>.json). Returns success message or error.
    async (args, _) => { const connection = await connect({ networkId: args.networkId, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const accountResult: Result<Account, Error> = await getAccount( args.accountId, connection, ); if (!accountResult.ok) { return { content: [{ type: 'text', text: `Error: ${accountResult.error}` }], }; } const keypairResult: Result<KeyPair, Error> = await getAccountKeyPair( args.accountId, args.networkId, keystore, ); if (!keypairResult.ok) { return { content: [{ type: 'text', text: `Error: ${keypairResult.error}` }], }; } const keypair = keypairResult.value; const writeKeyFileResult: Result<void, Error> = await (async () => { try { const filePayload = { account_id: args.accountId, public_key: keypair.getPublicKey().toString(), private_key: keypair.toString(), }; const filePath = args.filePath || `${args.accountId}.${args.networkId}.json`; await writeFile(filePath, JSON.stringify(filePayload, null, 2)); return { ok: true, value: undefined }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!writeKeyFileResult.ok) { return { content: [ { type: 'text', text: `Error: ${writeKeyFileResult.error}` }, ], }; } return { content: [ { type: 'text', text: `Account ${args.accountId} exported to ${args.filePath}`, }, ], }; },
  • Input schema using Zod: accountId (string, required), networkId (enum testnet/mainnet, default mainnet), filePath (optional string).
    accountId: z.string(), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), filePath: z .string() .optional() .describe( 'The path to the file to write the account to. If not provided, the account will be written to the current working directory.', ), },
  • MCP tool registration for 'account_export_account': provides description, input schema, and references the handler function.
    'account_export_account', noLeadingWhitespace` Export a NEAR account from the local keystore to a file.`, { accountId: z.string(), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), filePath: z .string() .optional() .describe( 'The path to the file to write the account to. If not provided, the account will be written to the current working directory.', ), }, async (args, _) => { const connection = await connect({ networkId: args.networkId, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const accountResult: Result<Account, Error> = await getAccount( args.accountId, connection, ); if (!accountResult.ok) { return { content: [{ type: 'text', text: `Error: ${accountResult.error}` }], }; } const keypairResult: Result<KeyPair, Error> = await getAccountKeyPair( args.accountId, args.networkId, keystore, ); if (!keypairResult.ok) { return { content: [{ type: 'text', text: `Error: ${keypairResult.error}` }], }; } const keypair = keypairResult.value; const writeKeyFileResult: Result<void, Error> = await (async () => { try { const filePayload = { account_id: args.accountId, public_key: keypair.getPublicKey().toString(), private_key: keypair.toString(), }; const filePath = args.filePath || `${args.accountId}.${args.networkId}.json`; await writeFile(filePath, JSON.stringify(filePayload, null, 2)); return { ok: true, value: undefined }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!writeKeyFileResult.ok) { return { content: [ { type: 'text', text: `Error: ${writeKeyFileResult.error}` }, ], }; } return { content: [ { type: 'text', text: `Account ${args.accountId} exported to ${args.filePath}`, }, ], }; }, );

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