1

I'm trying to read user staked validator information using @solana/web3.js. I was able to read the stake accounts for the given wallet address but having trouble with reading staked validator information(name, APY, etc...). Here's the code that I've used to read stake accounts.

cosnt stakeAccounts = await connection.getParsedProgramAccounts(
                StakeProgram.programId,
                {
                    filters: [
                        {
                            memcmp: {
                                offset: 12, // number of bytes
                                bytes: wallet.publicKey.toBase58(), // base58 encoded string
                            },
                        },
                    ],
                },
            );

I've tried to read the stake account information like below, but it returns an empty array.

const stakeAccountInfo = await connection.getParsedProgramAccounts(
                        new PublicKey("Config1111111111111111111111111111111111111"),
                        {
                            filters: [
                                { memcmp: { offset: 124, bytes: accountData instanceof Buffer ? account?.pubkey?.toString() : accountData?.parsed?.info?.stake?.delegation?.voter } },
                                { dataSize: 200 }  // Stake account data length
                            ]
                        }
                    );

1 Answer 1

1

The validator config account is totally different from a stake account, so you'll need to fetch it using different parameters. And the config program is a bit strange. Here's how to get all config program accounts:

const validatorInfos = await connection.getParsedProgramAccounts(
                        new PublicKey("Config1111111111111111111111111111111111111"),
                        {
                            filters: [
                                { memcmp: { offset: 1, bytes: new PublicKey("Va1idator1nfo111111111111111111111111111111").toBase58() } },
                            ]
                        }
                    );

You'll get entries that look like:

    {
      "account": {
        "data": {
          "parsed": {
            "info": {
              "configData": {
                "name": "kiwami.sol +MEV🚀"
              },
              "keys": [
                {
                  "pubkey": "Va1idator1nfo111111111111111111111111111111",
                  "signer": false
                },
                {
                  "pubkey": "4PVf8hUmukCp5i5RempNVYnzzfh2NtTnPkoFDonpZyVb",
                  "signer": true
                }
              ]
            },
            "type": "validatorInfo"
          },
          "program": "config",
          "space": 643
        },
        "executable": false,
        "lamports": 5366160,
        "owner": "Config1111111111111111111111111111111111111",
        "rentEpoch": 18446744073709551615,
        "space": 643
      },
      "pubkey": "4dUSzymwCJLJCDXjxgS6V7UehvA9EUFTZNUKjgdQ3mH7"
    }

And you'll need to search for the validator's vote account in the second entry in keys.

1

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.