unionlabs/union · error · Error

Private key not found

Error message

Private key not found

What it means

The playground script stride-to-union-legacy.ts parses --private-key from process.argv via node:util parseArgs and hard-fails when the flag is absent or empty. It is a CLI usage error: the Cosmos (Stride) sender key must be supplied on every invocation, as noted in the script's header comment.

Source

Thrown at typescript-sdk/playground/stride-to-union-legacy.ts:22

import { parseArgs } from "node:util"
import { consola } from "scripts/logger"
import { http } from "viem"
import { hexToBytes } from "../src/convert.ts"
import { createUnionClient, type TransferAssetsParametersLegacy } from "../src/mod.ts"

/* `bun playground/stride-to-union.ts --private-key "..."` */

const { values } = parseArgs({
  args: process.argv.slice(2),
  options: {
    "private-key": { type: "string" },
    "estimate-gas": { type: "boolean", default: false },
  },
})

const PRIVATE_KEY = values["private-key"]
if (!PRIVATE_KEY) {
  throw new Error("Private key not found")
}
const ONLY_ESTIMATE_GAS = values["estimate-gas"] ?? false

const cosmosAccount = await DirectSecp256k1Wallet.fromKey(
  Uint8Array.from(hexToBytes(PRIVATE_KEY)),
  "stride",
)
const [account] = await cosmosAccount.getAccounts()
console.info(account?.address)

try {
  const client = createUnionClient({
    account: cosmosAccount,
    chainId: "stride-internal-1",
    gasPrice: { amount: "0.0025", denom: "ustrd" },
    transport: http("https://stride-testnet-rpc.polkachu.com"),
  })

View on GitHub (pinned to 031785bb6d)

Solutions

  1. Run with the flag: bun playground/stride-to-union-legacy.ts --private-key "<your hex/bech32 key>"
  2. Indirect the secret: --private-key "$PRIVATE_KEY" after exporting the env var
  3. If absent, print a usage line and exit non-zero instead of a bare stack trace

Example fix

// before
const PRIVATE_KEY = values["private-key"]
if (!PRIVATE_KEY) {
  throw new Error("Private key not found")
}

// after
const PRIVATE_KEY = values["private-key"]
if (!PRIVATE_KEY) {
  console.error("Usage: bun playground/stride-to-union-legacy.ts --private-key <key> [--estimate-gas]")
  process.exit(1)
}
Defensive patterns

Strategy: validation

Validate before calling

const PRIVATE_KEY = values["private-key"] ?? process.env.PRIVATE_KEY
if (!PRIVATE_KEY) {
  console.error("Usage: bun playground/stride-to-union-legacy.ts --private-key <key> [--estimate-gas]")
  process.exit(1)
}

Prevention

When it happens

Trigger: Running `bun playground/stride-to-union-legacy.ts` without any flags; using a wrong flag spelling (--privateKey, --privateKey=...); passing an empty string.

Common situations: Copy-pasting the documented run command minus the key; CI jobs where the secret env var was never exported; new contributors running the playground for the first time.

Related errors


AI-assisted analysis of unionlabs/union@031785bb6d (2026-08-16). Data as JSON: /api/errors/e607eb6016e73d09. Report an issue: GitHub.