Generating & Parsing Wallet Keypairs
GENERATING WALLET SEED or KEYPAIR (PUBLIC / SECRET KEY).
Using a compatible stellar SDK, you can generate a seed. Once a seed is generated, you can parse it and get the entities like the Secret key and public key corresponding to it.
Please note that all secret keys start with ‘S’. All public keys start with something like ‘G’, but not a number and not ‘S’
- NodeJS
- Go
- Python
import { Keypair } from "@stellar/stellar-sdk";
// Generate a random Stellar keypair
const pair = Keypair.random();
// Get the secret seed and public key
const secret = pair.secret();
const publicKey = pair.publicKey();
console.log("Secret Seed:", secret);
console.log("Public Key:", publicKey);
package main
import (
"fmt"
"github.com/stellar/go/keypair"
)
func main() {
// Generate a random Stellar keypair
pair, err := keypair.Random()
if err != nil {
panic(err)
}
// Get the secret seed and public key
secret := pair.Seed()
publicKey := pair.Address()
fmt.Println("Secret Seed:", secret)
fmt.Println("Public Key:", publicKey)
}
from stellar_sdk import Keypair
# Generate a random Stellar keypair
pair = Keypair.random()
# Get the secret seed and public key
secret = pair.secret
public_key = pair.public_key
print("Secret Seed:", secret)
print("Public Key:", public_key)
If you already have your seed, but you need to obtain the keypair from it so as to know the public key corresponding to it, then you need to PARSE YOUR SECRET KEY
PARSING A SEED/SECRET KEY INTO A KEYPAIR
If you already have your secret key and you need to get the public key from it or parse it to be sure it is valid, then you need to use the correct method to parse it so that you obtain the secret key and public key from it.
Please note that all secret keys start with ‘S’. All public keys start with something like ‘G’, but not a number and not ‘S’
- NodeJS
- Go
- Python
import { Keypair } from "@stellar/stellar-sdk";
// Your Stellar secret seed (starts with 'S')
const seed = "SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";
// Parse the seed to get the Keypair object
const keypair = Keypair.fromSecret(seed);
// Access the public key and raw key material
console.log("Public Key:", keypair.publicKey());
console.log("Raw Secret (Buffer):", keypair.rawSecretKey()); // Uint8Array of bytes
package main
import (
"fmt"
"github.com/stellar/go/keypair"
)
func main() {
// Your Stellar secret seed (starts with 'S')
seed := "SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
// Parse the seed to get the Keypair object
kp, err := keypair.ParseFull(seed)
if err != nil {
panic(err)
}
// Access the public key
fmt.Println("Public Key:", kp.Address())
fmt.Println("Secret Seed:", kp.Seed())
}
from stellar_sdk import Keypair
# Your Stellar secret seed (starts with 'S')
seed = "SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
# Parse the seed to get the Keypair object
keypair = Keypair.from_secret(seed)
# Access the public key and raw key material
print("Public Key:", keypair.public_key)
print("Raw Secret (bytes):", keypair.raw_secret_key())