0

Is it possible to have a "side balance" of an ERC20 token in the same contract? So when it's queryable with token.balanceOf(address(this)), for example, it doesn't appear until a certain instruction (aka function call) is made?

For example:

Contract A has a WETH balance of 100, and moves 25 WETH to this "side balance" within the same contract, so it'd be 75 WETH in-balance (queryable and transferrable through any of the typical ERC20 methods) and 25 WETH in this side balance.

So if you'd do WETH.balanceOf(address(contractA)), the output would be 75.

And if you'd like to move the 25 WETH back to the "main balance", you'd call the designated instruction like contractA.moveToMain(), and doing WETH.balanceOf(address(contractA)) now would throw an output 100 WETH.

Is this possible in solidity and/or assembly?

Thanks!

1 Answer 1

0

It's impossible to have a "side balance" of an ERC20 token in the same contract.

If you need to have a "side balance", you can deploy another contract to use it as a "side balance". Use transfer, transferFrom methods to send and received the ERC20 tokens from the main contract to the "side balance" contract.

4
  • Having another contract is not an option in my case. Someone told me that it can be done through zk proofs, but that's all they mentioned. So I'm still wary on how a proof would invalidate part of a balance
    – dNyrM
    Commented Aug 19, 2022 at 14:51
  • Could be ETH balance as well, doesn't have to be ERC20 exclusively
    – dNyrM
    Commented Aug 19, 2022 at 14:56
  • Got it, but I'm not sure if zk proofs solve your problem. Commented Aug 19, 2022 at 14:58
  • Yea, no idea either. I started this post with the basis of being impossible what I want, but this dude told me this so might as well give it a shot and see if it can be done.
    – dNyrM
    Commented Aug 19, 2022 at 15:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.