-
Notifications
You must be signed in to change notification settings - Fork 153
How do I create a wallet given a private key. #457
-
There is no wallet constructor for when we have a private key. I just don't know how to proceed. I searched for Keypair, but there is no utility class for generating a keypair from a private key.
I'm guessing that you call the private key the 'seed' ? Then I would need a utility function to convert a private key into a byte[] representation of the private key.
Update: I'm going to install the Solana CLI - I bet it's got all sorts of useful tools.
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 1 comment
-
There is a method in the newest source code (Account.FromSecretKey()), but unfortunately this isn't available in the latest release (which for some reason was last updated 3 years ago :/). For example if you downloaded the packages from NuGet. However, you can still implement this function manually in your code. It's under src/Solnet.Wallet/Account.cs I have not tested it yet, but I hope this works:
public static Account FromSecretKey(string secretKey) { var B58 = new Base58Encoder(); byte[] skeyBytes = B58.DecodeData(secretKey); if (skeyBytes.Length != 64) { throw new ArgumentException("Not a secret key"); } Account acc = new Account(skeyBytes, skeyBytes.AsSpan(32, 32).ToArray()); return acc; }
Beta Was this translation helpful? Give feedback.