Skip to content

Instantly share code, notes, and snippets.

@cosmofract
Created August 18, 2023 11:49
Show Gist options
  • Save cosmofract/a3783788757caf0f6a36064d7c6efdbd to your computer and use it in GitHub Desktop.
Save cosmofract/a3783788757caf0f6a36064d7c6efdbd to your computer and use it in GitHub Desktop.
COSMOS (ATOM) ADDRESS CONVERTER
package main
import (
"fmt"
"log"
"github.com/btcsuite/btcutil/bech32"
)
// try it out at https://goplay.tools/snippet/7b4NzgxvmoM
// COSMOS (ATOM) ADDRESS CONVERTER
// by x.com/cosmofract
// github.com/cosmofract
// Donations welcome, even tiny ones.
// In return you get *at least* a shoutout!
func main() {
// PUT THE KNOWN ADDRESS HERE (like in the example):
pubkey := "cosmos1msrzkmqsnf77yqdkkm2h0z93mh445vhrrh8ukw"
//pubkey := "osmo1msrzkmqsnf77yqdkkm2h0z93mh445vhrtv5vqu"
//pubkey := "stars1msrzkmqsnf77yqdkkm2h0z93mh445vhrhtspal"
// PUT THE DESIRED HUMAN READABLE PREFIX HERE (like in the example):
//prefix := "cosmos"
//prefix := "osmo"
prefix := "stars"
_, rawBytes, err := bech32.Decode(pubkey)
if err != nil {
log.Fatalln("What are you doing? Just put a valid address in `pubkey`!")
}
newPubkey, err := bech32.Encode(prefix, rawBytes)
if err != nil {
log.Fatalln("Are you sure you chose a good `prefix`?")
}
fmt.Printf("The user with address\n\t[%s]\n", pubkey)
fmt.Printf("is also reachable on address\n\t[%s].\n", newPubkey)
fmt.Printf("\nDouble click the address and copy!\n")
fmt.Printf("\nTHIS PROGRAM IS FOR DEMONSTRATION PURPOSES ONLY!\nTHE EXACTNESS IS NOT GUARANTEED!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment