sample.env


Overview

The [sample.env](/projects/291/68843) file is a template for environment configuration variables used in the application. It defines key-value pairs that configure external service integrations, logging behavior, and network connectivity. This file acts as a reference for developers and deployment scripts to understand and provide necessary values for the application to function correctly in different environments (e.g., development, testing, production).

Typically, [sample.env](/projects/291/68843) is not used directly by the application but is copied to `.env` (or similar) where actual secret values and URLs are populated. This separation ensures sensitive information like API keys are not committed to version control while providing a clear schema for required configuration.


Environment Variables Explained

This file contains two categories of environment variables:

1. Secret Environment Variables

These variables hold sensitive credentials and API keys that must be kept confidential.

Variable Name

Description

Example Value

ETHERSCAN_API_KEY

API key for accessing the Etherscan blockchain explorer API. Used for querying Ethereum-based blockchain data.

YourEtherscanApiKeyHere

`INDEXER_API_KEY`

API key for authenticating requests to the Indexer service.

YourIndexerApiKeyHere

`RPC_API_KEY`

API key for Remote Procedure Call (RPC) endpoint access, enabling blockchain node communication.

YourRpcApiKeyHere

**Note:** The actual values should be kept secret and not pushed to version control.


2. General Environment Variables

These configure the endpoints, logging, and network settings for the application.

Variable Name

Description

Example Value

`INDEXER_URL`

HTTP URL for the Indexer REST API service. This service indexes blockchain data for querying.

`https://maticbook.nownodes.io`

`INDEXER_WS_URL`

WebSocket URL for the Indexer service, enabling real-time updates and event subscriptions.

`wss://maticbook.nownodes.io/wss`

`LOG_LEVEL`

Sets the verbosity of logging output. Common levels: `debug`, `info`, `warn`, `error`.

`debug`

`NETWORK`

Specifies the target blockchain network (e.g., mainnet, testnet).

mainnet

`RPC_URL`

HTTP URL for the blockchain RPC endpoint, used for submitting transactions and querying chain state.

`https://matic.nownodes.io`


Usage Example

In a Node.js project, the variables defined in `.env` (copied from [sample.env](/projects/291/68843)) can be loaded using the `dotenv` package:

require('dotenv').config();

console.log(process.env.INDEXER_URL);  // Outputs: https://maticbook.nownodes.io
console.log(process.env.LOG_LEVEL);    // Outputs: debug

This allows the application to dynamically configure itself based on environment without hardcoding values.


Implementation Details


Interaction with Other Parts of the System

The environment variables defined here effectively decouple configuration from code, supporting multiple deployment environments and secure management of secrets.


Visual Diagram

flowchart TD
    subgraph "Environment Variables"
        SECRETS[Secret Variables]
        GENERAL[General Variables]
    end

    SECRETS -->|Used for Authentication| BlockchainNode[Blockchain Node (RPC)]
    SECRETS -->|Used for Authentication| IndexerService[Indexer Service]

    GENERAL -->|Endpoint Config| BlockchainNode
    GENERAL -->|Endpoint Config| IndexerService
    GENERAL -->|Configures| LoggingSystem[Logging System]
    GENERAL -->|Configures| NetworkModule[Network Module]

    BlockchainNode -->|RPC Calls| Blockchain[Polygon Network]
    IndexerService -->|Queries & Subscriptions| Blockchain

    LoggingSystem -->|Controls Logging Output| Application[Application Core]
    NetworkModule -->|Network Selection| Application

Summary

The [sample.env](/projects/291/68843) file is a foundational configuration template defining secret keys and endpoint URLs that govern how the application interacts with blockchain nodes, indexer services, and logging frameworks. It promotes security by isolating secrets from codebases and flexibility by enabling environment-specific configuration. Proper setup of this file is critical for the application’s connectivity and operational correctness within the Polygon blockchain ecosystem.