{"record":{"id":"343e52613dc0669f","repo":"affaan-m/ECC","slug":"trading-wallet-private-key-not-set","errorCode":null,"errorMessage":"TRADING_WALLET_PRIVATE_KEY not set","messagePattern":"TRADING_WALLET_PRIVATE_KEY not set","errorType":"exception","errorClass":"EnvironmentError","httpStatus":null,"severity":"critical","filePath":"skills/llm-trading-agent-security/SKILL.md","lineNumber":120,"sourceCode":"\n        if self.hour_start_value <= 0:\n            self.halt(\"Invalid hour_start_value\")\n            return\n\n        hourly_pnl = (portfolio_value - self.hour_start_value) / self.hour_start_value\n        if hourly_pnl < -self.MAX_HOURLY_LOSS_PCT:\n            self.halt(f\"Hourly PnL {hourly_pnl:.1%} below threshold\")\n```\n\n### Wallet isolation\n\n```python\nimport os\nfrom eth_account import Account\n\nprivate_key = os.environ.get(\"TRADING_WALLET_PRIVATE_KEY\")\nif not private_key:\n    raise EnvironmentError(\"TRADING_WALLET_PRIVATE_KEY not set\")\n\naccount = Account.from_key(private_key)\n```\n\nUse a dedicated hot wallet with only the required session funds. Never point the agent at a primary treasury wallet.\n\n### MEV and deadline protection\n\n```python\nimport time\n\nPRIVATE_RPC = \"https://rpc.flashbots.net\"\nMAX_SLIPPAGE_BPS = {\"stable\": 10, \"volatile\": 50}\ndeadline = int(time.time()) + 60\n```\n\n## Pre-Deploy Checklist\n","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/affaan-m/ECC/blob/01e15490f04e29cfefe3896951f43db46994d8ee/skills/llm-trading-agent-security/SKILL.md#L102-L138","documentation":"At startup, the agent reads `TRADING_WALLET_PRIVATE_KEY` from the environment; if unset/empty, it raises `EnvironmentError(\"TRADING_WALLET_PRIVATE_KEY not set\")` before constructing the `Account`. This is a fail-fast on missing secret so the agent never runs unauthenticated.","triggerScenarios":"Process started without `TRADING_WALLET_PRIVATE_KEY` in the environment — `.env` not loaded, secret manager unreachable, deployed without the var, or name typo.","commonSituations":"Forgot to `export` the var in the shell. `python-dotenv` not loaded in the entrypoint. Container missing the secret volume/env. Different casing (`Trading_Wallet_Private_Key`). CI masked the var and the run used the literal masked string.","solutions":["Set the variable in the runtime environment (`.env` for local, secret manager / k8s secret for prod) and confirm with `printenv TRADING_WALLET_PRIVATE_KEY`.","Load `.env` explicitly at startup (`load_dotenv()`) before the check.","Make sure the var name casing matches exactly — environment variables are case-sensitive on POSIX.","If using a masked CI value, confirm the real value is what reaches the process (not the `***` placeholder)."],"exampleFix":"# before\nprivate_key = os.environ.get(\"TRADING_WALLET_PRIVATE_KEY\")\nif not private_key:\n    raise EnvironmentError(\"TRADING_WALLET_PRIVATE_KEY not set\")\n\n# after — fail fast with actionable message; load .env in dev\nfrom dotenv import load_dotenv\nload_dotenv()\nprivate_key = os.environ.get(\"TRADING_WALLET_PRIVATE_KEY\")\nif not private_key or private_key.startswith(\"***\"):\n    raise EnvironmentError(\"TRADING_WALLET_PRIVATE_KEY missing or masked; set it in the environment/secret manager\")","handlingStrategy":"validation","validationCode":"import os\ndef has_wallet_key() -> bool:\n    v = os.environ.get('TRADING_WALLET_PRIVATE_KEY')\n    return bool(v) and not v.startswith('***')","typeGuard":"null","tryCatchPattern":"try:\n    account = Account.from_key(os.environ['TRADING_WALLET_PRIVATE_KEY'])\nexcept (KeyError, EnvironmentError) as e:\n    log.error('secret missing: %s', e)\n    sys.exit(2)  # fail fast, do not run unauthenticated","preventionTips":["Load `.env` at startup (`load_dotenv()`) in dev.","Inject secrets via the platform secret manager (k8s secret, AWS SM), not the image.","Use a dedicated hot wallet with only session funds; never the treasury key."],"tags":["web3","secrets","configuration","startup","security"],"backgroundTag":null,"analyzedSha":"01e15490f04e29cfefe3896951f43db46994d8ee","analyzedAt":"2026-08-13T00:31:08.655Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}