Request Airdrop
You are going to do your first rpc call, RequestAirdrop.
This method can give you some SOL for testing.
There are bunch of methods. All of them are listed here.
You can specific endpoint when you create a client.
c := client.NewClient(rpc.LocalnetRPCEndpoint) // local server
​
c := client.NewClient(rpc.DevnetRPCEndpoint) // offical endpoint
Full Code
package main
​
import (
"context"
"fmt"
"log"
​
"github.com/portto/solana-go-sdk/client"
"github.com/portto/solana-go-sdk/rpc"
"github.com/portto/solana-go-sdk/types"
)
​
func main() {
c := client.NewClient(rpc.LocalnetRPCEndpoint)
​
newAccount := types.NewAccount()
fmt.Println(newAccount.PublicKey.ToBase58())
​
txhash, err := c.RequestAirdrop(
context.Background(),
newAccount.PublicKey.ToBase58(),
1e9, // 1 SOL = 10^9 lamports
)
if err != nil {
log.Fatalf("failed to request airdrop, err: %v", err)
}
​
fmt.Println("txhash:", txhash)
}
​
​Official explorer can lookup for txhash and account.
Remember to choose network which you are using. (also you can custom ULR)
​
Copy link