Skip to main content

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’

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);

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’

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