1

How can I deserialize data after a getProgramAccounts with JS ?

const accounts = await provider.connection.getProgramAccounts(program.programId);

console.log(accounts[0])

I see the log result:

  account: {
    data: <Buffer be df 51 6f 82 fb bb ca ff d3 4c 06 a2 31 97 98 75 d2 ab d2 aa 0f d3 bf 11 0c 68 9e 5f 7c 39 93 e7 6a 29 d8 fc fd 11 45 9d 00 00 00 00 00 00 00 00 00 ... 8950 more bytes>,
    executable: false,
    lamports: 63530880,
    owner: PublicKey {
      _bn: <BN: d380ccf0a95046f20a230a04b227a821f27fd7f0bf09efc9b7df5a511338d251>
    },
    rentEpoch: 367
  },
  pubkey: PublicKey {
    _bn: <BN: f9eaae395abbef69151e3d007ab25c5b6cf2080cf68f641b799538ee766122c1>
  }
}

I would like to have the data in the account human-readable.

I have tried without success to deserialize it to JSON.

1 Answer 1

2

In JS you should instead use getParsedProgramAccounts

RPC there's an optional encoding parameter. Encoding for account data can be either: base58, base64, or jsonParsed.

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.