Skip to content

docs(examples): cleanup#405

Merged
HealthyBuilder merged 4 commits into
solana-foundation:mainfrom
sonicfromnewyoke:sonic/docs-examples-cleanup
Apr 23, 2026
Merged

docs(examples): cleanup#405
HealthyBuilder merged 4 commits into
solana-foundation:mainfrom
sonicfromnewyoke:sonic/docs-examples-cleanup

Conversation

@sonicfromnewyoke
Copy link
Copy Markdown
Contributor

Problem

The rpc/examples/* tree has 52 runnable samples, one per RPC method. Many were filed once in 2021 with hardcoded inputs and never revisited. Some of them are:

  • broken: simulateTransaction/ is an empty main(){}; requestAirdrop/ uses a placeholder "xxxxxx..." pubkey; sendRawTransaction/ and sendEncodedTransaction/ embed pre-signed base64 blobs that every RPC now rejects as duplicate/invalid
  • silently stale: getTransaction/, getSignatureStatuses/, isBlockhashValid/ hardcode signatures/blockhashes that no longer exist on the cluster; getFeeForMessage/ passes a dummy base64 string with no hint at how to construct one; getProgramAccounts/ queries an unbounded Metaplex range that public RPCs refuse.
  • wrong cluster: getBlockProduction/, getInflation{Governor,Rate,Reward}/, getLargestAccounts/, getVoteAccounts/ all query testnet - where validator and economic data is sparse - instead of mainnet-beta
  • onfusing by design: sendTransaction/ (issue How to generate params in the sendTransaction method #328 ) decoded a pre-signed blob before calling SendTransaction, leading readers to think they need to start from a base64 string

Summary of Changes

  • fixed broken examples
  • un-staled stale read paths
  • repointed wrong-cluster examples

closes #328

The previous sample decoded a hard-coded, pre-signed base64 blob before
calling SendTransaction, which confused readers (see solana-foundation#328) about how to
actually produce that input. The pre-serialized flow is already covered
by the sendRawTransaction and sendEncodedTransaction examples.

Rewrite this example to show the idiomatic SendTransaction path:
generate a sender, airdrop on devnet, build a Transfer via
system.NewTransferInstruction, sign, and submit.

Closes solana-foundation#328
- simulateTransaction: had an empty main; simulate a mainnet transfer
  with SigVerify=false / ReplaceRecentBlockhash=true so no keys or
  funding are needed.
- requestAirdrop: replace placeholder 'xxx...' pubkey with a fresh
  wallet, and switch to devnet since testnet's faucet is often dry.
- sendRawTransaction / sendEncodedTransaction: dropped the stale
  hardcoded base64 blob that SendTransaction would reject. Both now
  build and sign a devnet transfer, then encode to bytes / base64
  before calling the corresponding RPC.
Several examples hardcoded signatures, blockhashes, or base64 blobs
that rotted the moment they were merged — or queried testnet where the
needed data is sparse. Reshape them to fetch fresh input on mainnet-beta
so they keep working as the cluster advances:

- getTransaction, getSignatureStatuses: pull a recent signature via
  GetSignaturesForAddressWithOpts on the SPL Token program, then
  operate on it.
- getFeeForMessage: build a real Transfer message in-code and base64
  it via tx.Message.ToBase64(), instead of a dummy string.
- isBlockhashValid: fetch a live blockhash via GetLatestBlockhash.
- getBlock: switch to mainnet-beta and pass MaxSupportedTransactionVersion,
  which is required now that v0 transactions exist in blocks.
- getProgramAccounts: swap the unbounded Metaplex query for a
  Token-2022 mint query with dataSize filter + DataSlice so the
  response stays small enough for public RPCs.
- getLeaderSchedule: switch to mainnet-beta and print a summary
  instead of spew-dumping every validator in the epoch.
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).
@sonicfromnewyoke sonicfromnewyoke changed the title Sonic/docs examples cleanup docs: examples cleanup Apr 19, 2026
@sonicfromnewyoke sonicfromnewyoke changed the title docs: examples cleanup docs(examples): cleanup Apr 19, 2026
@HealthyBuilder HealthyBuilder merged commit ac3149a into solana-foundation:main Apr 23, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to generate params in the sendTransaction method

2 participants