tokens_send_near
Transfer NEAR tokens between accounts on the NEAR blockchain. Specify sender, receiver, and amount, ensuring both accounts are on the same network (mainnet or testnet).
Instructions
Send NEAR tokens to an account (in NEAR). The signer account is the sender of the tokens, and the receiver account is the recipient of the tokens. Remember mainnet accounts are created with a .near suffix, and testnet accounts are created with a .testnet suffix. The user is sending tokens as the signer account. Please ensure that the sender and receiver accounts are in the same network.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| amount | No | The amount of NEAR to send in NEAR. e.g. 1.5 | |
| networkId | No | mainnet | |
| receiverAccountId | Yes | ||
| signerAccountId | Yes |
Implementation Reference
- src/services.ts:1641-1680 (handler)Handler function that connects to the NEAR network, retrieves the signer account, converts the amount to yoctoNEAR if necessary, calls account.sendMoney to transfer NEAR tokens to the receiver, and returns the transaction outcome or error.async (args, _) => { const connection = await connect({ networkId: args.networkId, keyStore: keystore, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const sendResult: Result<FinalExecutionOutcome, Error> = await (async () => { try { const account = await connection.account(args.signerAccountId); const amount = typeof args.amount === 'number' ? NearToken.parse_near(args.amount.toString()).as_yocto_near() : args.amount; const sendMoneyResult = await account.sendMoney( args.receiverAccountId, amount, ); return { ok: true, value: sendMoneyResult, }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!sendResult.ok) { return { content: [{ type: 'text', text: `Error: ${sendResult.error}` }], }; } return { content: [ { type: 'text', text: `Transaction sent: ${stringify_bigint(sendResult.value)}`, }, ], }; },
- src/services.ts:1630-1640 (schema)Input schema using Zod for validating parameters: signerAccountId (string), receiverAccountId (string), amount (union of number in NEAR or bigint in yoctoNEAR, default 1 yoctoNEAR), networkId (enum testnet/mainnet, default mainnet).signerAccountId: z.string(), receiverAccountId: z.string(), amount: 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 of NEAR to send in NEAR. e.g. 1.5'), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), },
- src/services.ts:1619-1681 (registration)Registration of the 'tokens_send_near' tool on the MCP server with name, description, input schema, and handler function.mcp.tool( 'tokens_send_near', noLeadingWhitespace` Send NEAR tokens to an account (in NEAR). The signer account is the sender of the tokens, and the receiver account is the recipient of the tokens. Remember mainnet accounts are created with a .near suffix, and testnet accounts are created with a .testnet suffix. The user is sending tokens as the signer account. Please ensure that the sender and receiver accounts are in the same network.`, { signerAccountId: z.string(), receiverAccountId: z.string(), amount: 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 of NEAR to send in NEAR. e.g. 1.5'), networkId: z.enum(['testnet', 'mainnet']).default('mainnet'), }, async (args, _) => { const connection = await connect({ networkId: args.networkId, keyStore: keystore, nodeUrl: getEndpointsByNetwork(args.networkId)[0]!, }); const sendResult: Result<FinalExecutionOutcome, Error> = await (async () => { try { const account = await connection.account(args.signerAccountId); const amount = typeof args.amount === 'number' ? NearToken.parse_near(args.amount.toString()).as_yocto_near() : args.amount; const sendMoneyResult = await account.sendMoney( args.receiverAccountId, amount, ); return { ok: true, value: sendMoneyResult, }; } catch (e) { return { ok: false, error: new Error(e as string) }; } })(); if (!sendResult.ok) { return { content: [{ type: 'text', text: `Error: ${sendResult.error}` }], }; } return { content: [ { type: 'text', text: `Transaction sent: ${stringify_bigint(sendResult.value)}`, }, ], }; }, );