Skip to content

Commit 517c4d9

Browse files
andrewklauclaude
andauthored
fix(block-proxy): add FASTNEAR_API_KEY support (#1364)
fix(block-proxy): add FASTNEAR_API_KEY support and clarify NEAR Lake env defaults Add optional FASTNEAR_API_KEY env var that appends ?apiKey= query param to fastnear upstream requests when set. Clarify in .env.example that NEAR_LAKE_BUCKET and NEAR_LAKE_REGION are auto-derived from NETWORK. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bfc1ec5 commit 517c4d9

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

apps/block-proxy/.env.example

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# --- fastnear (enabled by default, no config needed) ---
1818
# FASTNEAR_ENABLED=true
1919
# FASTNEAR_URL=https://mainnet.neardata.xyz
20+
# FASTNEAR_API_KEY=
2021

2122
# --- S3/MinIO (disabled by default, set these if you have a local block store) ---
2223
# S3_ENABLED=false
@@ -26,10 +27,14 @@
2627
# S3_ACCESS_KEY=
2728
# S3_SECRET_KEY=
2829

29-
# --- NEAR Lake (disabled by default, requires credentials) ---
30+
# --- NEAR Lake (disabled by default, requires AWS credentials) ---
31+
# Bucket and region are auto-derived from NETWORK:
32+
# mainnet → near-lake-data-mainnet, eu-central-1
33+
# testnet → near-lake-data-testnet, eu-central-1
34+
# Only NEAR_LAKE_ENABLED + credentials are needed to enable.
3035
# NEAR_LAKE_ENABLED=false
31-
# NEAR_LAKE_BUCKET=near-lake-data-mainnet
32-
# NEAR_LAKE_REGION=eu-central-1
3336
# NEAR_LAKE_ACCESS_KEY=
3437
# NEAR_LAKE_SECRET_KEY=
38+
# NEAR_LAKE_BUCKET= # optional override (auto-derived from NETWORK)
39+
# NEAR_LAKE_REGION=eu-central-1 # optional override
3540
# UPSTREAM_TIMEOUT_SECS=7

apps/block-proxy/src/config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ const env = cleanEnv(process.env, {
88
CACHE_DIR: str({ default: '/app/cache' }),
99
CACHE_ENABLED: bool({ default: true }),
1010
CACHE_TTL_SECS: num({ default: 3600 }),
11+
FASTNEAR_API_KEY: str({ default: '' }),
1112
FASTNEAR_ENABLED: bool({ default: true }),
1213
FASTNEAR_URL: str({ default: '' }),
1314
LOG_LEVEL: str({ default: 'info' }),
@@ -60,6 +61,7 @@ const config = {
6061
cacheDir: env.CACHE_DIR,
6162
cacheEnabled: env.CACHE_ENABLED,
6263
cacheTtlSecs: env.CACHE_TTL_SECS,
64+
fastnearApiKey: env.FASTNEAR_API_KEY,
6365
fastnearBaseUrl: deriveFastnearUrl(env.NETWORK, env.FASTNEAR_URL),
6466
fastnearEnabled: env.FASTNEAR_ENABLED,
6567
logLevel: env.LOG_LEVEL,
@@ -89,6 +91,7 @@ export function logConfigSummary(): void {
8991
cacheDir: config.cacheDir,
9092
cacheEnabled: config.cacheEnabled,
9193
cacheTtlSecs: config.cacheTtlSecs,
94+
fastnearApiKey: mask(config.fastnearApiKey),
9295
fastnearEnabled: config.fastnearEnabled,
9396
fastnearUrl: config.fastnearBaseUrl,
9497
nearLakeAccessKey: mask(config.nearLakeAccessKey),

apps/block-proxy/src/upstream/fastnear.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,23 @@ import type { Config } from '#config';
55
const MAX_BODY_SIZE = 100 * 1024 * 1024; // 100 MB
66

77
export class FastnearUpstream {
8+
private apiKey: string;
89
private baseUrl: string;
910
private timeoutMs: number;
1011

1112
constructor(config: Config) {
13+
this.apiKey = config.fastnearApiKey;
1214
this.baseUrl = config.fastnearBaseUrl;
1315
this.timeoutMs = config.upstreamTimeoutMs;
1416
}
1517

18+
private buildUrl(path: string): string {
19+
const url = `${this.baseUrl}${path}`;
20+
return this.apiKey ? `${url}?apiKey=${this.apiKey}` : url;
21+
}
22+
1623
async fetch(height: number): Promise<Buffer> {
17-
const url = `${this.baseUrl}/v0/block/${height}`;
24+
const url = this.buildUrl(`/v0/block/${height}`);
1825
const start = Date.now();
1926

2027
const response = await globalThis
@@ -67,7 +74,7 @@ export class FastnearUpstream {
6774
}
6875

6976
async fetchLastBlockFinal(): Promise<Buffer> {
70-
const url = `${this.baseUrl}/v0/last_block/final`;
77+
const url = this.buildUrl('/v0/last_block/final');
7178
const start = Date.now();
7279

7380
const response = await globalThis

0 commit comments

Comments
 (0)