-
Notifications
You must be signed in to change notification settings - Fork 21
Open
Description
Hi,
Populated the .env file and tried two different API keys.
Problem: env creds CDP_API_KEY_NAME and CDP_API_KEY_SECRET not loading and hence /api/wallets throws an error
Error:
import { Coinbase } from "@coinbase/coinbase-sdk";
console.log("CDP_API_KEY_NAME:", process.env.CDP_API_KEY_NAME); // added for debugging
console.log("CDP_API_KEY_SECRET:", process.env.CDP_API_KEY_SECRET); // added for debugging
if (!process.env.CDP_API_KEY_NAME || !process.env.CDP_API_KEY_SECRET) {
throw new Error("CDP_API_KEY_NAME and CDP_API_KEY_SECRET must be set");
}
const { CDP_API_KEY_NAME, CDP_API_KEY_SECRET } = process.env;
const apiKeyString = CDP_API_KEY_SECRET as string;
Coinbase.configure({
apiKeyName: CDP_API_KEY_NAME as string,
privateKey: apiKeyString.replaceAll("\\n", "\n") as string,
});Logs:
> next dev
▲ Next.js 14.2.12
- Local: http://localhost:3000
- Environments: .env.local # (tried also .env or .env.development)
✓ Starting...
✓ Ready in 3.6s
○ Compiling /api/wallets ...
✓ Compiled /api/wallets in 2.2s (714 modules)
CDP_API_KEY_NAME: undefined
CDP_API_KEY_SECRET: undefined
# (log burb)
page: '/api/wallets'
}
5 |
6 | if (!process.env.CDP_API_KEY_NAME || !process.env.CDP_API_KEY_SECRET) {
> 7 | throw new Error("CDP_API_KEY_NAME and CDP_API_KEY_SECRET must be set");
| ^
8 | }
9 |
10 | const { CDP_API_KEY_NAME, CDP_API_KEY_SECRET } = process.env;
GET /api/wallets 500 in 53ms
GET /favicon.ico 500 in 11ms
GET /favicon.ico 500 in 7ms
GET /favicon.ico 500 in 6msWhat am I doing wrong here? dotenv is installed and I am using just npm run dev
Also, I tried this here without success:
//next.config.mjs
/** @type {import('next').NextConfig} */
import { config } from "dotenv";
// Load environment variables
config();
const nextConfig = {
env: {
CDP_API_KEY_NAME: process.env.CDP_API_KEY_NAME,
CDP_API_KEY_SECRET: process.env.CDP_API_KEY_SECRET,
},
};
export default nextConfig;Metadata
Metadata
Assignees
Labels
No labels