Skip to main content
Glama

opt_in_to_asset

Opt into an Algorand Standard Asset using your account mnemonic and the asset ID. Enables blockchain asset interaction through the Algorand MCP Server.

Instructions

Opt into an Algorand Standard Asset

Input Schema

NameRequiredDescriptionDefault
accountMnemonicYesAccount mnemonic phrase (25 words)
assetIdYesAsset ID to opt into

Input Schema (JSON Schema)

{ "properties": { "accountMnemonic": { "description": "Account mnemonic phrase (25 words)", "type": "string" }, "assetId": { "description": "Asset ID to opt into", "type": "number" } }, "required": [ "accountMnemonic", "assetId" ], "type": "object" }

Implementation Reference

  • Core implementation of the optInToAsset method in AlgorandService class. Handles importing account from mnemonic, creating a 0-amount asset transfer transaction for opt-in, signing, sending, and confirming the transaction using algosdk.
    async optInToAsset(accountMnemonic: string, assetId: number) { try { const account = this.importAccountFromMnemonic(accountMnemonic); const suggestedParams = await this.algodClient.getTransactionParams().do(); const txn = algosdk.makeAssetTransferTxnWithSuggestedParamsFromObject({ sender: account.addr, receiver: account.addr, amount: 0, assetIndex: assetId, suggestedParams, }); const signedTxn = txn.signTxn(account.sk); const response = await this.algodClient.sendRawTransaction(signedTxn).do(); const txId = response.txid || txn.txID(); // Wait for confirmation const result = await algosdk.waitForConfirmation(this.algodClient, txId, 4); return { txId, confirmedRound: result.confirmedRound, }; } catch (error) { throw new Error(`Asset opt-in failed: ${error}`); } }
  • Zod schema defining the input arguments for the opt_in_to_asset tool: accountMnemonic (string) and assetId (number).
    const OptInToAssetArgsSchema = z.object({ accountMnemonic: z.string(), assetId: z.number(), });
  • src/index.ts:247-264 (registration)
    Registration of the 'opt_in_to_asset' tool in the TOOLS array, including name, description, and input schema matching the Zod schema.
    { name: 'opt_in_to_asset', description: 'Opt into an Algorand Standard Asset', inputSchema: { type: 'object', properties: { accountMnemonic: { type: 'string', description: 'Account mnemonic phrase (25 words)', }, assetId: { type: 'number', description: 'Asset ID to opt into', }, }, required: ['accountMnemonic', 'assetId'], }, },
  • Handler case in the main tool dispatcher that validates arguments using OptInToAssetArgsSchema, calls the AlgorandService.optInToAsset method, and formats the success/error response.
    case 'opt_in_to_asset': { const parsed = OptInToAssetArgsSchema.parse(args); try { const result = await algorandService.optInToAsset( parsed.accountMnemonic, parsed.assetId ); return { content: [ { type: 'text', text: `Asset Opt-in Successful!\nAsset ID: ${parsed.assetId}\nTransaction ID: ${result.txId}\nConfirmed in Round: ${result.confirmedRound}`, }, ], }; } catch (error) { return { content: [ { type: 'text', text: `Asset opt-in failed: ${error}`, }, ], isError: true, }; } }

Other Tools

Related Tools

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/Jake-loranger/algorand-mcp-server'

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