How to maintain balances of two tokens in a single contract

How can we maintain the balances of two different bep-20 tokens in a single smart contract? I am trying to write a function that transfers the second type and the first type on different occasions but I don’t know how to access and transfer either of them when we only have a single balances mapping. I don’t want to use the balances of the token contracts rather use the balance of my own contract to transfer these separate tokens is it possible?

Do you have any code to share? If the BEP20 tokens are different contracts than the one you’re working from, you should be able to use BEP20(tokenAddressA).balanceOf() and BEP20(tokenAddressB).balanceOf(). If both tokens are merged into a single contract (weird), well, then we’ll have to see.

Bear in mind that keeping internal track of balances could go wrong if there is no syncing mechanism. For example, someone could send tokens to the contract to increase its balance and mess up the internal accounting.

@martriay The kind of logic that I’m trying to create is that lets suppose there are two token contracts and a third handler contract. Once you mint tokens in the first two contracts, you could manually send some of these to the third handler contract. The handler contract has different functions which send either of the two tokens from its own balance depending upon requirements.

Ok. Then what’s the problem, isn’t BEP20(tokenAddressA).transfer() working?

This is transferring tokens directly from tokenA. I want to first transfer these tokens to Handler amd then when users meet certain requirements handler should transfer these tokens from its own balance to the users not from tokenA or tokenB address directly