How to convert between different aspects of data for
Token Denominations
In Cosmos, every denomination amount is formatted as an unsigned integer. With this, the chain does not have to deal with fractions. For an EVM chain this amount is typically 10**18 power, while Juno and other native Cosmos chains use the 10**6 power. This means if I want to send you 1 JUNO, I am actually sending 1,000,000 of the smaller token.
You can figure out which power a token uses by its prefix character in the denomination. In the case of JUNO, the actual denomination is shown as ujuno. This u signals that it is using any amount times 10**6 to get the human readable amount.
10JUNO = 10,000,000ujuno
0.5 JUNO = 500,000ujuno
0.00001 JUNO = 10ujuno
This means the smallest amount anyone can send is 0.000001 JUNO
Address Conversions
Valoper -> Base
Convert the validator operator wallet to a standard base address
You can only convert between the same cointype, so converting a JUNO (118) to EVM address such as Terra's 330 will not properly convert. This is not possible to do without their private key
// npm i @cosmjs/encodingimport {fromHex, toBech32} from'@cosmjs/encoding'// where junovalcons is the wallet prefix for the chain + valconsconstprefix="junovalcons"let addr =toBech32(prefix,fromHex("1470B9237056641663CB4DFDEC86B064578B29BF"))console.log(addr)// This outputs junovalcons1z3ctjgms2ejpvc7tfh77ep4sv3tck2dl30r3mx // which matches their page// https://ping.pub/juno/staking/junovaloper196ax4vc0lwpxndu9dyhvca7jhxp70rmcqcnylw
With this, you can now make a mapping between a junovaloper and signing junovalcons address
Hex -> Bech32
Convert juno address between hex and bech32 format.
junod debug addr [address] [flags]
TIP
The command will accept either hex or bech32 coded address as the [address] argument. The command will return the same output for either.
TIP
Your bech32 encoded juno local addresses can be queried with junod keys list
Convert raw bytes output (eg. [10 21 13 127]) to hex.
junod debug raw-bytes <raw-bytes>
Example command:
junod debug raw-bytes "10 21 13 127"
Returns:
0A150D7F
Public Key -> Valcons
Convert a validators public key to the validator consensus tendermint address
You can get the Public Key from the REST/LCD endpoint:
cosmos/staking/v1beta1/validators
https://api.juno.strange.love/cosmos/staking/v1beta1/validators
&
https://.../cosmos/staking/v1beta1/validators/<junovaloper...>
// npm i @cosmjs/encodingimport {fromBase64, toBech32} from'@cosmjs/encoding'// npm i @cosmjs/cryptoimport { sha256 } from'@cosmjs/crypto'let prefix ="junovalcons"// Chain Format: // {// "@type":"/cosmos.crypto.ed25519.PubKey",// "key":"/O7BtNW0pafwfvomgR4ZnfldwPXiFfJs9mHg3gwfv5Q="// }// we just need the .key string from the objectlet pubKey ="/O7BtNW0pafwfvomgR4ZnfldwPXiFfJs9mHg3gwfv5Q="constaddr=toBech32(prefix,sha256(fromBase64(pubKey)).slice(0,20))console.log(addr)// junovalcons1z3ctjgms2ejpvc7tfh77ep4sv3tck2dl30r3mx
PubKey -> Hex, Base64, or Bech32
Decode a ED25519 pubkey from hex, base64, or bech32.
junod debug pubkey [pubkey] [flags]
TIP
The command will accept hex, base64 or bech32 coded keys as [pubkey] argument. The command will return the same output for any of these inputs.
TIP
Your bech32 encoded validator pubkey can be queried with junod tendermint show-validator