Skip to content

Commit c7148dc

Browse files
docs(examples): point cluster-sensitive RPC examples at mainnet-beta
Several examples queried testnet, where the underlying data is sparse or economically meaningless (few validators voting, no real inflation rewards paid out, low-balance largest accounts). Point them at mainnet- beta so they return representative data: - getBlockProduction: drop the redundant second call and switch to mainnet-beta. - getInflationGovernor / getInflationRate / getLargestAccounts: endpoint swap only. - getInflationReward: fetch a currently-voting validator via GetVoteAccounts instead of hardcoding a testnet pubkey, so the example keeps producing rewards across epochs. - getVoteAccounts: drop the stale testnet VotePubkey filter, list all vote accounts, and print a summary (mainnet has >1000).
1 parent f2b3165 commit c7148dc

6 files changed

Lines changed: 47 additions & 48 deletions

File tree

rpc/examples/getBlockProduction/getBlockProduction.go

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,30 +22,19 @@ import (
2222
)
2323

2424
func main() {
25-
endpoint := rpc.TestNet_RPC
26-
client := rpc.New(endpoint)
25+
ctx := context.Background()
26+
// Testnet has few validators; mainnet-beta has the real schedule.
27+
client := rpc.New(rpc.MainNetBeta_RPC)
2728

28-
{
29-
out, err := client.GetBlockProduction(context.TODO())
30-
if err != nil {
31-
panic(err)
32-
}
33-
spew.Dump(out)
34-
}
35-
{
36-
out, err := client.GetBlockProductionWithOpts(
37-
context.TODO(),
38-
&rpc.GetBlockProductionOpts{
39-
Commitment: rpc.CommitmentFinalized,
40-
// Range: &rpc.SlotRangeRequest{
41-
// FirstSlot: XXXXXX,
42-
// Identity: solana.MustPublicKeyFromBase58("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"),
43-
// },
44-
},
45-
)
46-
if err != nil {
47-
panic(err)
48-
}
49-
spew.Dump(out)
29+
out, err := client.GetBlockProductionWithOpts(
30+
ctx,
31+
&rpc.GetBlockProductionOpts{
32+
Commitment: rpc.CommitmentFinalized,
33+
// Range: &rpc.SlotRangeRequest{ FirstSlot: ..., Identity: ... },
34+
},
35+
)
36+
if err != nil {
37+
panic(err)
5038
}
39+
spew.Dump(out)
5140
}

rpc/examples/getInflationGovernor/getInflationGovernor.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222
)
2323

2424
func main() {
25-
endpoint := rpc.TestNet_RPC
26-
client := rpc.New(endpoint)
25+
client := rpc.New(rpc.MainNetBeta_RPC)
2726

2827
out, err := client.GetInflationGovernor(
2928
context.TODO(),

rpc/examples/getInflationRate/getInflationRate.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222
)
2323

2424
func main() {
25-
endpoint := rpc.TestNet_RPC
26-
client := rpc.New(endpoint)
25+
client := rpc.New(rpc.MainNetBeta_RPC)
2726

2827
out, err := client.GetInflationRate(
2928
context.TODO(),

rpc/examples/getInflationReward/getInflationReward.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,23 @@ import (
2323
)
2424

2525
func main() {
26-
endpoint := rpc.TestNet_RPC
27-
client := rpc.New(endpoint)
26+
ctx := context.Background()
27+
client := rpc.New(rpc.MainNetBeta_RPC)
2828

29-
pubKey := solana.MustPublicKeyFromBase58("6dmNQ5jwLeLk5REvio1JcMshcbvkYMwy26sJ8pbkvStu")
29+
// Fetch any currently-voting validator so the example keeps working
30+
// across epochs without a hardcoded pubkey.
31+
voteAccounts, err := client.GetVoteAccounts(ctx, nil)
32+
if err != nil {
33+
panic(err)
34+
}
35+
if len(voteAccounts.Current) == 0 {
36+
panic("no current vote accounts")
37+
}
38+
votePubkey := voteAccounts.Current[0].VotePubkey
3039

3140
out, err := client.GetInflationReward(
32-
context.TODO(),
33-
[]solana.PublicKey{
34-
pubKey,
35-
},
41+
ctx,
42+
[]solana.PublicKey{votePubkey},
3643
&rpc.GetInflationRewardOpts{
3744
Commitment: rpc.CommitmentFinalized,
3845
},

rpc/examples/getLargestAccounts/getLargestAccounts.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222
)
2323

2424
func main() {
25-
endpoint := rpc.TestNet_RPC
26-
client := rpc.New(endpoint)
25+
client := rpc.New(rpc.MainNetBeta_RPC)
2726

2827
out, err := client.GetLargestAccounts(
2928
context.TODO(),

rpc/examples/getVoteAccounts/getVoteAccounts.go

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,30 @@ package main
1616

1717
import (
1818
"context"
19+
"fmt"
1920

20-
"github.com/davecgh/go-spew/spew"
21-
"github.com/gagliardetto/solana-go"
2221
"github.com/gagliardetto/solana-go/rpc"
2322
)
2423

2524
func main() {
26-
endpoint := rpc.TestNet_RPC
27-
client := rpc.New(endpoint)
25+
ctx := context.Background()
26+
client := rpc.New(rpc.MainNetBeta_RPC)
2827

29-
out, err := client.GetVoteAccounts(
30-
context.TODO(),
31-
&rpc.GetVoteAccountsOpts{
32-
VotePubkey: solana.MustPublicKeyFromBase58("vot33MHDqT6nSwubGzqtc6m16ChcUywxV7tNULF19Vu").ToPointer(),
33-
},
34-
)
28+
// Without options, returns every vote account on the cluster. To
29+
// filter to one validator, pass &GetVoteAccountsOpts{VotePubkey: &...}.
30+
out, err := client.GetVoteAccounts(ctx, nil)
3531
if err != nil {
3632
panic(err)
3733
}
38-
spew.Dump(out)
34+
35+
// Full response is large on mainnet; print a summary.
36+
fmt.Println("current vote accounts:", len(out.Current))
37+
fmt.Println("delinquent vote accounts:", len(out.Delinquent))
38+
for i, v := range out.Current {
39+
if i >= 5 {
40+
break
41+
}
42+
fmt.Printf(" %s stake=%d commission=%d%%\n",
43+
v.VotePubkey, v.ActivatedStake, v.Commission)
44+
}
3945
}

0 commit comments

Comments
 (0)