0

found nice examples generating verification keys and payment keys but I don't get to same time generate the seed phrase. Without the seed phrase I cannot open the wallet in a hot wallet to view it and so forth.

I simply do not understand the docs. here is api docs https://pycardano.readthedocs.io/en/latest/api/pycardano.crypto.html?highlight=seed%20phrase

1 Answer 1

1

You can take a look at this function that I am using to work with Hierarchical Deterministic Wallets in PyCardano. If the mnemonic file does not exist, it generates a new one and saves it to disk, and if it exists, it is using it.

def wallet_from_mnemonic(mnemonic_file: str, address_count: int = 1) -> dict:
    """Generate the wallet from a mnemonic phrase existing in a file on disk.
    If the mnemonic file does not exist, generate a new mnemonic and save it.
    """
    try:
        with open(mnemonic_file, "r") as f:
            mnem = f.read().strip()
    except FileNotFoundError:
        mnem = HDWallet.generate_mnemonic()
        with open(mnemonic_file, "w") as f:
            f.write(mnem)
    hdw = HDWallet.from_mnemonic(mnem)

    """
    Derive the staking key
    """
    stk = hdw.derive_from_path(stake_derivation_path)
    stk_skey = StakeExtendedSigningKey.from_hdwallet(stk)
    stk_vkey = StakeExtendedVerificationKey.from_signing_key(stk_skey)

    """
    Derive the first payment address
    """
    wlts = {}
    for i in range(address_count):
        payment = hdw.derive_from_path(payment_derivation_path[0:-1] + str(i))
        p_skey = ExtendedSigningKey.from_hdwallet(payment)
        p_vkey = 
PaymentExtendedVerificationKey.from_signing_key(p_skey)
        p_addr = Address(p_vkey.hash(), stk_vkey.hash(), network)
        wlts[i] = {
            'addr': p_addr,
            'skey': p_skey,
            'vkey': p_vkey
        }
    return wlts
1
  • great I'll try it. Even if I however generated new wallets with more info already
    – Mik_A
    Commented Sep 26, 2023 at 13:22

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.