Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

152
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda