2

New to solana, going through my first tut.

The first task is to generate a keypair from the web3.js package.

my file --

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!`);

my output --

SyntaxError: Octal escape sequences are not allowed in strict mode.
    at ESMLoader.moduleStrategy (node:internal/modules/esm/translators:139:18)
    at ESMLoader.moduleProvider (node:internal/modules/esm/loader:236:14)     
    at async link (node:internal/modules/esm/module_job:67:21)

I don't think this is a solana error but the stuff I'm finding online about this is pretty obscure and less than helpful. Does anyone know why I'm getting this.

here is how I'm calling the file -

npx esrun genKeyPair.ts

my package.json

{
  "name": "generate-keypair",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@solana-developers/node-helpers": "^1.2.1",
    "@solana/web3.js": "^1.87.6",
    "esrun": "^3.2.26",
    "typescript": "^5.3.3"
  }
}


11
  • This is for sure not a Solana specific issue, but rather a JS/TS related issue. What is your local setup for this? I see you using esrun but no other details here.
    – nickfrosty
    Commented Jan 3 at 18:49
  • do you have the npm packages installed?
    – nickfrosty
    Commented Jan 3 at 18:49
  • I'm guessing this is a typescript issue. Try turning off strict mode via your tsconfig.json
    – nickfrosty
    Commented Jan 3 at 18:50
  • Yes so I've followed this step by step soldev.app/course/intro-to-cryptography
    – 4cody
    Commented Jan 3 at 19:29
  • 1
    @4cody sounds like this is a warning from some node internal code, in the ESM loader node:internal/modules/esm/loader:236:14 - what version of node.js are you using? Can you try upgrading to the current latest 18x or 20.x?
    – mikemaccana
    Commented Jan 4 at 18:09

1 Answer 1

2

Upgrade your node.js

The error is in node's inbuilt modules (anything that starts with node: is code that comes with node.js itself). There's an octal escape sequence like \033 in one of these inbuilt files and it shouldn't be there. In short: there was a bug in node.js itself.

But your code works fine on node 20.6.0

% node -v
v20.6.0

Running it:

% npx esrun genKey.ts
✅ Generated keypair!
3
  • 1
    This somewhat fixed my issue. I'm still getting the octal error but I'm able to see an expected printout of the desired console log --- "generated keypair" Thanks
    – 4cody
    Commented Jan 5 at 18:08
  • Interesting - what does node -v return?
    – mikemaccana
    Commented Jan 8 at 19:41
  • it returns v20.6.0
    – 4cody
    Commented Jan 9 at 20:13

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.