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

147
Visualizações
Why does balanceOf return 0 sometimes after a swap?

I might be misunderstanding something about the way the EVM works, but I am running a script that conducts a tokenswap using the uniswap sdk and then logs the balances of the 2 tokens after the fact in a database/to the console. Intermittently the balanceOf function of the ERC20 contract will return 0 after the swap even though it's successful and I can see on the explorer the balance is not 0.

The way I understand it, once the transfer event is emitted in the swap and the transaction is mined (I am awaiting this), the balance should be updated for the address.

Sample code below:

const swapTx = await routerContract.swapExactTokensForTokens(...params.args);
const swapReceipt = await swapTx.wait();
const token1Bal = await token1Contract.balanceOf(myAddress);
const token2Bal = await token2Contract.balanceOf(myAddress);
console.log(token1Bal); //should be 0
console.log(token2Bal); //should not be 0, but sometimes is returning as 0???

Thanks.

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