I have created a game where I have an interface and a contract with a Game function But when I compile it throws an exception:
TypeError: Type is not callable myGameContract.depositPlayer(0, msg.value)();
It is clear that it refers to the fallback after: msg.value)();
But, I don't know how to fix the interface.
interface Game{
function depositPlayer(uint256 _pid, uint256 _amount) external payable;
function myGame(address _reciever) external payable {
addressBoard = payable(_reciever);
myGameContract= Game(addressBoard );
myGameContract.depositPlayer(0, msg.value)();
I need in this case it to contain a fallback ();
More bellow:
For more clarification, comment as the answer indicates, only the call function contains a fallback
You can execute an external function without the empty parentheses.
Example that executes the external depositPlayer
function:
myGameContract.depositPlayer(0, msg.value); // removed the `()`
You can execute the fallback
function by sending an empty data
field.
address(myGameContract).call("");
But the fallback function is executed when no suitable function (specified in the data
field) is found. It's not executed after each function. So you can't execute both depositPlayer
and fallback
in the same call (except for executing depositPlayer
from the fallback
).