4

I have stored information in the following account:

#[account]
pub struct user{
    name: String,
    age:  u64
}

I want to get this information from chain and display it on my frontend using Reactjs.

What are the solana/web3js commands to access data stored in accounts on chain

0

1 Answer 1

3

If you're using Anchor (which I recommend), you can use fetch to decode account data easily.

If you're not using Anchor you need to specify the structure and decode it using something like borsh.

Here is an example

const schema = new Map([[Test, { kind: 'struct', fields: [['x', 'u8'], ['y', 'u64'], ['z', 'string'], ['q', [3]]] }]]);

const newValue = borsh.deserialize(schema, decoded, buffer);

Example I wrote of decoding Metaplex Metadata

1
  • 1
    can you guide me about fetch? I tried googling it but couldn't find much
    – fahad
    Aug 18, 2022 at 5:23

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.