I want to validate the address of solana either is valid or invalid by using python how could I do that?like in web3.py we validate an ethereum account/address and it returns false or true as output.
You can use web3.js
new PublicKey('your_address') to verify if it is a valid public key.
web3.js also provides
PublicKey.isOnCurve(...) to validate if a public key is on
ed25519 curve. Given there are PDAs in Solana, and that their addresses are valid public key, but are NOT on the curve.
To summarize: If you are able to instantiate, it means it is a valid public key, if you want to know if the address is on the curve, you need to further validate by calling
Just noticed that you wanted an answer specific to python, depending on the client that you are using, there should be similar methods to use. One that I found is in solana-py, use the PublicKey object to validate.
Actuall there's no function available in python Sep 28, 2022 at 5:37
you don't have isOnCurve(), but just try to instantiate by using new PublicKey(...) -> if this throws error, it is not valid. Sep 28, 2022 at 6:08
Pubkey.is_on_curve: kevinheavey.github.io/solders/api_reference/… Oct 2, 2022 at 1:22
The examples in solders don't always work as intended. This is the current working example:
address = 'solana address'
sol_addr = Pubkey.from_string(address)
if sol_addr.LENGTH == 32:
print ('passed test2')
These are the two major ways of validating a Sol address. Another way is to use the pair, but there are many dexes too on Sol so that won't be too solid.
0x0euuejei isn't a valid base58 pubkey, probably better to use a valid one in the example Mar 11 at 18:07
Yeah edited to : solana address , for a better understanding– thewiseMar 12 at 8:01
Also what doesn't work in Solders? Mar 13 at 18:10
The example given on solders webpage doesn't include converting the address from a string(Pubkey.from_string('address'), though the API , in venv file houses the example, you need to first convert from a valid string else you won't be able to run the rest of the code on the address. Same with converting to string , Pubkey.string() doesn't work, but Str('address') works perf– thewiseMar 14 at 20:25
can you share a link to the part of the docs that is incorrect please? Mar 14 at 21:25