{"record":{"id":"0b091f458055e689","repo":"shardeum/shardeum","slug":"parameter-value-is-not-a-valid-bigint-instance","errorCode":null,"errorMessage":"Parameter value is not a valid bigint instance","messagePattern":"Parameter value is not a valid bigint instance","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/utils/serialization.ts","lineNumber":80,"sourceCode":"export const _base10BNParser = (value: bigint | DecimalString): bigint => {\n  if (typeof value == 'string' && value.slice(0, 2) == '0x') {\n    throw new Error('Parameter value does not seem to be a valid base 10 (decimal)')\n  }\n  if (typeof value === 'string' && isNaN(value as unknown as number)) {\n    throw new Error('Parameter value does not seem to be a valid base 10 (decimal)')\n  }\n  if (typeof value === 'bigint') {\n    return value\n  }\n  if (typeof value == 'string') {\n    return BigInt(value)\n  }\n  throw new Error(`_base10BNParser: Unacceptable parameter value ${value}  typeof ${typeof value}`)\n}\n\nexport const _readableSHM = (bnum: bigint, autoDecimal = true): string => {\n  if (typeof bnum !== 'bigint') {\n    throw new Error('Parameter value is not a valid bigint instance')\n  }\n\n  const unit_SHM = ' shm'\n  const unit_WEI = ' wei'\n\n  if (!autoDecimal) return bnum.toString() + unit_WEI\n\n  const numString = bnum.toString()\n  // 1 eth or 1 SHM === 10^18 wei\n  // if wei value gets too big let's convert to SHM in a floating point precision.\n  // 14 is where we set this threshold. hardcoded for now.\n  if (numString.length > 14) {\n    const floating_index = numString.length - 18\n\n    if (floating_index <= 0) {\n      const mantissa = '0'.repeat(Math.abs(floating_index)) + numString\n      return '0.' + mantissa + unit_SHM\n    }","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/shardeum/shardeum/blob/0c454caf067f7b896569eabdd5f47cb8b61738b3/src/utils/serialization.ts#L62-L98","documentation":"_readableSHM formats a bigint amount of wei into a human-readable SHM string. It requires its first argument to be a native bigint; anything else (number, string, BN) fails immediately. This mirrors the parser guard one function above in the same file.","triggerScenarios":"Calling _readableSHM(1000) with a plain number, passing a decimal string like '1.5', or feeding a BN.js object from older EthereumJS-style code into a logging/formatting call.","commonSituations":"Refactoring legacy BN-based code to bigint but forgetting log/format call sites; tests that pass numbers for convenience.","solutions":["Convert the value with _base10BNParser (or BigInt(...)) before calling _readableSHM","Search call sites for _readableSHM and audit each argument's type at runtime","Add a TS type annotation (bnum: bigint) enforcement / noImplicitAny so mismatches are caught at compile time"],"exampleFix":"// before\nconsole.log(_readableSHM(account.balance)) // balance is a number/BN\n\n// after\nconsole.log(_readableSHM(BigInt(account.balance)))","handlingStrategy":"type-guard","validationCode":"const n = typeof bnum === 'number' ? BigInt(bnum) : bnum\n_readableSHM(n as bigint)","typeGuard":"const isBigInt = (v: unknown): v is bigint => typeof v === 'bigint'","tryCatchPattern":null,"preventionTips":["Keep amount state as bigint end-to-end","Convert at API boundaries once, not at every log call"],"tags":["bigint","formatting","type-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"0c454caf067f7b896569eabdd5f47cb8b61738b3","analyzedAt":"2026-08-28T11:43:29.666Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}