opt_in_to_asset
Enable an Algorand account to receive a specific blockchain asset by providing the account mnemonic and asset ID. This tool facilitates asset management on the Algorand network.
Instructions
Opt into an Algorand Standard Asset
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountMnemonic | Yes | Account mnemonic phrase (25 words) | |
| assetId | Yes | Asset ID to opt into |
Implementation Reference
- src/algorand.ts:239-266 (handler)The core handler function `optInToAsset` in the AlgorandService class that implements the asset opt-in by creating a zero-amount asset transfer transaction from the account to itself, signing it, sending it, and waiting for confirmation.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}`); } }
- src/index.ts:58-61 (schema)Zod schema for input validation of the tool arguments: accountMnemonic (string) and assetId (number).const OptInToAssetArgsSchema = z.object({ accountMnemonic: z.string(), assetId: z.number(), });
- src/index.ts:247-264 (registration)MCP tool registration in the TOOLS array, defining the name, description, and JSON inputSchema for the opt_in_to_asset tool.{ 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'], }, },
- src/index.ts:618-644 (handler)Top-level MCP server handler for the tool: parses args with schema, calls the service handler, formats 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, }; } }