Note: The called function should be payable if you send value and the value you send should be less than your current balance

I want to call the function of contract A in my contract B. I call the balanceOf function to display the balance normally, but when I call the transfer function, it does display Note: The called function should be payable if you send value and the value you send should be less than your current balance. I can't even add payable, can anyone help me?
my A contract

function transfer(address _to, uint256 _value)
        external
        payable
        returns (bool success)
    {function transfer(address _to, uint256 _value)
        external
        payable
        returns (bool success)
    {
        require(balancesOf[msg.sender] >= _value);
        require(_to != address(0));
        require(balancesOf[_to] + _value > balancesOf[_to]);
        balancesOf[msg.sender] -= _value;
        balancesOf[_to] += _value;
        return true;
    }

my B contract

interface X {
    function balanceOf(address _owner) external view returns (uint256 balance);
    function transfer(address _to, uint256 _value)external payable returns (bool success);
}

contract A {
    X public token;
    
    constructor(address payable _address){
        token = X(_address);

    }
    
    function GetbalanceOf(address _owner) external view returns (uint balance) {
        return token.balanceOf(_owner);
    }
    function buy(address xx) external  {
         token.transfer(xx,100);
    }
}

Hello @zcjxfflove

I'm not exactly sure what you are trying to do, so my answer may be off, but the main issue might be with a misunderstanding of how ERC20 works in the context of contract composition.

  • If Alice has 100 tokens, and calls transfer on contract A, Alice's tokens are going to be transferred
  • If Alice has 100 tokens, and calls buy on contract B, contract B will call transfer on contract A, and contract A will try to move tokens out of B's balance (not out of Alice's balance).

So in order for B's buy function to work, B needs to be the owner of tokens.