Managing Wallets

Load a Solana Wallet ('Keypair')

Every interaction with the Solana blockchain revolves around a wallet which needs to sign (and pay for) transactions.

A keypair consists of two keys - a 'public key' (or 'pubkey') and a 'secret key'. It is crucial that you keep the secret key secure at all times, as this alone is required to approve any transaction on behalf of the wallet it controls.

You can think of a keypair as analogous to a web2 API key and secret. It is required to be provided as part of requests to demonstrate authorization.

Reload an Existing Wallet

You can reload an existing Keypair using a secret key, which can be stored somewhere (such as in a Secret Manager tool, a .env file or in some other secure local storage) in bytes or in some representation of bytes.

In this example, a Keypair is reloaded from a base58 encoded secret key.

import base58
from solana.keypair import Keypair

secret_key = base58.b58decode('zSaKmpRbsJQQjmMRQsADRQ1vss8P2SQLbxGiiL8LFf9rJ8bFT8S1jAqj8Fkwg9hyq6vb97rR8EDkyu5EFD2tFbj')

owner_keypair = Keypair.from_secret_key(secret_key)

print(f'Keypair loaded with public key {owner_keypair.public_key}')

Create a New Wallet

If you do not already have a keypair, it's easy to generate one. If you intend to access this wallet again, just be sure to safely store the secret key for future recall.

import base58
from solana.keypair import Keypair

new_keypair = Keypair()
b58encoded_secret = base58.b58encode(new_keypair.secret_key)
new_pubkey = new_keypair.public_key

# Save this secret somewhere safe.
# It might be useful to identify/index it by the corresponding public key

Last updated