'Unable to derive Sollet wallet address using mnemonic phrases in Solana-web3
My understanding is Solana should be same as other blockchain, with the same mnemonic phrase and derived path, we should be able to produce the same public address. So, after obtaining mnemonic phrase, I wrote below code to check
const solanaWeb3 = require('@solana/web3.js');
const bip39 = require('bip39');
const ed = require('ed25519-hd-key');
const nacl= require('tweetnacl');
const mnemonic = "<mnemonic phrases>"
let path = "m/44'/501'/0'/0'";
const seed = bip39.mnemonicToSeedSync(mnemonic);
const derivedSeed = ed.derivePath(path, seed.toString('hex')).key;
const account = new solanaWeb3.Account(nacl.sign.keyPair.fromSeed(derivedSeed).secretKey);
keypair = solanaWeb3.Keypair.fromSecretKey(account.secretKey);
console.log(keypair.publicKey);
However, it gave me a completely different public address from my sollet wallet. Any idea of what went wrong?
Thanks in advance!
Solution 1:[1]
It could be that you're using a slightly different derivation path than the one shown. Looking through the Sollet code, you may want to try a path of m/44'/501'/0' instead. Check out where derivePath is used: https://github.com/project-serum/spl-token-wallet/blob/9c9f1d48a589218ffe0f54b7d2f3fb29d84f7b78/src/utils/walletProvider/localStorage.js#L25
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Jon C |
