Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

How do I create a wallet given a private key. #457

Unanswered
Gavin-Williams asked this question in Q&A
Discussion options

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.

You must be logged in to vote

Replies: 1 comment

Comment options

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;
}
You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /