0

A address sends X amount of token to B address. As this transaction happens inside the interface function _transfer(address recipient, uint256 amount) I know that the amount variable holds the token number that A sends to B.

My question is: does the address type has a function which let me retrieve amount after transfer has been called by referring to the transaction address? Not historically, just until the current contract's (contract of one transaction) lifecycle ends.

Based on this question I assume address(this) returns the contract's own address and can be called with balanceOf but it won't return a value until I don't call _transfer. Is it right?

 function _transfer(address sender, address recipient, uint256 amount) internal {
      uint256 tokenAmountInCurrentContract = amount;
      //...
 }

 function retrieveCurrentContractTokenAmount() internal returns (bool) {
      // would this do it?          
      return balanceOf(address(this));
 }
 
 function balanceOf(address account) external view returns (uint256) {
      return _balances[account];
 }
2
  • What are you trying to achieve? The function balanceOf should be usable at any time. If you call it before _mint it should return the previous balance, and after _mint it should return the new balance.
    – Ismael
    Commented Nov 14, 2021 at 4:41
  • @Ismael I am implementing a tax feature and I see everybody is sending the swapped ETH to address(this)
    – rihekopo
    Commented Nov 15, 2021 at 17:20

0

Your Answer

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

Browse other questions tagged or ask your own question.