# 환경 변수 정리

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-protocol-whitepaper-ko/acp/acp-dev/best-practices-guide/environment-variable-sanitization.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.
