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.