Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

149
Views
How to differentiate between WEI and ETHER value?

While creating a marketplace project, I listen to events to store NFT prices on my node backend. In the given sample I implemented a pre-save middleware that checks if the number is an integer or not and if the number is an integer, it assumes that the value is in Ether and runs next middleware. If it is not an Integer I assume that this is a WEI value thus I convert from WEI to ETHER. The problem arises when the ETHER value is in decimals, suppose "1.2 ETH". Since this is not an integer the next() callback is skipped and fromWei("1.2ETH") functions runs on an ETHER value.

nft.pre('save', async function(next) {
  if (!this.isModified('nftPrice')) return next();
  if(!(Number.isInteger(this.nftPrice))) return next();
  this.nftPrice=web3.fromWei(`${this.nftPrice}`,'ether');
  next();
});

This can cause problems in price value of an assets as the end user will be feeded wrong price.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!