MCPcopy Index your code
hub / github.com/blocto/solana-go-sdk

github.com/blocto/solana-go-sdk @v1.30.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.30.0 ↗ · + Follow
1,208 symbols 4,084 edges 311 files 197 documented · 16% updated 2y agov1.30.0 · 2024-05-07★ 48241 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Solana Go SDK

<img src="https://github.com/blocto/solana-go-sdk/actions/workflows/go.yml/badge.svg?branch=main"></img>
<img src="https://goreportcard.com/badge/github.com/blocto/solana-go-sdk"></img>
<img alt="GitHub go.mod Go version" src="https://img.shields.io/github/go-mod/go-version/blocto/solana-go-sdk">
<img alt="GitHub release (latest SemVer)" src="https://img.shields.io/github/v/release/blocto/solana-go-sdk?display_name=tag">

Guide

Getting Started

Installing

go get -v github.com/blocto/solana-go-sdk

Example

Hello World

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/blocto/solana-go-sdk/client"
    "github.com/blocto/solana-go-sdk/rpc"
)

func main() {
    c := client.NewClient(rpc.MainnetRPCEndpoint)

    // If you would like to customize the http client used to make the
    // requests you could do something like this
    // c := client.New(rpc.WithEndpoint(rpc.MainnetRPCEndpoint),rpc.WithHTTPClient(customHTTPClient))

    resp, err := c.GetVersion(context.TODO())
    if err != nil {
        log.Fatalf("failed to version info, err: %v", err)
    }

    fmt.Println("version", resp.SolanaCore)
}

RPC

All interfaces of rpc follow the solana's json-rpc docs.

The implementation of client in this project separate into two parts, rpc and wrapped. The wrapped only returns main result value and the rpc returns whole rpc response. You can switch it by yourself for different situation. Take getBalance as example:

package main

import (
    "context"
    "fmt"
    "log"

    "github.com/blocto/solana-go-sdk/client"
    "github.com/blocto/solana-go-sdk/rpc"
)

func main() {
    c := client.NewClient(rpc.DevnetRPCEndpoint)

    // get balance
    balance, err := c.GetBalance(
        context.TODO(),
        "RNfp4xTbBb4C3kcv2KqtAj8mu4YhMHxqm1Skg9uchZ7",
    )
    if err != nil {
        log.Fatalf("failed to get balance, err: %v", err)
    }
    fmt.Printf("balance: %v\n", balance)

    // get balance with sepcific commitment
    balance, err = c.GetBalanceWithConfig(
        context.TODO(),
        "RNfp4xTbBb4C3kcv2KqtAj8mu4YhMHxqm1Skg9uchZ7",
        rpc.GetBalanceConfig{
            Commitment: rpc.CommitmentProcessed,
        },
    )
    if err != nil {
        log.Fatalf("failed to get balance with cfg, err: %v", err)
    }
    fmt.Printf("balance: %v\n", balance)

    // for advanced usage. fetch full rpc response
    res, err := c.RpcClient.GetBalance(
        context.TODO(),
        "RNfp4xTbBb4C3kcv2KqtAj8mu4YhMHxqm1Skg9uchZ7",
    )
    if err != nil {
        log.Fatalf("failed to get balance via rpc client, err: %v", err)
    }
    fmt.Printf("response: %+v\n", res)
}

Programing model & Program

There are some important tpyes in solana.

  • Program

resides in the program/ folder.

  • Pubkey (a basic identity of key)

resides in the common/ folder.

  • Insturciton (contain many pubkeys and program ID)
  • Message (contain many instructions)
  • Transaction (contain a message and many signatures)
  • Account (a pub/pri keypair )

reside in the types/ folder.

More Example

for more examples, follow examples/ folder

Extension points exported contracts — how you extend this code

Option (FuncType)
Option is a configuration type for the Client
rpc/options.go

Core symbols most depended-on inside this repo

PublicKeyFromString
called by 1348
common/public_key.go
NewClient
called by 161
client/client.go
NewRpcClient
called by 140
rpc/client.go
SerializeData
called by 87
pkg/bincode/serialize.go
process
called by 74
client/rpc.go
call
called by 73
rpc/client.go
AccountFromBase58
called by 53
types/account.go
Serialize
called by 46
types/message.go

Shape

Function 582
Struct 337
Method 187
TypeAlias 101
FuncType 1

Languages

Go100%
Rust1%

Modules by API surface

program/tokenprog/instruction.go44 symbols
program/token/instruction.go44 symbols
program/system/instruction.go27 symbols
program/sysprog/instruction.go27 symbols
program/stakeprog/instruction.go23 symbols
program/stake/instruction.go23 symbols
program/tokenprog/instruction_test.go22 symbols
program/token/instruction_test.go22 symbols
program/metaplex/token_metadata/instruction.go19 symbols
program/metaplex/tokenmeta/state.go16 symbols
program/metaplex/token_metadata/state.go16 symbols
types/message.go15 symbols

For agents

$ claude mcp add solana-go-sdk \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page