Generate Keypair
The Keypair
object represents a key pair used to
sign transactions in a Stellar network. The Keypair
object can contain both a public and a private key, or only a public key.
If a Keypair
object does not contain a private
key it can’t be used to sign transactions. The most convenient method of
creating a new keypair is by passing the account’s secret seed:
1from stellar_sdk import Keypair
2
3secret = "SBK2VIYYSVG76E7VC3QHYARNFLY2EAQXDHRC7BMXBBGIFG74ARPRMNQM"
4keypair = Keypair.from_secret(secret)
5
6# GDHMW6QZOL73SHKG2JA3YHXFDHM46SS5ZRWEYF5BCYHX2C5TVO6KZBYL
7public_key = keypair.public_key
8
9can_sign = keypair.can_sign() # True
You can create a keypair from public key, but its function is limited:
1from stellar_sdk import Keypair
2
3public_key = "GDHMW6QZOL73SHKG2JA3YHXFDHM46SS5ZRWEYF5BCYHX2C5TVO6KZBYL"
4keypair = Keypair.from_public_key(public_key)
5can_sign = keypair.can_sign() # False
You can also create a randomly generated keypair:
1from stellar_sdk import Keypair
2
3keypair = Keypair.random()
4print("Public Key: " + keypair.public_key)
5print("Secret Seed: " + keypair.secret)