import type { GetAccountParams, GetAccountResult } from '@tevm/actions' import { option } from 'pastel' import { z } from 'zod' import CliAction from '../components/CliAction.js' import { envVar, useAction } from '../hooks/useAction.js' // Add command description for help output export const description = 'Get local account balance, nonce, code, and storage metadata\nExample: tevm get-account --address 0x4200000000000000000000000000000000000006 --rpc https://mainnet.optimism.io --run --json' // Options definitions and descriptions const optionDescriptions = { address: 'Ethereum address of the account to get (env: TEVM_ADDRESS)', rpc: 'RPC endpoint (env: TEVM_RPC)', returnStorage: 'Return account storage (can be expensive) (env: TEVM_RETURN_STORAGE)', blockTag: 'Block tag to fetch account from (latest, earliest, pending, etc.) (env: TEVM_BLOCK_TAG)', } // Empty args tuple export const args = z.tuple([]) export const options = z.object({ // Required address address: z.string().describe( option({ description: optionDescriptions.address, }), ), // Interactive mode flag (run directly without interactive editor) run: z .boolean() .default(false) .describe( option({ description: 'Run directly without interactive parameter editing (env: TEVM_RUN)', alias: 'r', }), ), // Transport options rpc: z .string() .default(envVar('rpc') || 'http://localhost:8545') .describe( option({ description: optionDescriptions.rpc, defaultValueDescription: 'http://localhost:8545', }), ), // Account retrieval options returnStorage: z .boolean() .default(false) .describe( option({ description: optionDescriptions.returnStorage, }), ), blockTag: z .string() .optional() .describe( option({ description: optionDescriptions.blockTag, }), ), // Output formatting json: z .boolean() .default(envVar('json') === 'true') .describe( option({ description: 'Emit the stable machine-readable JSON envelope (env: TEVM_JSON)', defaultValueDescription: 'false', }), ), }) type Props = { args: z.infer options: z.infer } // Default values for all parameters const defaultValues: Record = { rpc: 'http://localhost:8545', returnStorage: false, blockTag: 'latest', } export default function GetAccount({ options }: Props) { // Use the action hook with inlined createParams and executeAction const actionResult = useAction({ actionName: 'get-account', options, defaultValues, optionDescriptions, // Inlined createParams function createParams: (enhancedOptions: Record): GetAccountParams => { const targetAddress = enhancedOptions['address'] as `0x${string}` if (!targetAddress) { throw new Error('Address is required') } if (enhancedOptions['blockTag'] && enhancedOptions['blockTag'] !== 'latest') throw new Error('Use get-balance/get-storage-at for historical reads') return { address: targetAddress, } }, // Inlined executeAction function executeAction: async (client: any, params: GetAccountParams): Promise => { return await client.tevmGetAccount(params) }, }) // Render the action UI return ( ) }