Logo

A Deep Dive Into Solana's Data Structure

How to recover data from the blockchain

About The Workshop

The goal of this workshop is to discover through some examples how the data on the Solana blockchain works and how to recover this data

How does it work?

Slides link

Practice Time

Getting started

# Clone the repository (you can also click "Use this template")
git clone https://github.com/sonarwatch/solana-workshop.git solana-workshop
cd solana-workshop

...
# Install dependencies
yarn install

# Run steps files
.\node_modules\.bin\ts-node-dev .\src\step01.ts

# Run main.ts file
yarn dev # runs main.ts file
...

Step 01

In this step we get the account info of the USDC token. For this we use connection.getAccountInfo. We obtain some data as a Buffer that we will decode in the next step.

Step 02

In this step we decode the USDC token data. For that we decode the buffer thanks to the MintAccountStruct. MintAccountStruct is based on the Metaplex Beet library.

Step 03

In this step, we get the account info a USDC token account. For this, we use connection.getAccountInfo. We obtain some data as a Buffer that we will decode in the next step.

Step 04

In this step we decode the USDC token data. For that we decode the buffer thanks to the TokenAccountStruct. TokenAccountStruct is based on the Metaplex Beet library.

Step 05 - TODO

In this step, the goal is to display the amount of each token that a wallet has. For this there are several steps:

  1. Get all tokens accounts of a wallet, then decode them with connection.getProgramAccounts, then decode them with TokenAccountStruct.
  2. Get all the mints and get the accounts info with getMultipleAccountsInfo, then decode mints accounts with MintAccountStruct
  3. Divided step 1 amounts by step 2 decimals
  4. Display tokens amounts in the console
  5. Display mints as symbols thanks to Solana token list

(back to top)

Go further

You can go further and try to decode other accounts. Here are two examples you can start with:

Solana Staking (StakeAccount)

You can recover your staking accounts.

Marinade Finance (TicketAccountData)

On Marinade, When you choose 'Delayed unstake' your mSOL, these operations happen under the hood:

  1. You are given a claim ticket indicating the amount and due time of your unstake.
  2. mSOL is burnt and removed from the supply.
  3. The unstake operation is launched and performed by the bot.
  4. At due time, you will be able to claim your SOL and destroy the claim ticket in exchange. (A claim ticket has no expiry date.)

What you can do is try to decode the TicketAccount.

Jet Staking (StakeAccount)

Jet Protocol has a governance program where you can stake $JET tokens. You can try to decode your StakeAccount to find out how many $JET you have staked.

(back to top)

Useful Links

(back to top)

Contact

(back to top)