Introducing a new way to review your PRs.

Read the announcement

solana-foundation / solana-go

Go SDK library and RPC client for the Solana Blockchain

View on GitHub

26 documents · Updated Nov 16, 2026

docs / slnc-command

slnc command application

The slnc command application is the shell-facing entry point for common Solana cluster reads, wallet actions, and selected transaction workflows. It turns process arguments and shared settings into a command path, then connects that path to the Solana library, encrypted key storage, and terminal input helpers. It provides the executable detail for Command-line tooling.

Startup path

The executable starts by passing its build version to the command package. It then executes the root command, which lets the command framework select a group and subcommand from the user's input. The root also prepares shared configuration and logging before a command handler runs.

The startup sequence is:

flowchart LR
    A[Start slnc] --> B[Set command version]
    B --> C[Execute root command]
    C --> D[Load flags and environment settings]
    D --> E[Set up command logging]
    E --> F[Run selected command]
    F --> G[Return cluster result or command error]

The root command reports a handler error and exits with a non-zero status. This gives both people and shell scripts a clear result boundary.

References: cmd/…/main.go• L15-29 cmd/…/root.go• L30-70

Root command settings

The root command owns settings that apply across the command tree. These settings select the RPC endpoint, add HTTP headers, choose the vault file, and provide the Google Cloud KMS key path when a vault uses that protection method.

The command application accepts a full RPC URL or a short cluster name. The supported short names resolve to Solana devnet, testnet, and mainnet endpoints. Environment settings use the SLNC_ prefix, and command scope is part of the resulting name, so shared settings include names such as SLNC_GLOBAL_RPC_URL and SLNC_GLOBAL_VAULT_FILE.

References: cmd/…/root.go• L33-70 cmd/…/root.go• L73-91 cmd/…/common.go• L28-59

Command organization

The command tree groups actions by user goal. Each group provides a stable place for related commands, while each leaf command defines its own positional input and connects that input to a library operation.

Command familySystem role
getReads account, block, slot, blockhash, transaction, and token data from a cluster.
systemOrganizes native SOL instruction actions.
tokenOrganizes token queries and token instruction actions.
token-registryReads token metadata and registers metadata on chain.
vaultCreates, updates, inspects, and exports encrypted key material.
request-airdropRequests lamports for an account.

The group structure is assembled when the command package initializes. A group attaches to the root, and a leaf attaches to its group. This keeps command discovery separate from the work performed after dispatch.

References: cmd/…/root.go• L36-63 cmd/…/get.go• L19-25 cmd/…/system.go• L22-29 cmd/…/token.go• L22-29 cmd/…/token_registry.go• L22-29 cmd/…/vault.go• L24-31 cmd/…/request_airdrop.go• L30-64

Read command family

The get family presents read-only cluster information through one shared request path. Its commands cover individual accounts and balances, program-owned accounts, blocks, slots, recent blockhashes, blockhash validity, account transactions, and selected token data.

Read commands obtain the shared RPC client, validate or convert user input when needed, call the matching SDK RPC method, and print a human-readable result. Account and program-account reads can also use the command decoder to turn recognized binary token data into typed library values before output.

References: cmd/…/get.go• L19-25 cmd/…/common.go• L28-46 cmd/…/get_account.go• L29-68 cmd/…/get_program_accounts.go• L30-76 cmd/…/decoding.go• L26-61

System and token command families

The system and token families provide the command-level shape for Solana instruction work. They collect the public values needed for native SOL or token actions and are intended to hand those values to the SDK's instruction and transaction APIs.

The current transfer commands are entrypoint scaffolding. They validate the expected three-value shape and print the captured source, destination, and amount, but they do not yet build, sign, or submit a transfer. This differs from the token-registry registration command, which uses library instruction builders and transaction submission to perform its on-chain action.

References: cmd/…/system_transfer.go• L27-50 cmd/…/token_transfer.go• L27-49 cmd/…/token_registry_register.go• L34-50 cmd/…/token_registry_register.go• L91-157

Token registry commands

The token-registry family connects command input to token metadata stored on Solana. Read commands fetch one entry or list entries through the token-registry library. The register command checks the metadata values and registrar key, creates the required metadata account, builds the registration transaction, signs it with vault keys, and sends it through the RPC client.

This family shows the full command-to-library path: shell values become typed program data, the library builds the transaction, the vault supplies signing keys, and the RPC client returns the transaction result.

References: cmd/…/token_registry_get.go• L32-64 cmd/…/token_registry_list.go• L31-69 cmd/…/token_registry_register.go• L34-50 cmd/…/token_registry_register.go• L68-89 cmd/…/token_registry_register.go• L109-157

Vault command family

The vault family manages the local source of private keys used by signing commands. It can create a protected vault from new or imported keys, add keys to an existing vault, list public keys, or deliberately export private keys.

Commands that need keys use a shared load-and-open path. That path reads the configured vault file, selects the protection method recorded in the vault, and makes the keys available only after successful decryption or KMS access. The detailed protection model is described in Key security and keystore support.

References: cmd/…/vault_create.go• L32-51 cmd/…/vault_create.go• L68-139 cmd/…/vault_add.go• L32-79 cmd/…/vault_list.go• L24-42 cmd/…/vault_export.go• L24-36 cmd/…/common.go• L71-97

Shared command context

Command handlers share two forms of context: a configured RPC client for cluster access and an optional opened vault for signing. This keeps endpoint selection and key access outside individual business actions.

RPC client boundary

