Cover Image for Understanding Solana: A Comprehensive Exploration of Instructions and its Types

Understanding Solana: A Comprehensive Exploration of Instructions and its Types

Blockchain
Analysis

Solana is a blockchain platform designed for high-speed and low-cost transactions, making it ideal for decentralized applications (DApps). We need Solana because it addresses scalability issues faced by other blockchain networks, allowing for faster and cheaper transactions. In the blockchain space, Solana's significance lies in its ability to support a wide range of DApps while maintaining efficiency and security.

Bitquery Solana APIs help analyzing Solana instructions, enabling developers and researchers to explore and understand transactional data on the Solana blockchain easily. In this blog, we will use these APIs to see in detail about the nature of Solana instructions and their types.

Overview of Solana’s transactions and instructions.

What are Solana Instructions?

Solana Instructions are commands or operations that dictate specific actions within the Solana blockchain, such as transferring tokens, executing smart contracts, or updating data.

Why do we need Solana Instructions?

We need Solana Instructions to interact with and utilize the functionalities provided by the Solana blockchain. They serve as the fundamental building blocks for performing various tasks and transactions within decentralized applications (DApps) and smart contracts.

We use Solana Instructions wherever there is a need to execute specific actions on the Solana blockchain. This could include sending tokens, deploying smart contracts, interacting with decentralized finance (DeFi) protocols, or any other activity that requires blockchain-based computation.

To utilize Solana Instructions, developers typically engage with the Solana blockchain via its software development kits (SDKs), command-line interfaces (CLIs), or directly through smart contracts. Through these interfaces, users provide the necessary parameters and invoke specific instructions to execute desired actions on the Solana network.

What is a transaction and how is it related to instruction?

A transaction is like a complete package of actions or operations that a user wants to perform on the Solana blockchain. It typically includes multiple instructions bundled together. For example, if you want to send tokens and update some data on the blockchain, you would combine these actions into a single transaction.

It is made up of one or more instructions, and each instruction represents a specific action or task within that transaction.

As transactions occur on the Solana blockchain, data is recorded in tables. Raw Solana tables initially present this data in an encoded format, which can be complex for human users to decipher. However, by decoding these tables, the information is transformed into a more human-readable format, facilitating easier interpretation and understanding. This decoding process ensures that users can effectively analyze and extract meaningful insights from Solana transactional data, aiding in various development, research, and analytical endeavors.

We require raw and decoded Solana tables for effective analysis and comprehension of Solana transactions and instructions. Raw tables offer a detailed view of the underlying data structure, while decoded tables simplify the information for easier interpretation, aiding developers, researchers, and analysts in understanding transactional data and identifying relevant details.

Introduction to Solana's instruction columns

Solana's instruction column is a key component of its blockchain technology. It's like a set of instructions that tell the Solana network what actions to take. Think of it as a recipe book for the blockchain.

We need this instruction column because it helps the Solana network understand what users want to do. Whether it's transferring tokens, executing a smart contract, or any other action on the blockchain, these instructions guide the network in performing those tasks efficiently.

We use the instruction column whenever we interact with the Solana blockchain. For instance, when you send tokens to someone, your wallet sends an instruction to the Solana network through this column, telling it to deduct tokens from your account and add them to the recipient's account.

Now, let's break down the meanings of some common instruction types in Solana:

Solana Transfer Info

This instruction tells the network to move tokens from one account to another. It's like transferring money from one bank account to another.

The query below retrieves detailed information about a single transfer instruction executed on the Solana blockchain at a specific block height. It fetches data such as the block height, timestamp, transaction details including signature, fee payer, and success status, program information including ID, name, and parsed name, and log details such as the total gas consumed during the transaction. The query is limited to fetching the transfer instruction at the specified block height.

open this query in IDE

{
  solana(network: solana) {
    instructions(
      options: {limit: 1, desc: "block.timestamp.time"}
      parsedActionName: {in: ["transfer"]}
      height: {is: 254313029}
    ) {
      block {
        height
        timestamp {
          time
        }
      }
      transaction {
        signature
        feePayer
        success
      }
      program {
        id
        name
        parsedName
      }
      log {
        totalGas
      }
    }
  }
}

Delegate

With this instruction, you're assigning someone else to handle certain tasks or decisions on your behalf. In Solana, it's often used for staking or voting.

This query aims to retrieve the signature and success status of the most recent successful "Delegate" instruction on the Solana blockchain occurring after March 20, 2024.

open this query in IDE

{
  solana(network: solana) {
    instructions(
      options: {limit: 1, offset: 1, desc: "block.height"}
      parsedActionName: {in: ["delegate"]}
      success: {is: true}
      time: {after: "2024-03-20"}
    ) {
      transaction {
        signature
        success
        transactionIndex
      }
      externalAction {
        name
        type
      }
      external
      block {
        height
      }
    }
  }
}


Create Account:

This instruction tells the network to create a new account. Just like opening a new bank account, but on the blockchain.

This query retrieves the signature and success status of the second most recent "createAccount" instruction on Solana occurring at a block height.

