1

I am using this code to fetch my local wallet:

const userWallet = web3.Keypair.fromSecretKey(new Uint8Array(fs.readFileSync(WALLET_PATH)));

But I got the following error:

Error: bad secret key size

1 Answer 1

2

The file at WALLET_PATH is your keypair encoded as JSON, and your code is trying to interpret the characters in the JSON file as raw bytes. You'll need to JSON-decode the contents of the file, and then pass them into fromSecretKey. I haven't run this, but something like this should do it:

const userWallet = web3.Keypair.fromSecretKey(new Uint8Array(JSON.parse(fs.readFileSync(WALLET_PATH))));

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.