The shared client converts the root settings into the library's RPC client. It normalizes cluster aliases, trims URL endings, and turns configured header values into request headers. A read or transaction command then calls the SDK's typed RPC methods instead of creating JSON-RPC requests itself.

The boundary is shown below.

sequenceDiagram
    participant User as Shell user
    participant Cmd as slnc command
    participant Client as SDK RPC client
    participant Cluster as Solana cluster

    User->>Cmd: Flags and arguments
    Cmd->>Client: Configure endpoint and headers
    Cmd->>Client: Call typed RPC operation
    Client->>Cluster: JSON-RPC request
    Cluster-->>Client: Cluster response
    Client-->>Cmd: Typed SDK result
    Cmd-->>User: Formatted output or error

References: cmd/…/common.go• L28-59 cmd/…/get_balance.go• L27-49 cmd/…/get_block.go• L29-50

Credential boundary

Private values cross into the command process through two controlled paths. A protected vault supplies private keys after it opens, while the CLI helper reads passphrases and imported private keys without displaying the typed value.

Vault creation asks for a passphrase twice so the new protection value can be confirmed. Vault opening asks for the value needed to decrypt an existing vault. An insecure environment override exists for automation, but it moves the secret into the process environment and must be treated as a less safe path.

References: cmd/…/common.go• L71-97 cmd/…/vault_create.go• L105-129 cmd/…/vault_add.go• L86-131 cli/cli.go• L23-48 cli/getpass.go• L24-29

Library connections

The command application is a boundary layer rather than a second Solana implementation. It gathers user input and selects an operation, while the SDK supplies public-key types, RPC methods, program instructions, transaction assembly, signing, and output encoders.

The main connections are:

  • RPC reads call the typed client in rpc.
  • Account and token inspection uses Solana data types and program decoders.
  • Token-registry registration uses program instruction builders and transaction APIs.
  • Vault commands use the vault package for protected key storage.
  • Passphrase and hidden-input work uses the cli package.
  • Human-readable output uses the text encoding helpers where a structured view is useful.

This separation lets a command change its shell interface without changing the library contract that defines how Solana data is read or how a transaction is built.

References: cmd/…/common.go• L22-46 cmd/…/get_account.go• L24-60 cmd/…/token_registry_register.go• L24-30 cmd/…/token_registry_register.go• L109-151 cmd/…/vault_create.go• L24-29

Error and output boundary

A command either prints a result for the user or returns an error to the root command. Input errors can stop a command before an RPC call, while endpoint, vault, decode, and transaction errors can stop it after shared setup.

The root turns a returned error into a message and process exit status. Some older command paths stop directly during setup, so callers should use the process status as the reliable success signal rather than parse a printed message alone.

References: cmd/…/root.go• L42-47 cmd/…/common.go• L61-69 cmd/…/get_transactions.go• L42-80 cmd/…/token_registry_get.go• L45-59

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the executable's version handoff and root execution path aligned. A new entrypoint must still initialize the command package before dispatch.
  • Keep command registration aligned with the command tree and its environment-name scope. Moving a leaf changes how users invoke it and how Viper finds its flags.
  • Keep root flag names, cluster aliases, header parsing, and shared RPC client setup aligned. A setting can be accepted but still fail to affect requests if the binding path changes.
  • Keep commands that sign transactions aligned with the vault protection marker, selected key, instruction signer roles, and transaction submission path.
  • Keep typed account decoding aligned with the program owner and data shape. A recognized owner with a changed binary layout can produce the wrong displayed object.
  • Keep hidden-input paths separate from normal output paths. Changes to import, passphrase, or export commands can expose private values to terminals or logs.

Important failure modes

TriggerConsequenceGuard
The root command is not executed after version setup.The process starts but no command can dispatch.Preserve the executable-to-root handoff in main.
A cluster alias or RPC URL is invalid.The command cannot reach the intended Solana endpoint.Use a supported alias or a valid full URL.
An HTTP header does not use the expected Name: value form.Shared client setup stops before the RPC request.Keep header names free of spaces and include the separator.
A vault file is missing or its protection method cannot open.A key-dependent command stops before it can sign or inspect keys.Use the matching vault file and passphrase or KMS access.
A command receives the wrong positional argument count.Cobra rejects the request before the handler runs.Follow the leaf command's argument contract.
A transfer command is expected to send funds.The current system and token transfer handlers only print their values.Treat them as scaffolding until they connect instruction building, signing, and submission.
Account data is owned by an unsupported program or has an unknown shape.The command prints only the raw account view or cannot decode the data.Use the matching library decoder and treat unknown data as untyped.
A registrar key is not present in the opened vault.Token registration cannot sign its transaction.Put the selected registrar private key in the vault before registration.

Key files

FileWhy to read it
cmd/…/main.goShows the executable startup and version handoff.
cmd/…/root.goDefines root dispatch, shared flags, logging setup, and environment mapping.
cmd/…/common.goConnects shared settings to the RPC client and vault loader.
cmd/…/get.goIntroduces the cluster-read command family.
cmd/…/get_account.goShows a read command that combines RPC data with typed account decoding.
cmd/…/token_registry_register.goShows the complete input, vault, library transaction, and RPC submission path.
cmd/…/system_transfer.goShows the current native SOL transfer boundary and its unfinished scope.
cmd/…/token_transfer.goShows the equivalent token transfer boundary.
cmd/…/vault_create.goShows protected key creation and the passphrase or KMS choice.
cmd/…/vault_add.goShows hidden private-key input and vault update flow.
cli/cli.goDefines passphrase collection and confirmation.
cli/getpass.goDefines hidden terminal input.