Solidity Call Function
Code: https://solidity-by-example.org/call/
Note: I changed this code and I found a small error (I wrote to Smart Contract Engineer)
RECEIVER
CALLER
What is the Problem ?
Contract Caller does not know the source code for the Contract Receiver.
But….
It knows the address of contract Receiver(_addr) and the function to call(YouCanCallMe).
Action…
Deploy the receiver contract.
Deploy the caller contract.
Copy the receiver contract address (_addr)
Open the Caller contract and paste Receiver contract address(_addr) to the testCall function add 5 ether to the value(msg.value).
Click the TestCall.
We can control it.
Bingo ! Receiver contract takes the 5 ETH.
Now, we try to sent 5 ether to the function does not exict in Receiver contract. There is no function “TouCanCallMe” in receiver contract.
Open the Caller contract and paste Receiver contract address(_addr) to the testCallDoesNotExist function and add 3 ether to the value(msg.value).
Click the testCallDoesNotExist.
Yes. There is no “TouCanCallMe” function in receiver contract but we have fallback function and receiver contract takes this ether using the fallback function.Receiver contract’s balance is now 8 ETH.
Doç.Dr. Engin YILMAZ