0

Is there a way to know whether an address is an token Program/Storage/Data/Vote/Stake/Withdraw account from the format only? If not, how can I find this out with the help of the node RPC?

I guess I could call this and check the owner property (Vote111111111111111111111111111111111111111 or Stake111111111111111111111111111111111111111). But is this really the way to do it?

curl --location 'https://api.mainnet-beta.solana.com' \
--header 'Content-Type: application/json' \
--data '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getAccountInfo",
    "params": [
        "G9x1mqewTeVnXLmv3FamYD5tq1AdS395RHH3MLQPj6TY",
        {
            "encoding": "base64"
        }
    ]
}'
{
    "jsonrpc": "2.0",
    "result": {
        "context": {
            "apiVersion": "1.16.21",
            "slot": 237193626
        },
        "value": {
            "data": [
                "...",
                "base64"
            ],
            "executable": false,
            "lamports": 2382905146621,
            "owner": "Vote111111111111111111111111111111111111111",
            "rentEpoch": 0,
            "space": 3731
        }
    },
    "id": 1
}

2 Answers 2

0

Yeah, you can check owner and whether the account is on the curve or off the curve. Guessing an account's type solely by its public key is impossible, as they all follow the same ed2559 curve for cryptography. When an account is a PDA, they don't fall on the ed2599 curve and hence don't have a private key. For other types accounts, they have a private key so the only way to check their type is via the owner attribute.

0

You've answered your own question! Since account data is just presented as bytes, you need to be aware of the format used by the owning program.

Stake accounts, owned by Stake111111111111111111111111111111111111111, are encoded in one particular way, and vote accounts, owned by Vote111111111111111111111111111111111111111, are encoded differently.

Some programs publish their IDL (interface description language) on-chain, which gives information about how to decode accounts and instructions, so you can fetch and use those too. Anchor is the most popular framework which does that: https://github.com/coral-xyz/anchor

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.