Skip to content

feat: add --mainnet flag to switch Bech32 address prefix - #1

Merged
danbaruka merged 1 commit into
mainfrom
feat/mainnet-prefix-flag
Mar 24, 2026
Merged

danbaruka merged 1 commit into
mainfrom
feat/mainnet-prefix-flag

Conversation

@danbaruka

Copy link
Copy Markdown
Owner

Changes

  • Add --mainnet flag to allow runtime switching between mainnet and testnet Bech32 address prefixes
  • Define constants for mainnet ("safro") and testnet ("addr_safro") prefixes
  • Implement getBech32Prefix() function to inspect os.Args before Cobra parses flags, since SDK config must be sealed early
  • Update NewRootCmd() to dynamically set all Bech32 prefix variables based on the flag
  • Register --mainnet flag with Cobra to prevent unknown flag errors

Details

This allows users to run the same binary with different address prefixes by passing --mainnet, while maintaining backward compatibility with testnet as the default.

Introduces a persistent --mainnet CLI flag that selects the correct
Bech32 address prefix before sdk.GetConfig().Seal() is called:

- Default (testnet): addr_safro / addr_safrovaloper / addr_safrovalcons
- --mainnet:         safro      / safrovaloper      / safrovalcons

os.Args is pre-scanned via getBech32Prefix() so the prefix is set
before Cobra parses flags, which is required by the Cosmos SDK config
seal contract.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@danbaruka
danbaruka merged commit ae795ec into main Mar 24, 2026
3 of 20 checks passed
danbaruka added a commit that referenced this pull request Apr 26, 2026
feat: add --mainnet flag to switch Bech32 address prefix
@danbaruka
danbaruka deleted the feat/mainnet-prefix-flag branch April 26, 2026 10:42
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.

1 participant