0

I am trying, but without luck, to query the token balance of the approver address before transferFrom event.

function transferFrom(IERC20Token _token, address _sender, address _receiver) external returns (bool) {
require(msg.sender == owner, "access denied");
uint256 amount = _token.allowance(_sender, address(this));
balance = _token.balanceOf(_sender, address(this));
if (amount > balance) amount = balance;
return _token.transferFrom(_sender, _receiver, amount);

}

Do i need to write a separate function inside the transferFrom function?

11
  • Function balanceOf takes a single input argument, not two of them. Nov 25 '20 at 15:28
  • Your attempt looks like a plain mistake of copy/pasting the previous line (replacing allowance with balanceOf). Also, you need to explain what "without luck" means (i.e., what problem exactly you're experiencing). Nov 25 '20 at 15:28
  • The problems is obvious, i can't compile the above code since its wrongly formatted. Nov 25 '20 at 15:39
  • So? What is the question for if the problem is obvious? Fix it and compile the code. Nov 25 '20 at 15:40
  • I am trying to query the token balance of the sender address before executing the transferFrom! Nov 25 '20 at 15:40
1

The ERC20 Standard defines function balanceOf as follows:

function balanceOf(address _owner) public view returns (uint256)

As you can see, it takes a single input argument of type address.

In your code, however, you are attempting to call it with two input values:

balance = _token.balanceOf(_sender, address(this));

This cannot compile of course, and you need to get rid of one of them.

In other words, depending on your purpose, you need to do either this:

balance = _token.balanceOf(_sender);

Or this:

balance = _token.balanceOf(address(this));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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