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

146
Views
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
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!