{"record":{"id":"a1f7c58eaa426cce","repo":"FuelLabs/fuels-ts","slug":"invalid-data-a1f7c5","errorCode":"INVALID_DATA","errorMessage":"invalid base58 value ${letter}","messagePattern":"invalid base58 value (.+?)","errorType":"exception","errorClass":"FuelError","httpStatus":null,"severity":"error","filePath":"packages/utils/src/utils/base58.ts","lineNumber":22,"sourceCode":"\nimport { arrayify } from './arrayify';\nimport type { BytesLike } from './arrayify';\n\nconst BN_0 = bn(0);\nconst BN_58 = bn(58);\nconst Alphabet = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';\nlet Lookup: null | Record<string, BN> = null;\n\nfunction getAlpha(letter: string): BN {\n  if (Lookup == null) {\n    Lookup = {};\n    for (let i = 0; i < Alphabet.length; i++) {\n      Lookup[Alphabet[i]] = bn(i);\n    }\n  }\n  const result = Lookup[letter];\n  if (result == null) {\n    throw new FuelError(ErrorCode.INVALID_DATA, `invalid base58 value ${letter}`);\n  }\n  return bn(result);\n}\n\n/**\n *  Encode value as a Base58-encoded string.\n */\nexport function encodeBase58(_value: BytesLike): string {\n  const bytes = arrayify(_value);\n\n  let value = bn(bytes);\n  let result = '';\n  while (value.gt(BN_0)) {\n    result = Alphabet[Number(value.mod(BN_58))] + result;\n    value = value.div(BN_58);\n  }\n\n  // Account for leading padding zeros","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/FuelLabs/fuels-ts/blob/b3f37c91aca4aa9d5e4c0d3967f66237190826ea/packages/utils/src/utils/base58.ts#L4-L40","documentation":"Thrown by the internal getAlpha helper in base58.ts when a character in the input string is not part of the Base58 Bitcoin alphabet (no 0, O, I, l). The Lookup table maps only the 58 valid alphabet characters to their digit values; any character absent from the table triggers the error, reporting the offending letter.","triggerScenarios":"Calling decodeBase58(value) where value contains a character outside '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz' — e.g. '0', 'O', 'I', 'l', a space, punctuation, or any non-ASCII char. The error fires on the first such character encountered while iterating.","commonSituations":"Decoding a value that is actually base64, hex, or a raw string mistaken for base58. Hand-typed base58 strings containing a '0' or capital 'O'/'I' or lowercase 'l'. Whitespace/newline accidentally included in a copy-pasted address. Truncated or corrupted address from a log. Using a checksummed/modified alphabet variant.","solutions":["Confirm the input is genuinely Base58 (Bitcoin alphabet); strip whitespace/newlines before decoding.","Replace forbidden look-alikes (0->O not valid; I, O, l are not in the alphabet) by re-reading the source address.","If the value is hex or base64, decode with the appropriate utility instead of decodeBase58.","Pre-validate with a regex: /^[1-9A-HJ-NP-Za-km-z]+$/."],"exampleFix":"// before\ndecodeBase58('  0IJKxyz  '); // contains space, '0', 'I'\n\n// after\nconst cleaned = '  0IJKxyz  '.trim();\nif (!/^[1-9A-HJ-NP-Za-km-z]+$/.test(cleaned)) throw new Error('not base58');\ndecodeBase58(cleaned);","handlingStrategy":"validation","validationCode":"const BASE58_RE = /^[1-9A-HJ-NP-Za-km-z]+$/;\nfunction isBase58(v: unknown): v is string {\n  return typeof v === 'string' && BASE58_RE.test(v.trim());\n}\nif (!isBase58(value)) throw new Error('not a base58 string');\ndecodeBase58(value.trim());","typeGuard":"const isBase58 = (v: unknown): v is string =>\n  typeof v === 'string' && /^[1-9A-HJ-NP-Za-km-z]+$/.test(v);","tryCatchPattern":"try {\n  const bn = decodeBase58(value);\n} catch (e) {\n  if (e instanceof FuelError && e.code === ErrorCode.INVALID_DATA) {\n    // input wasn't base58; redirect to the correct decoder or reject\n  }\n  throw e;\n}","preventionTips":["Trim whitespace/newlines from copied base58 values before decoding.","Reject the four excluded chars (0, O, I, l) up front with a regex.","Use the right decoder for hex/base64 inputs."],"tags":["base58","decode","address","validation"],"backgroundTag":null,"analyzedSha":"b3f37c91aca4aa9d5e4c0d3967f66237190826ea","analyzedAt":"2026-08-12T20:30:56.448Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}