Environment Variables
Environment variables are used to configure sensitive settings like private keys and deployment-specific parameters. This approach keeps sensitive information out of configuration files, enhancing security.
Required Environment Variables
These environment variables are essential for ApiCharge to function correctly and must be set in all deployments.
Variable Name | Description | Example |
---|---|---|
APICHARGE_SIGNING_KEY |
The ED25519 private key (Stellar secret seed) used to sign quotes and access tokens | SABC...XYZ (56 characters starting with 'S') |
APICHARGE_NETWORK_PASSPHRASE |
The Stellar network passphrase that matches your chosen network (Testnet or Mainnet) | Test SDF Network ; September 2015 |
stellar keys generate YOUR_NAME
ASP.NET Core Environment Variables
These standard ASP.NET Core environment variables control the web server behavior.
Variable Name | Description | Example |
---|---|---|
ASPNETCORE_ENVIRONMENT |
Sets the runtime environment name, affecting which appsettings.{Environment}.json file is loaded | Development , Production , Staging |
ASPNETCORE_URLS |
Defines which URLs and ports the web server should listen on | http://0.0.0.0:80;https://0.0.0.0:443 |
ASPNETCORE_HTTPS_PORT |
Specifies which port to use for HTTPS | 443 |
Certificate Environment Variables
These variables are used to configure HTTPS certificates when not using the Kestrel configuration in appsettings.json.
Variable Name | Description | Example |
---|---|---|
ASPNETCORE_Kestrel__Certificates__Default__Path |
The file path to the HTTPS certificate | /app/certs/certificate.pfx |
ASPNETCORE_Kestrel__Certificates__Default__Password |
The password for the HTTPS certificate | cert_password |
Redis Configuration
These variables configure the Redis connection when using Redis for distributed caching in clustered deployments.
Variable Name | Description | Example |
---|---|---|
REDIS_CONNECTION_STRING |
Redis connection string to override the one in appsettings.json | redis:6379,password=password123 |
Logging Configuration
These variables control logging levels and destinations.
Variable Name | Description | Example |
---|---|---|
Logging__LogLevel__Default |
The default log level | Information , Warning , Error |
Logging__LogLevel__Microsoft |
Log level for Microsoft namespaces | Warning |
Logging__LogLevel__ApiChargePrototype |
Log level for ApiCharge-specific code | Debug , Information |
Custom Environment Variables
You can define custom environment variables to override any setting in the appsettings.json file. The naming convention follows a double-underscore pattern to represent the hierarchical structure of the JSON.
Examples:
# Override GlobalSettings.UseNetwork
GlobalSettings__UseNetwork=Mainnet
# Override GlobalSettings.ToleratedClockSkew (TimeSpan)
GlobalSettings__ToleratedClockSkew=00:05:00
# Override QuoteValidityDuration
GlobalSettings__QuoteValidityDuration=01:30:00
# Override a specific route quote price
ApiChargeQuotes__Quotes__0__MicroUnitPrice=500000
Environment Variables in Docker
When deploying with Docker, you can set environment variables in the docker-compose.yml file or using the -e flag with docker run:
# In docker-compose.yml
services:
apicharge:
image: apicharge:latest
environment:
- APICHARGE_SIGNING_KEY=S...
- APICHARGE_NETWORK_PASSPHRASE=Test SDF Network ; September 2015
- ASPNETCORE_ENVIRONMENT=Production
- ASPNETCORE_URLS=http://0.0.0.0:80;https://0.0.0.0:443
Or when using docker run:
docker run -e APICHARGE_SIGNING_KEY=S... -e APICHARGE_NETWORK_PASSPHRASE="Test SDF Network ; September 2015" apicharge:latest
Environment Variables in Kubernetes
When deploying to Kubernetes, you should use Secrets for sensitive information and ConfigMaps for non-sensitive configuration:
# Create a Secret for sensitive data
kubectl create secret generic apicharge-secrets \
--from-literal=APICHARGE_SIGNING_KEY=S... \
--from-literal=APICHARGE_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
# In your deployment YAML
spec:
containers:
- name: apicharge
image: apicharge:latest
envFrom:
- secretRef:
name: apicharge-secrets
env:
- name: ASPNETCORE_ENVIRONMENT
value: "Production"
Setting Environment Variables Locally
For local development, you can set environment variables using:
Windows (PowerShell):
$env:APICHARGE_SIGNING_KEY="S..."
$env:APICHARGE_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
Windows (Command Prompt):
set APICHARGE_SIGNING_KEY=S...
set APICHARGE_NETWORK_PASSPHRASE=Test SDF Network ; September 2015
Linux/macOS:
export APICHARGE_SIGNING_KEY="S..."
export APICHARGE_NETWORK_PASSPHRASE="Test SDF Network ; September 2015"
Using a .env file with dotnet run:
Create a .env file in your project directory:
APICHARGE_SIGNING_KEY=S...
APICHARGE_NETWORK_PASSPHRASE=Test SDF Network ; September 2015
Then install the dotenv tool and run your application:
dotnet tool install --global dotnet-env
dotnet env run -- dotnet run
Next Steps
Now that you understand how to configure ApiCharge, you can learn more about:
- Routes Overview - How to define API routes in ApiCharge
- Rate Limiters - Available rate limiting strategies
- Deployment Options - Different ways to deploy ApiCharge