Why are there two owners in the get getParsedProgamAccounts response | Solana

56 views Asked by At

I implemented the following code and I am confused by the response:

async function getTokenAccounts(wallet: string) {
        const filters:GetProgramAccountsFilter[] = [
            {
              dataSize: 165, // number of bytes
            },
            {
              memcmp: {
                offset: 32, // number of bytes
                bytes: wallet, // base58 encoded string
              },            
            }];
        const accounts = await connection.getParsedProgramAccounts(
            TOKEN_PROGRAM_ID, // new PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
            {
              filters: filters,
            }
          );
          
        console.log(`Accounts`+ JSON.stringify(accounts))

Here the response:

{
        "account": {
            "data": {
                "parsed": {
                    "info": {
                        "isNative": false,
                        "mint": "DevGvK5Z7dPJmcFv5WWG6Ezo1qykNRQShgLSqeQieAsq",
                        "owner": "FY6RKTw4YZmMmP2uB5wp7pjao9HWVXzTc9P7fjRV79JH",
                        "state": "initialized",
                        "tokenAmount": {
                            "amount": "100",
                            "decimals": 0,
                            "uiAmount": 100,
                            "uiAmountString": "100"
                        }
                    },
                    "type": "account"
                },
                "program": "spl-token",
                "space": 165
            },
            "executable": false,
            "lamports": 2039280,
            "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
            "rentEpoch": 18446744073709552000,
            "space": 165
        },
        "pubkey": "8dYdhrh9i9hfEvVCPL1XE5tPikpWeZDVbM2DDLSVHQgU"
    }

I am confused about the two "owner" properties. The SPL token DevGvK5Z7dPJmcFv5WWG6Ezo1qykNRQShgLSqeQieAsq is held by the wallet FY6RKTw4YZmMmP2uB5wp7pjao9HWVXzTc9P7fjRV79JH but I don't understand why the Token Program is also listed as the owner of the account TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA?

Any advice would be highly appreciated.

1

There are 1 answers

0
Jon C On

The term "owner" is overloaded in the context of SPL token accounts.

Generally, every account on the Solana blockchain has an "owner", which is the program that is permitted to modify its data and deduct its lamports: https://docs.solana.com/developing/programming-model/accounts#ownership-and-assignment-to-programs

So all SPL token accounts are owned by the SPL token program TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA.

Within the data of the account, however, is an "owner" field. The SPL token program interprets those 32 bytes in the account to mean the pubkey that is allowed to deduct funds in the SPL token account, among other things.