1

I am using python-sdk to perform stellar operations. Now I need to validate a stellar address. I know that the JS sdk has got a function StrKey.isValidEd25519PublicKey(address); however I cannot find the same in Python SDK.

Any idea, how I can do this?

2 Answers 2

3

check this out: https://github.com/StellarCN/py-stellar-base/blob/6329db3658c9b646a69c567019d95b41b7363eee/stellar_base/utils.py#L251

def is_valid_address(address):
try:
    return decode_check('account', address)
except (DecodeError, TypeError):
    raise StellarAddressInvalidError('Invalid Stellar Address: {}'.format(address))
0

Thats how i have done it:

from stellar_sdk.exceptions import Ed25519PublicKeyInvalidError

def check_stellar_address(address):
    try:
        Account(account_id=address, sequence=0)
        return True

    except Ed25519PublicKeyInvalidError:
        return False

Your Answer

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

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