unionlabs/union · error · Error
Denom must be between 2 and 128 characters
Error message
Denom must be between 2 and 128 characters
What it means
This message comes from a patch the repo applies to @cosmjs/stargate's GasPrice.checkDenom. The patch relaxes the minimum denom length from 3 to 2 characters (aligned with the Cosmos SDK 0.42 denom regex note); it still throws when the denom in a gas price string is shorter than 2 or longer than 128 characters.
Source
Thrown at patches/@cosmjs__stargate.patch:27
-const math_1 = require("@cosmjs/math");
-const proto_signing_1 = require("@cosmjs/proto-signing");
+"use strict"
+Object.defineProperty(exports, "__esModule", { value: true })
+exports.calculateFee = exports.GasPrice = void 0
+const math_1 = require("@cosmjs/math")
+const proto_signing_1 = require("@cosmjs/proto-signing")
/**
* Denom checker for the Cosmos SDK 0.42 denom pattern
* (https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/types/coin.go#L599-L601).
@@ -10,58 +10,58 @@ const proto_signing_1 = require("@cosmjs/proto-signing");
* This is like a regexp but with helpful error messages.
*/
function checkDenom(denom) {
- if (denom.length < 3 || denom.length > 128) {
- throw new Error("Denom must be between 3 and 128 characters");
- }
+ if (denom.length < 2 || denom.length > 128) {
+ throw new Error("Denom must be between 2 and 128 characters")
+ }
}
/**
* A gas price, i.e. the price of a single unit of gas. This is typically a fraction of
* the smallest fee token unit, such as 0.012utoken.
*/
class GasPrice {
- constructor(amount, denom) {
- this.amount = amount;
- this.denom = denom;
- }
- /**
- * Parses a gas price formatted as `<amount><denom>`, e.g. `GasPrice.fromString("0.012utoken")`.
- *
- * The denom must match the Cosmos SDK 0.42 pattern (https://github.com/cosmos/cosmos-sdk/blob/v0.42.4/types/coin.go#L599-L601).
- * See `GasPrice` in @cosmjs/stargate for a more generic matcher.
- *
- * Separators are not yet supported.View on GitHub (pinned to 031785bb6d)
Solutions
- Ensure the patch is applied: reinstall dependencies through the package manager config (e.g. bun's patchedDependencies in package.json) so patches/@cosmjs__stargate.patch takes effect
- Use a denom of at least 2 characters (prefer the chain's canonical 3+ character base denom like "uatom")
- After upgrading @cosmjs/stargate, re-generate/refresh the patch file so it matches the new version
Example fix
// before (denom too short — throws even with the patch)
const gasPrice = GasPrice.fromString("0.025u")
// after
const gasPrice = GasPrice.fromString("0.025uatom") // 2+ character denom Defensive patterns
Strategy: validation
Validate before calling
const GAS_PRICE_PATTERN = /^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/
export const validateGasPrice = (s: string) => {
const m = s.match(GAS_PRICE_PATTERN)
if (!m) throw new Error(`Invalid gas price string: ${s}`)
const denom = m[2]
if (denom.length < 2 || denom.length > 128) {
throw new Error(`Denom ${denom} must be 2-128 characters`)
}
return s
} Type guard
const isPatchedGasPriceString = (s: string): boolean => {
const m = s.match(/^([0-9.]+)([a-zA-Z][a-zA-Z0-9/:._-]*)$/)
return Boolean(m) && m![2].length >= 2 && m![2].length <= 128
} Try / catch
try {
const gasPrice = GasPrice.fromString(raw)
} catch (error) {
if ((error as Error).message.includes("Denom must be between")) {
// either fix the denom length, or verify the repo patch to @cosmjs/stargate is applied
}
throw error
} Prevention
- After any dependency reinstall/upgrade, confirm patches/@cosmjs__stargate.patch is applied (check the patched file in node_modules shows 2..128)
- Use the chain's canonical base denom (usually 3+ chars) in gas prices
- Wrap GasPrice.fromString in a single validated helper used everywhere
When it happens
Trigger: Calling GasPrice.fromString (directly or via Stargate/Union client setup with gasPrice) where the denom portion is 1 character (e.g. "0.025u") or over 128 characters. With the patch, 2-character denoms like "ux" are accepted; without the patch applied, even valid 2-character denoms throw the 3-and-128 variant.
Common situations: A chain with a 2-character base denom (why the patch exists) failing after node_modules was reinstalled without applying patchedDependencies; hand-built gas price strings with truncated denoms; upgrading @cosmjs/stargate so the patch no longer applies cleanly.
Related errors
AI-assisted analysis of unionlabs/union@031785bb6d (2026-08-16).
Data as JSON: /api/errors/f54c8347dffcfc4e.
Report an issue: GitHub.