简体   繁体   English

如何从秘密短语(助记符)SOLANA 生成密钥对

[英]how to generate keypair from secret phrase (mnemonic) SOLANA

I am working with solana and phantom wallet I have a wallet with a public key and I have it's secret phrase composed of 12 wordw.我正在使用 solana 和幻像钱包我有一个带公钥的钱包,我有一个由 12 个 wordw 组成的秘密短语。 when I generate keypairs from the secret phrase I use :当我从我使用的秘密短语生成密钥对时:

const getKeyPair = (mnemomic) => {
  const seed = bip39.mnemonicToSeedSync(mnemomic).slice(0, 32);
  const Keypair = web3.Keypair.fromSeed(seed);
  return Keypair;
};

the generated keypair has publicKey and privateKey , but when am checking my balance using the generated public key I find the balance is always 0 even when I try to airdrop sols using my code it's not getting in the account.生成的密钥对具有 publicKey 和 privateKey ,但是当我使用生成的公钥检查我的余额时,我发现余额始终为 0,即使我尝试使用我的代码空投 sols 也没有进入帐户。

But if I check using my public key from phantom wallet I get the sols I have and if I want to airdrop sols they also proceed normally.但是,如果我使用幻像钱包中的公钥进行检查,我会得到我拥有的 sols,如果我想空投 sols,它们也会正常进行。

Why is my generated public key is not the same as the one in phantom wallet?为什么我生成的公钥与虚拟钱包中的不一样?

First, we need to generate the publicKey and privateKey from the seed phrase using this command :首先,我们需要使用以下命令从种子短语生成publicKeyprivateKey

solana-keygen recover 'prompt:?key=0/0' -o phantom_wallet.json solana-keygen 恢复 'prompt:?key=0/0' -o phantom_wallet.json

remark : our account may have many wallets the command above access the first wallet , if we need to access wallet number 10 for example we need to change the 'prompt:?key=0/0' to 'prompt:?key=10/0' "only the first 0 is changing"备注:我们的账户可能有很多钱包上面的命令访问第一个钱包,如果我们需要访问10号钱包例如我们需要将'prompt:?key=0/0'更改为'prompt:?key=10/ 0' "只有第一个 0 在改变"

next this will generate public key "will be written in the console" and a json file with secret key contains an array of 64 element which is the secret key .接下来,这将生成公钥“将写入控制台”,并且带有密钥的 json 文件包含一个64 元素的数组,即密钥 now to generate the KEYPAIRS in solana web3 javascript SDK we do the following:现在要在 solana web3 javascript SDK 中生成密钥对,我们执行以下操作:

 let seed = Uint8Array.from(
    process.env.REACT_APP_OUR_SECRET_KEY.split(",")
  ).slice(0, 32);

  // create keypairs
  let KEYPAIRS = web3.Keypair.fromSeed(seed);

IMPORTANT : in .env files REACT_APP_OUR_SECRET_KEY is stored without brackets [ ] example : 15,320,52,... as we see a table without brackets [ ]重要提示:在 .env 文件中,REACT_APP_OUR_SECRET_KEY 存储时不带括号 [] 示例:15,320,52,... 因为我们看到的表格不带括号 []

solana-keygen recover 'prompt:?key=0/0' -o phantom_wallet.json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 Solana 的助记词中获取正确的公共地址? - How to get proper public address from mnemonic phrase for Solana? 从 window.crpyto.subtle.generateKey 生成助记词 - Generate Mnemonic Phrase from window.crpyto.subtle.generateKey 如何仅从用户的公钥(Solana)中获取用户的密钥对? - How to get a user's keypair from their public key only (Solana)? 如何为 Solana javascript API 创建 web3.Keypair 对象? - How to create web3.Keypair object for Solana javascript API? blockchain.info如何生成助记密码? - How does blockchain.info generate the mnemonic passphrase? 如何为 React Native Expo 快速生成 RSA 密钥对 - How to quickly generate an RSA Keypair for React Native Expo 索拉纳区块链。 如何生成私钥? - Solana blockchain. How can i generate private key? 如何为MAC密钥生成OpenID共享密钥? - How to generate an OpenID shared secret for a MAC key? Spotify-如何/在何处生成ENCRYPTION_SECRET? - Spotify - How/Where to generate ENCRYPTION_SECRET? 如何使用 @solana/web3.js 从 Solana 中的自定义令牌中删除铸币权限? - How do I remove the minting authority from my custom token in Solana using @solana/web3.js?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM