{"record":{"id":"0c389b831e2dffd9","repo":"shardeum/shardeum","slug":"base10bnparser-unacceptable-parameter-value-va","errorCode":null,"errorMessage":"_base10BNParser: Unacceptable parameter value ${value}  typeof ${typeof value}","messagePattern":"_base10BNParser: Unacceptable parameter value (.+?)  typeof (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/utils/serialization.ts","lineNumber":75,"sourceCode":"  }\n\n  throw new Error(`_base16BNParser: Unacceptable parameter value ${value}  typeof ${typeof value}`)\n}\n\nexport 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","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/shardeum/shardeum/blob/0c454caf067f7b896569eabdd5f47cb8b61738b3/src/utils/serialization.ts#L57-L93","documentation":"_base10BNParser converts a value to a BigInt but only accepts values that are already bigint or string. Any other type (number, null, undefined, object, BN instance) is rejected with this message. This is a strict input-sanitization guard, not a parsing failure of valid input.","triggerScenarios":"Calling a Shardeum API (e.g. internal apply functions that serialize amounts) with a numeric JS number like 1000 instead of '1000' or 1000n, or passing null/undefined/BN.js objects into a field that eventually flows into _base10BNParser.","commonSituations":"Mixing BN.js or number literals into code paths migrated to native bigint; JSON payloads parsed with numbers instead of strings; default/missing config values (undefined) reaching amount fields.","solutions":["Convert the value to a string or bigint before calling: use String(value) or BigInt(value)","Trace the offending field name printed in the message (the ${value}/${typeof value} tells you the type) and fix it at the source","If the value legitimately may be a number, add a typeof value === 'number' branch that converts via BigInt(Math.trunc(value)) or String(value)"],"exampleFix":"// before\nconst wei = _base10BNParser(someNumber) // typeof number -> throws\n\n// after\nconst wei = _base10BNParser(BigInt(someNumber))\n// or\nconst wei = _base10BNParser(String(someNumber))","handlingStrategy":"type-guard","validationCode":"if (typeof v !== 'bigint' && typeof v !== 'string') {\n  v = String(v)\n}\nconst bn = _base10BNParser(v)","typeGuard":"const isParsable = (v: unknown): v is bigint | string =>\n  typeof v === 'bigint' || (typeof v === 'string' && /^-?\\d+$/.test(v))","tryCatchPattern":null,"preventionTips":["Always pass wei amounts as strings or bigints through JSON boundaries","Enable strict TS types on amount fields","Unit-test parsers with number/null/undefined inputs"],"tags":["bigint","serialization","type-validation","input-validation"],"backgroundTag":"invalid-argument-type","analyzedSha":"0c454caf067f7b896569eabdd5f47cb8b61738b3","analyzedAt":"2026-08-28T11:43:29.666Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}