UNPKG

@sei-js/mcp-server

Version:

Model Context Protocol (MCP) server for interacting with EVM-compatible networks

30 lines (29 loc) 1.01 kB
import dotenv from 'dotenv'; import { z } from 'zod'; // Load environment variables from .env file dotenv.config(); // Define environment variable schema const envSchema = z.object({ PRIVATE_KEY: z.string().optional() }); // Parse and validate environment variables const env = envSchema.safeParse(process.env); // Format private key with 0x prefix if it exists const formatPrivateKey = (key) => { if (!key) return undefined; // Ensure the private key has 0x prefix return key.startsWith('0x') ? key : `0x${key}`; }; // Export validated environment variables with formatted private key export const config = { privateKey: env.success ? formatPrivateKey(env.data.PRIVATE_KEY) : undefined }; /** * Get the private key from environment variable as a Hex type for viem. * Returns undefined if the PRIVATE_KEY environment variable is not set. * @returns Private key from environment variable as Hex or undefined */ export function getPrivateKeyAsHex() { return config.privateKey; }