DEV Community

Cover image for Solana Development 101: What are Accounts, Programs, Transactions and more....
Web3 Space
Web3 Space

Posted on

Solana Development 101: What are Accounts, Programs, Transactions and more....

๐Ÿ˜Ž Solana has three things

  • Transactions
  • Programs (Smart contracts)
  • Accounts

  • Solana is a big computer that anyone can use to run and store their code for a fee. Deployed code is called Program.

  • To interact with a program we send transactions to the blockchain from a client

Solana

๐Ÿ™‚ We can interact with out program using Json RPC APIs having HTTP and Websockets methods.

HTTP methods

curl http://localhost:8899 -X POST -H "Content-Type: application/json" -d '
  {
    "jsonrpc": "2.0",
    "id": 1,
    "method": "getBalance",
    "params": [
      "83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri"
    ]
  }
'
Enter fullscreen mode Exit fullscreen mode
  • Requests can be send in batches.
  • Commitment parameters are of three types
    • finalized (By default)
    • confirmed
    • processed
  • when we request commitment in the API the response comes with RpcResponse structure
    • It has two fields context and value
  • We can provide filters also in the request to enable pre filtering of the data
  • HTTP API have so many methods like getAccountInfo, getBalance etc
  • Similarly Websockets can submit subscription requests to the sockets using commitment parameter defining how a change should be to trigger a notification
  • Real-time Updates: WebSockets are used to establish a persistent, bidirectional communication channel between clients and Solana nodes. This enables real-time updates and notifications, which is particularly useful for applications requiring live data.
  • Subscription Mechanism: Clients can subscribe to specific events or data streams using WebSocket connections. For example, a client may subscribe to block notifications, new transactions, or changes in specific accounts.

From client side, we can submit transactions with instructions via client SDK to build a variety of dApps.

Wallets

It is a pair of Public and Private keys. Private key is used to sign the transactions and public key is to verify the actions.

Transactions

It is a set of instructions box with some extra things and we need a transaction to create, update, delete data on the chain but we dont need it when we want to read the data only

Solana Transaction Structure

It is a fundamental unit of activity on solana to run the program. It has Signatures and Message.

Signatures is an array of digital signatures of transactionโ€™s signers

Message has fields like Header, Account addresses, Recent Blockhash and Instructions

  • Header has 3 uint8 which gives the info of
    • No. of accounts that needs to sign the payload
    • No. of accounts that wont sign
    • No. of accounts that are read only
  • Account addresses:- An array of addresses that will be used in this txn
  • Recent blockhash to ensure the txn is not too old and is not reprocessed

Instructions

Item Description
Program ID The ID of the program being called
Accounts The accounts that the instruction wants to read or modify
Data Input data provided to the program as additional information or parameters in the format of a byte array

Transaction Fees

Every time we run a transaction somebody on the network is providing us the resources and thus fees needs to be paid from us in lamports which is the smallest unit of SOL crypto currency. 1SOL = 1,000,000,000 lamports.

This fees will be paid/distributed among the validators who provide us the resources.

It is calculated from:

  • a statically set base fees per signature
  • computational resources used during execution

Accounts

These are the storage spaces on the chain. Program doesnโ€™t hold any data if next transaction needs some previous state then it needs to go to the account. It is like a file which can hold some data and Program can talk to the File or Account. Account who stores the Program data is marked as executable and can process instructions.

Itโ€™s address is a 256bit public key and can store upto 10MB of data. When an account is created it is assigned some space and to rent this space account should have some enough tokens to cover the rent otherwise it will be removed alongwith the data. If it holds rent for 2 years then it is considered as rent-exempt and wonโ€™t be deleted.

Programs

Programs are responsible from creation of accounts, running instructions to collection of fees and more. They process instructions from both end user or other programs. Programs are stateless and the data they use is generally stored in the accounts that are passed via params. There are two types of Solana programs:-

  • Native Programs are used for transferring SOL, creating Accounts, assigning ownership etc
  • Solana Program Library programs are used for creating, swapping and lending tokens, generating stake pools and maintaining on-chain name service (referring to giving human readable names, maintaining a decentralized naming registry for domain names etc).

We can build dApps on top of Native Programs and SPL using CLI only without writing rust. Also we can use public addresses of some programs to build on top of them. We need to know their structure, accounts and error codes etc.

In our Next Blog, we'll see how to code a Hello World in rust and deploy as a Program on Solana Chain.

๐Ÿ”ฅ *Follow for more *

Top comments (0)