docs(examples): cleanup#405
Merged
HealthyBuilder merged 4 commits intoApr 23, 2026
Merged
Conversation
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).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:simulateTransaction/is an emptymain(){};requestAirdrop/uses a placeholder "xxxxxx..." pubkey;sendRawTransaction/andsendEncodedTransaction/embed pre-signed base64 blobs that every RPC now rejects as duplicate/invalidgetTransaction/,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.getBlockProduction/,getInflation{Governor,Rate,Reward}/,getLargestAccounts/,getVoteAccounts/all query testnet - where validator and economic data is sparse - instead of mainnet-betasendTransaction/(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 stringSummary of Changes
closes #328