ethereum/go-ethereum · error · Error
This unit doesn't exists, please use the one of the followin
Error message
This unit doesn't exists, please use the one of the following units
What it means
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.
Source
Thrown at internal/jsre/deps/web3.js:2135
return fromAscii(val);
}
return fromDecimal(val);
};
/**
* Returns value of unit in Wei
*
* @method getValueOfUnit
* @param {String} unit the unit to convert to, default ether
* @returns {BigNumber} value of the unit (in Wei)
* @throws error if the unit is not correct:w
*/
var getValueOfUnit = function (unit) {
unit = unit ? unit.toLowerCase() : 'ether';
var unitValue = unitMap[unit];
if (unitValue === undefined) {
throw new Error('This unit doesn\'t exists, please use the one of the following units' + JSON.stringify(unitMap, null, 2));
}
return new BigNumber(unitValue, 10);
};
/**
* Takes a number of wei and converts it to any other ether unit.
*
* Possible units are:
* SI Short SI Full Effigy Other
* - kwei femtoether babbage
* - mwei picoether lovelace
* - gwei nanoether shannon nano
* - -- microether szabo micro
* - -- milliether finney milli
* - ether -- --
* - kether -- grand
* - mether
* - getherView on GitHub (pinned to 6bb0588ad8)
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.
Example fix
// before var wei = web3.toWei(amount, 'eth'); // throws // after var wei = web3.toWei(amount, 'ether');
Defensive patterns
Strategy: validation
Validate before calling
var VALID_UNITS = ['wei','kwei','mwei','gwei','szabo','finney','ether','kether','grand']; // or Object.keys(unitMap)
function safeToWei(v, unit) {
unit = String(unit || 'ether').trim().toLowerCase();
if (VALID_UNITS.indexOf(unit) === -1) throw new Error('unknown unit: ' + unit);
return web3.toWei(v, unit);
} Type guard
function isKnownUnit(u) {
return typeof u === 'string' &&
Object.keys(web3.unitMap || {}).indexOf(u.trim().toLowerCase()) !== -1;
} Prevention
- Whitelist unit strings from user input before toWei/fromWei.
- Trim+lowercase units at your API boundary.
- Centralize unit constants instead of repeating string literals.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Filter ID Error: filter().get() can't be chained synchronous
- invalid iban address
- Contract transaction couldn't be found after 50 blocks
- The contract code couldn't be stored, please check your gas
- Cannot send value to non-payable constructor
AI-assisted analysis of ethereum/go-ethereum@6bb0588ad8 (2026-08-15).
Data as JSON: /api/errors/7be34b2b88c60eed.
Report an issue: GitHub.