# 环境变量净化

我们看到很多团队因为把环境变量搞错了，导致难以快速启动并运行 ACP。在我们的示例中，我们提供了带有一些辅助代码的环境变量清理。请使用它们！或者，你也可以自己实现。&#x20;

这可确保你能够顺利运行代码，并且与环境变量相关的错误会被快速捕获并处理。

```javascript
// 清理环境变量
function sanitizeEnvironmentVariables() {
  const requiredVars = [
    'WHITELISTED_WALLET_PRIVATE_KEY',
    'WHITELISTED_WALLET_ENTITY_ID',
    'SELLER_AGENT_WALLET_ADDRESS'
  ];
  
  for (const varName of requiredVars) {
    const value = process.env[varName];
    
    if (!value) {
      throw new Error(`缺少必需的环境变量：${varName}`);
    }
    
    // 验证特定格式
    if (varName.includes('WALLET_ADDRESS')) {
      if (!/^0x[a-fA-F0-9]{40}$/.test(value)) {
        throw new Error(`无效的钱包地址格式：${varName}`);
      }
    }
    
    if (varName.includes('PRIVATE_KEY')) {
      if (!/^0x[a-fA-F0-9]{64}$/.test(value)) {
        throw new Error(`无效的私钥格式：${varName}`);
      }
    }
    
    if (varName.includes('ENTITY_ID')) {
      const entityId = parseInt(value);
      if (isNaN(entityId) || entityId < 0) {
        throw new Error(`无效的实体 ID：${varName}`);
      }
    }
  }
}

// 在启动时调用
sanitizeEnvironmentVariables();
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.virtuals.io/virtuals-bai-pi-shu/acp/acp-kai-fa-zhe-ru-men-zhi-nan/zui-jia-shi-jian-zhi-nan/huan-jing-bian-liang-jing-hua.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
