From a6c86c509022065e04510e1be751be6511a2c47d Mon Sep 17 00:00:00 2001 From: Sonic Date: Mon, 20 Apr 2026 01:38:28 +0300 Subject: [PATCH] docs: describe program decoders --- README.md | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index ca59ef81e..0b8764dc8 100644 --- a/README.md +++ b/README.md @@ -343,9 +343,25 @@ func decodeSystemTransfer(tx *solana.Transaction) { // OR { // There is a more general instruction decoder: `solana.DecodeInstruction`. - // But before you can use `solana.DecodeInstruction`, - // you must register a decoder for each program ID beforehand - // by using `solana.RegisterInstructionDecoder` (all solana-go program clients do it automatically with the default program IDs). + // It looks up the decoder for `progKey` in a central registry, so it + // works for any program ID regardless of what you know at compile time. + // + // Each `programs/` package registers its decoder via init(), + // which only runs when the package is imported. If you are not + // already using the package's builders (e.g. `system.NewTransferInstruction`), + // blank-import it so the decoder is available - same idiom as + // database/sql drivers: + // + // import ( + // _ "github.com/gagliardetto/solana-go/programs/system" + // _ "github.com/gagliardetto/solana-go/programs/token" + // // ...add more as needed + // ) + // + // For a program that solana-go does not ship (e.g. a custom Anchor + // program), register its decoder yourself: + // + // solana.MustRegisterInstructionDecoder(myProgramID, myDecoderFunc) decodedInstruction, err := solana.DecodeInstruction( progKey, accounts, @@ -361,9 +377,6 @@ func decodeSystemTransfer(tx *solana.Transaction) { if !reflect.DeepEqual(inst, decodedInstruction) { panic("they are NOT equal (this would never happen)") } - - // To register other (not yet registered decoders), you can add them with - // `solana.RegisterInstructionDecoder` function. } {