Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/blocto/solana-go-sdk
Solana Golang SDK
https://github.com/blocto/solana-go-sdk
blockchain go golang sdk solana
Last synced: 25 days ago
JSON representation
Solana Golang SDK
- Host: GitHub
- URL: https://github.com/blocto/solana-go-sdk
- Owner: blocto
- License: mit
- Created: 2020-12-21T05:32:45.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-06-19T04:29:08.000Z (5 months ago)
- Last Synced: 2024-09-28T09:42:57.351Z (about 1 month ago)
- Topics: blockchain, go, golang, sdk, solana
- Language: Go
- Homepage: https://blocto.github.io/solana-go-sdk/
- Size: 894 KB
- Stars: 376
- Watchers: 19
- Forks: 95
- Open Issues: 42
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-ccamel - blocto/solana-go-sdk - Solana Golang SDK (Go)
- best-of-crypto - GitHub - 30% open · ⏱️ 16.05.2024): (Decentralized Finance (DeFi))
README
Solana Go SDK
# Guide
## Getting Started
### Installing
```sh
go get -v github.com/blocto/solana-go-sdk
```### Example
#### Hello World
```go
package mainimport (
"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](https://docs.solana.com/developing/clients/jsonrpc-api).
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:
```go
package mainimport (
"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