Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda