💻
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. Advanced
  2. Durable Nonce

Get Nonce Account

You have created a nonce account in previous example. Now we need to fetch its blockhash. I will explain in next step. For now we focus how to fetch blockhash from nonce account.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/portto/solana-go-sdk/client"
	"github.com/portto/solana-go-sdk/program/sysprog"
	"github.com/portto/solana-go-sdk/rpc"
)

func main() {
	c := client.NewClient(rpc.LocalnetRPCEndpoint)
	accountInfo, err := c.GetAccountInfo(
		context.Background(),
		"CJBP7wJcYbPqfhvtSmLBUf4VzBqJbgC776Wr7CzUCd1m",
	)
	if err != nil {
		log.Fatalf("failed to get account info, err: %v", err)
	}

	nonceAccount, err := sysprog.NonceAccountDeserialize(accountInfo.Data)
	if err != nil {
		log.Fatalf("failed to deserialize nonce account, err: %v", err)
	}

	/*
		type NonceAccount struct {
			Version          uint32
			State            uint32
			AuthorizedPubkey common.PublicKey
			Nonce            common.PublicKey
			FeeCalculator    FeeCalculator
		}
	*/
	fmt.Printf("%+v\n", nonceAccount)
}

the Nonce is what we looking for!

PreviousCreate Nonce AccountNextUse Nonce

Last updated 3 years ago

Was this helpful?