-
Notifications
You must be signed in to change notification settings - Fork 0
/
Call.sol
31 lines (30 loc) · 992 Bytes
/
Call.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// It's A call documentation but it's not recomended
// Better way is send, not call.
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
contract Receiver {
event Received(address caller, uint amount, string message);
fallback() external payable {
emit Received(msg.sender, msg.value, "Fallback was called");
}
function foo(string memory _message, uint _x) public payable returns (uint) {
emit Received(msg.sender, msg.value, _message);
return _x + 1;
}
}
contract Caller {
event Response(bool success, bytes data);
function testCallFoo(address payable _addr) public payable {
(bool success, bytes memory data) = _addr.call{value: msg.value, gas: 5000}(
abi.encodeWithSignature("foo(string,uint256)", "call foo", 123)
);
emit Response(success, data);
}
function testCallDoesNotExist(address payable _addr) public payable {
(bool success, bytes memory data) = _addr.call{value: msg.value
}(
abi.encodeWithSignature("doesNotExist()")
);
emit Response(success, data);
}
}