1

I am working through https://www.soldev.app/course/intro-to-cryptography

and at the point where I am attempting to import the secret key from a .env

I am getting an error:

enter image description here

My keypair is set using:

import { Keypair } from "@solana/web3.js";

const keypair = Keypair.generate();

console.log(The public key is: , keypair.publicKey.toBase58()); console.log(The secret key is: , keypair.secretKey); console.log(✅ Finished!);

not sure how to resolve it as I am already using a base58.. Any help would be appreciated

2 Answers 2

2

Looks like it is expecting you to have a keypair in your .env file.

You can just create that file next to your ts files and add the key

SECRET_KEY=[yourkeypair]

You can generate a new one like so:

solana-keygen grind --starts-with dev:1

and then copy the contents into your .env file

Then you can also get the address

solana address keypair.json 

and then airdrop some sol to it for example:

solana airdrop -k keypair.json
2
  • 1
    Hey! Thanks for the reply. I do have the key in my .env file it is in the same directory as the ts file in this format: SECRET_KEY="[(a series of numbers)]" Commented Jan 8 at 17:12
  • 1
    GOT IT! lol it was a syntax error.. I had [(numbers)] needed to remove () Commented Jan 8 at 17:16
0

I did the exact same as the steps but end up getting this error:

node:internal/process/esm_loader:34
      internalBinding('errors').triggerUncaughtException(
                                ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find module 'F:\web3-solana\generate-keypair\node_modules\.bin\node_modules\dotenv\config.js' imported from F:\web3-solana\generate-keypair\node_modules\.bin\esrun-1723786154129.tmp.mjs
Did you mean to import "../dotenv/config.js"?
    at finalizeResolution (node:internal/modules/esm/resolve:265:11)
    at moduleResolve (node:internal/modules/esm/resolve:933:10)
    at defaultResolve (node:internal/modules/esm/resolve:1157:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:390:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:359:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:234:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:87:39)
    at link (node:internal/modules/esm/module_job:86:36) {
  code: 'ERR_MODULE_NOT_FOUND',
  url: 'file:///F:/web3-solana/generate-keypair/node_modules/.bin/node_modules/dotenv/config.js'
}

Node.js v20.12.1

@GoodBurger Any idea how to resolve this, i have spent almost two-three hours but can't get rid of this issue. It only comes when i want to load the variable from .env file. Rest of the code is working fine as excepted.

1
  • my .env file is the same directory as the .ts file and the variable is also correct without any syntax error. Commented Aug 16 at 5:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.