2

I want to generate an kusama address. The substrate-interface can make it?Or how to generate an ss58 format address by python

1 Answer 1

2

You need to provide the SS58 prefix to the create_from_mnemonic function to make it generate a Kusama address as opposed to a generic Substrate address:

from substrateinterface import Keypair

# 2 for Kusama.
prefix = 2
# If you want to use a random mnemonic:
mnemonic = Keypair.generate_mnemonic()
# ... or use a specific mnemonic:
mnemonic = 'episode together nose spoon dose oil faculty zoo ankle evoke admit walnut'

keypair = Keypair.create_from_mnemonic(mnemonic, ss58_format=prefix)
# Prints JHXFqYWQFFr5RkHVzviRiKhY7tutyGcYQb6kUyoScSir862
print(keypair.ss58_address)

Kusama has the prefix 2, you can see all of them in the ss58-registry.

2
  • Also you can add Keypair.generate_mnemonic() to the anwser above to generate a new address
    – Arjan
    Commented Sep 8, 2022 at 18:26
  • Thanks, I appreciate you answering the Python questions! Commented Sep 9, 2022 at 10:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.