cosmos-sdk decimal precision for coins onchain

2.1k Views Asked by At

Am building a cosmos-sdk chain and was wondering what the official support was for coin's decimal precision on a cosmos chain either being minted via a peg or seeded via genesis as the primary staking/demon token.

We would like to support 10**18 as this matches ethereum and just want to get clarity on this. Thanks

2

There are 2 best solutions below

2
Denis Fadeev On

Coin.Amount used throughout the SDK is an int. There is a DecCoin, but it doesn't seem to be used that much.

Practically speaking, coins are integer values and the upper limit seems to be 10**76 when added to genesis with appd add-genesis-account. However, after the chain has started, having on balance more than 10**76 works fine.

0
okwme On

The Bank Module and subsequent Coin type contain metadata capabilities that include decimals as outlined in ADR-024-coin-metadata.

The relevant types are as follows:

message DenomUnit {
  string denom    = 1;
  uint32 exponent = 2;  
  repeated string aliases = 3;
}

message Metadata {
  string description = 1;
  repeated DenomUnit denom_units = 2;
  string base = 3;
  string display = 4;
}

And the example of the $ATOM, which has 6 decimals, is given here:

{
  "description": "The native staking token of the Cosmos Hub.",
  "denom_units": [
    {
      "denom": "uatom",
      "exponent": 0,
      "aliases": [
        "microatom"
      ],
    },
    {
      "denom": "matom",
      "exponent": 3,
      "aliases": [
        "milliatom"
      ]
    },
    {
      "denom": "atom",
      "exponent": 6,
    }
  ],
  "base": "uatom",
  "display": "atom",
}