I am trying to handle multiple chains in a single Node.js backend. When I was dealing with one chain, which is Ethereum, I just made sure my web3 was targeting that chain ID and doing the transfer. But now, I would like to target both Ethereum and Polygon, which I need to ensure the transfer and transfer tracking are working on the correct chain.
So I assume before I call the following code:
const contract = new web3.eth.Contract(JSON.parse(r.rows[0].contract_abi), contractAddress);
I would need to check the current chain ID and switch it accordingly if needed. Otherwise, it would not find the contract as it is not on the current chain.
But while I do so, I might need to switch back as my previous transaction is being tracked by repeatedly calling the following code:
await web3.eth.getTransactionReceipt(txHash);
If I switch the chain, I think all ongoing tracking process would be affected.
Is it possible to keep some web3 on one chain while some other web3 on other chains, so that all processes can go simultaneously? Or would they not affect each other? I wonder how Opensea did this on their platform, they clearly have a tracking system across both chains.