💻
Solana Go
GithubMissing content?
  • 🏠Introduction
  • 🛠️Prepare
  • Tour
    • Intro
    • Create Account
    • Request Airdrop
    • Get Balance (SOL)
    • Transfer (SOL)
    • Create Mint (Token)
    • Create Account (Token)
      • Random Token Account
      • Associated Token Account
    • Mint To (Token)
    • Get Balance (Token)
    • Transfer (Token)
  • Advanced
    • Durable Nonce
      • Create Nonce Account
      • Get Nonce Account
      • Use Nonce
  • Metaplex (NFT)
    • Get Metadata
  • Misc
    • Need To Know
Powered by GitBook
On this page

Was this helpful?

  1. Tour

Request Airdrop

PreviousCreate AccountNextGet Balance (SOL)

Last updated 3 years ago

Was this helpful?

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 .

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)
}

Remember to choose network which you are using. (also you can custom ULR)

can lookup for txhash and account.

here
Official explorer