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!
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.