Open this query in IDE

{
  solana(network: solana) {
    instructions(
      options: {limit: 1, offset: 1}
      parsedActionName: {in: ["createAccount"]}
      height: {is: 255934467}
    ) {
      transaction {
        signature
        success
      }
      accountsCount
      action {
        name
        type
      }
      externalAction {
        type
        name
      }
      externalProgram {
        parsedName
        name
        parsed
        id
      }
    }
  }
}

Close Account Opposite of "Create Account," this instruction tells the network to close an existing account.

Open this query in IDE

{
  solana(network: solana) {
    instructions(
      options: {limit: 1, offset: 1, desc: "block.height"}
      parsedActionName: {in: ["delegate"]}
      success: {is: true}
      time: {after: "2024-03-20"}
    ) {
      transaction {
        signature
        success
        transactionIndex
      }
      externalAction {
        name
        type
      }
      external
      block {
        height
      }
    }
  }
}

Token Minting

This query retrieves Solana instructions related to token minting operations within a specified time range. It filters instructions associated with actions like initializing a mint, minting tokens, creating accounts, and more. Additionally, it only considers successful instructions from the "spl-token" program. The query returns details such as block height, program ID, transaction signature, and external program ID.

open this query in IDE

query ($network: SolanaNetwork!, $limit: Int!, $offset: Int!, $from: ISO8601DateTime, $till: ISO8601DateTime) {
  solana(network: $network) {
    instructions(
      options: {desc: "block.height", limit: $limit, offset: $offset}
      time: {since: $from, till: $till}
      parsedActionName: {in: ["initializeMint", "mintTo", "create", "initializeImmutableOwner", "createAccount"]}
      success: {is: true}
      parsedProgramName: {is: "spl-token"}
    ) {
      block {
        height
      }
      program {
        id
      }
      transaction {
        signature
      }
      externalProgram {
        id
      }
    }
  }
}
{
  "limit": 100,
  "offset": 0,
  "network": "solana",
  "from": "2024-03-11T13:57:23.000Z",
  "till": "2024-03-11T18:12:23.999Z",
  "dateFormat": "%Y-%m-%d"
}

These instructions are the building blocks of interactions on the Solana blockchain, allowing users to perform various actions securely and efficiently.

Other important queries to understand Solana’s instructions.

  1. Retrieve Successful Transactions within a Time Range:

This query fetches data about recent instructions on the Solana mainnet blockchain during a specific timeframe. It targets transactions and includes details like transaction signatures and whether they were successful

open this query in IDE

{
  solana(network: solana) {
    instructions(
      options: {limit: 10, desc: "block.timestamp.time"}
      time: {since: "2024-01-01T00:00:00Z", till: "2024-01-02T00:00:00Z"}
    ) {
      transaction {
        signature
        success
      }
      accountsCount
      action {
        name
        type
      }
      externalAction {
        type
        name
      }
      externalProgram {
        parsedName
        name
        parsed
        id
      }
      block {
        timestamp {
          time
        }
      }
    }
  }
}


  1. Recent Solana Instructions Analysis

This query fetches data about recent instructions on the Solana mainnet blockchain during a specific timeframe. It captures information about programs involved in these instructions and includes transaction signatures associated with them.

open this query in IDE

{
  solana(network: solana) {
    instructions(
      options: {limit: 2}
      time: {since: "2024-01-01T00:00:00Z", till: "2024-01-02T00:00:00Z"}
    ) {
      program {
        id
      }
      transaction {
        signature
      }
    }
  }
}

  1. Solana Financial Transaction Details

This query focuses on retrieving specific details of financial transactions within the Solana network. It captures transaction signatures, fee payers, and success statuses, providing developers with essential insights into recent financial activities on Solana.

open this query in IDE

{
  solana(network: solana) {
    instructions(options: {limit: 2}, height: {gt: 254067096}) {
      transaction {
        signature
        feePayer
        success
      }
    }
  }
}

  1. Retrieve Token Transfer Transactions

This query fetches information about the last 10 transfers of the SOL token on the Solana network after a specific block height. It includes details such as the sender's and receiver's addresses, transaction signature and fee, date of the transaction, and the timestamp of the block in which the transaction occurred.

Open this query in IDE


{
  solana(network: solana) {
    transfers(
      currency: {in: "SOL"}
      height: {gt: 254073030}
      options: {limit: 10, desc: "block.timestamp.time"}
    ) {
      sender {
        address
      }
      receiver {
        address
      }
      transaction {
        recentBlockHash
        signature
        fee
      }
      date {
        year
      }
      block {
        timestamp {
          time
        }
      }
    }
  }
}

  1. Solana Instruction Accounts Snapshot

The query helps users understand the state of instruction accounts and associated activity at that particular block height.It includes details such as action names, parsed program names, account information (index, name, owner, type), block details (height, hash, previous block hash, and timestamp), and transaction details (fee payer, signature, success status, and transaction index).

open this query in IDE


