{"record":{"id":"7be34b2b88c60eed","repo":"ethereum/go-ethereum","slug":"this-unit-doesn-t-exists-please-use-the-one-of-th","errorCode":null,"errorMessage":"This unit doesn't exists, please use the one of the following units","messagePattern":"This unit doesn't exists, please use the one of the following units","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"internal/jsre/deps/web3.js","lineNumber":2135,"sourceCode":"            return fromAscii(val);\n    }\n\n    return fromDecimal(val);\n};\n\n/**\n * Returns value of unit in Wei\n *\n * @method getValueOfUnit\n * @param {String} unit the unit to convert to, default ether\n * @returns {BigNumber} value of the unit (in Wei)\n * @throws error if the unit is not correct:w\n */\nvar getValueOfUnit = function (unit) {\n    unit = unit ? unit.toLowerCase() : 'ether';\n    var unitValue = unitMap[unit];\n    if (unitValue === undefined) {\n        throw new Error('This unit doesn\\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2));\n    }\n    return new BigNumber(unitValue, 10);\n};\n\n/**\n * Takes a number of wei and converts it to any other ether unit.\n *\n * Possible units are:\n *   SI Short   SI Full        Effigy       Other\n * - kwei       femtoether     babbage\n * - mwei       picoether      lovelace\n * - gwei       nanoether      shannon      nano\n * - --         microether     szabo        micro\n * - --         milliether     finney       milli\n * - ether      --             --\n * - kether                    --           grand\n * - mether\n * - gether","sourceCodeStart":2117,"sourceCodeEnd":2153,"githubUrl":"https://github.com/ethereum/go-ethereum/blob/6bb0588ad8e7f922e4ad5580f51265a4097af08f/internal/jsre/deps/web3.js#L2117-L2153","documentation":"Thrown by getValueOfUnit in web3.js when converting a value to/from wei using a unit name that is not in the unitMap lookup table. The unit is lowercased before lookup, so only the canonical names (wei, kwei/mwei/gwei/..., ether, kether, femtoether, lovelace, shannon, etc.) are accepted. The error message embeds the full JSON of valid units so you can see exactly what is allowed.","triggerScenarios":"Calling web3.fromWei(x, 'gwei ') / toWei(v, 'GWEI') works, but a typo like 'gwai', an empty-but-non-null string, or a fabricated unit such as 'szabo ' (trailing space) or 'eth' hits unitValue === undefined and throws. Any toWei/fromWei call with an unmapped unit string triggers it.","commonSituations":"Console scripts in geth attach or dapps using the bundled web3 copy a unit name wrong ('eth' instead of 'ether', 'kwei' misspelled), pass a user-supplied string straight into toWei, or pass a unit with whitespace/casing that was expected to be normalized beyond lowercasing.","solutions":["Read the unitMap dumped in the error message and use one of those exact unit names (e.g. 'ether', 'gwei', 'kwei').","Trim and lowercase the unit string before calling toWei/fromWei.","If accepting user input, validate it against a whitelist (Object.keys(web3.eth.unitMap or the printed map) before converting.","For 'eth' style shorthand, map it explicitly: unit = unit === 'eth' ? 'ether' : unit."],"exampleFix":"// before\nvar wei = web3.toWei(amount, 'eth'); // throws\n\n// after\nvar wei = web3.toWei(amount, 'ether');","handlingStrategy":"validation","validationCode":"var VALID_UNITS = ['wei','kwei','mwei','gwei','szabo','finney','ether','kether','grand']; // or Object.keys(unitMap)\nfunction safeToWei(v, unit) {\n  unit = String(unit || 'ether').trim().toLowerCase();\n  if (VALID_UNITS.indexOf(unit) === -1) throw new Error('unknown unit: ' + unit);\n  return web3.toWei(v, unit);\n}","typeGuard":"function isKnownUnit(u) {\n  return typeof u === 'string' &&\n    Object.keys(web3.unitMap || {}).indexOf(u.trim().toLowerCase()) !== -1;\n}","tryCatchPattern":null,"preventionTips":["Whitelist unit strings from user input before toWei/fromWei.","Trim+lowercase units at your API boundary.","Centralize unit constants instead of repeating string literals."],"tags":["web3","units","input-validation"],"backgroundTag":null,"analyzedSha":"6bb0588ad8e7f922e4ad5580f51265a4097af08f","analyzedAt":"2026-08-15T10:06:53.996Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}