Skip to content
Advertisement

Trying to test Wallet instantiation in Solana JS

I’m trying to follow some code to test out instantiating a wallet in code. I’m hardcoding private key (will not do this in prod obviously) just to see how everything works. I’m getting this error:

JavaScript

My code is as below:

JavaScript

Advertisement

Answer

So the issue here was the encoding. For ease of use, it’s best to use the phantom wallet. I tried converting the seed to bs58 but I was still unsuccessful. If you insist on using another wallet and are using the .js web3 library for Solana, you’d probably be better off using

const wallet = new Wallet(Keypair.fromSecretKey(new Uint8Array([1,2,3,4,5,6]))) but this would require you to keep your private key array exposed which is not recommended.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement