• Stars
    star
    317
  • Rank 128,645 (Top 3 %)
  • Language
    Go
  • License
    MIT License
  • Created over 3 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Solana Golang SDK

Solana Go SDK

GitHub go.mod Go version GitHub release (latest SemVer)

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

More Repositories

1

aptos-go-sdk

Aptos (@aptos-labs) Golang SDK
Go
138
star
2

bloctoswap-contracts

Smart contracts for BloctoSwap
Cadence
58
star
3

fcl-demo

Demo DApp on Flow
JavaScript
43
star
4

blocto-sdk

Integrate with Blocto wallet on Arbitrum, Optimism, Aptos, Polygon, BNB Chain, Avalanche and Ethereum.
TypeScript
28
star
5

solana-contract-wallet

Solana contract wallet used in Blocto wallet & SDK
Rust
23
star
6

flow-swift-sdk

Swift
22
star
7

fcl-android

🌊 Flow Client Library for Android
Kotlin
21
star
8

fcl-swift

🌊 Flow Client Library Swift version
Swift
20
star
9

blocto-unity-sdk

The repository contains fcl-unity, blocto-unity-sdk and demo app.
C#
18
star
10

flow-transactions

Audited Flow transactions.
Cadence
16
star
11

blt-contracts

Blocto Token Smart Contracts
Cadence
16
star
12

blocto-ios-sdk

Integrate with Blocto wallet on Polygon, Flow, BNB Chain, Avalanche and Ehtereum.
Swift
14
star
13

bloctobay-contracts

Blocto Bay Smart Contracts
Cadence
10
star
14

solana-web3.kotlin

Solana SDK in Kotlin
Kotlin
10
star
15

blocto-docs

Documentations for integrating with Blocto
HTML
9
star
16

blocto-solana-web3-provider

JavaScript
7
star
17

4337-contracts

TypeScript
4
star
18

solana-web3.swift

Swift
4
star
19

reward-demo

Sample React project from sending Blocto point as reward
JavaScript
4
star
20

flow-dapp-demo

Demo Flow Dapp - Message Board
JavaScript
3
star
21

blocto-android-sdk

Integrate with Blocto wallet on Polygon, Flow, BNB Chain, Avalanche and Ehtereum.
Kotlin
2
star
22

blocto-integration

Blocto Integration Documentation
1
star
23

flow-hello-world

Please check out https://docs.blocto.app/blocto-sdk/javascript-sdk/flow/tutorial
JavaScript
1
star
24

quiz

Quiz component for Blocto blockchain guide
JavaScript
1
star
25

wallet-web-ui

TypeScript
1
star
26

blocto-connector

Blocto SDK connector for web3-react
TypeScript
1
star
27

bloctoswap-listings

JavaScript
1
star
28

eslint-config-portto

Eslint config for portto
JavaScript
1
star
29

evm-contract-wallet

JavaScript
1
star
30

flow-event-scraper

This project demonstrates how to use FCL to scrap event from Flow block.
TypeScript
1
star
31

solana-web3-demo

JavaScript
1
star
32

assets-v2

1
star
33

blocto-sdk-examples

TypeScript
1
star