Fix Ethers Utils parseUnits Errors
DodaTech
Updated 2026-06-26
1 min read
You will learn how to parse token amounts for contract interactions.
The Problem
The ethers utils parse units pattern is frequently misapplied in smart contract and dapp development, leading to vulnerabilities, gas inefficiencies, or logic errors. This guide shows the correct implementation and common pitfalls to avoid.
Quick Fix
Wrong
const amount = ethers.utils.parseUnits(1.5, 18); // Number input
Floating point precision loss.
Right
const amount = ethers.utils.parseUnits('1.5', 18); // '1500000000000000000'
String input preserves precision. Use string for user input.
Prevention
- Always pass values as strings to parseUnits
- Specify decimals parameter explicitly
- Use 18 for ETH, check token contract for token decimals
- Use DodaTech's amount converter
- Format validation before parsing
DodaTech Tools
Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Doda Browser's developer tools include a Solidity debugger and transaction inspector. DodaZIP archives secure contract templates for team collaboration. Durga Antivirus Pro scans deployed contracts for known vulnerability signatures.
FAQ
← Previous
Fix Ethers Utils formatUnits Errors
Next →
How to Fix Excalidraw Collaboration Not Working
Built by the developers of DodaTech
Doda Browser, DodaZIP & Durga Antivirus Pro