{
  solana(network: solana) {
    instructionAccounts(
      height: {is: 254292327}
      options: {limit: 10, desc: "block.timestamp.time"}
    ) {
      instruction {
        action {
          name
        }
        program {
          parsedName
        }
      }
      account {
        index
        name
        owner
        type
      }
      block {
        height
        hash
        previousBlockHash
        timestamp {
          time
        }
      }
      transaction {
        feePayer
        signature
        success
        transactionIndex
      }
    }
  }
}

  1. External Program and Log Retrieval

This query retrieves specific details about an instruction executed on the Solana blockchain. It's focused on a particular transaction, identified by its unique signature. The query aims to shed light on what happened within this transaction, providing insights into the external program involved and the action it performed. By examining the external program's ID and name, as well as details about the action, such as its type and name, developers can gain a deeper understanding of the transaction's purpose and functionality. Additionally, the query captures log data related to the instruction's execution, including gas consumption, resulting logs, and overall outcomes.

open this query in IDE

{
  solana(network: solana) {
    instructions(
      signature: {is: "5H7YVPqpwiXXNXXgSpYeZpoBko7BmUmjG2yvwBgcSrCDaUCJX9S48FK6o8CgQCrCh74yRd8AospkEQT2Vpa4SJPu"}
    ) {
      externalProgram {
        id
        name
        parsed
        parsedName
      }
      externalAction {
        type
        name
      }
      log {
        consumed
        logs
        result
        totalGas
        instruction
      }
    }
  }
}

  1. Latest Solana Swap Instruction Details

This query fetches detailed information about the most recent swap instruction executed on the Solana blockchain. It provides data on the block height, timestamp, transaction details, program information, external action, and log details related to the swap instruction. The query is limited to return only one instruction also can be modified as per the use case.

open this query in IDE

{
  solana(network: solana) {
    instructions(
      options: {limit: 1, desc: "block.timestamp.time"}
      parsedActionName: {in: ["swap"]}
      height: {is: 254311197}
    ) {
      block {
        height
        timestamp {
          time
        }
      }
      transaction {
        signature
        feePayer
        success
      }
      program {
        id
        name
        parsedName
      }
      externalAction {
        name
        type
      }
      log {
        totalGas
        instruction
      }
    }
  }
}


Understanding Different Types of Solana Programs

Solana ecosystem hosts various types of programs that interact with its blockchain. These programs can broadly be categorized into non-native, native, and Anchor programs. Understanding these distinctions is crucial for developers working on Solana.

  • Non-Native Programs:

Non-native programs on Solana are typically written in languages other than Rust, which is the primary language for Solana development. They are compiled to run on Solana's BPF (BPF) virtual machine. These programs leverage Solana's capabilities while allowing developers to use their preferred programming languages.

  • Native Programs:

Native programs, on the other hand, are written in Rust and compiled directly into Solana's bytecode. They are optimized for performance and efficiency on the Solana blockchain. Native programs have direct access to Solana's core functionalities and can interact closely with the network.

  • Anchor Programs:

Anchor is a framework for building Solana programs in Rust. It simplifies the development process by providing high-level abstractions and tooling. Anchor programs are native programs written using the Anchor framework. They offer a more developer-friendly experience and streamline the deployment and management of Solana smart contracts.

Developers can utilize Bitquery to gain insights into Solana's program ecosystem. By leveraging it’s capabilities, developers can discern program types, from non-native solutions in diverse languages to native Rust-based programs and Anchor frameworks for streamlined development.To identify the type of program used on Solana, developers can inspect the source code or documentation associated with the program. Non-native programs may mention the use of languages like C, C++, or JavaScript. Native programs are typically written in Rust and compiled using Solana's toolchain. Anchor programs are identified by the use of the Anchor framework in Rust projects.

Conclusion:

Solana's rapid growth in the blockchain space is fueled by its ability to overcome scalability challenges, offering high-speed, low-cost transactions for decentralized applications (DApps). With Solana APIs and Bitquery, developers gain powerful tools to analyze transactional data efficiently. By understanding Solana's diverse program ecosystem, developers can maximize the platform's potential for innovation and decentralized solutions.

About Bitquery

Bitquery is a set of software tools that parse, index, access, search, and use information across blockchain networks in a unified way. Our products are:

  • Coinpath® APIs provide blockchain money flow analysis for more than 24 blockchains. With Coinpath’s APIs, you can monitor blockchain transactions, investigate crypto crimes such as bitcoin money laundering, and create crypto forensics tools. Read this to get started with Coinpath®.
  • Digital Assets API provides index information related to all major cryptocurrencies, coins, and tokens.
  • DEX API provides real-time deposits and transactions, trades, and other related data on different DEX protocols like Uniswap, Kyber Network, Airswap, Matching Network, etc.

If you have any questions about our products, ask them on our Telegram channel or email us at sales@bitquery.io. Also, subscribe to our newsletter below, we will keep you updated with the latest in the cryptocurrency world.

Subscribe to our newsletter

Subscribe and never miss any updates related to our APIs, new developments & latest news etc. Our newsletter is sent once a week on Monday.