-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path30_TestCall.sol
More file actions
31 lines (25 loc) · 872 Bytes
/
30_TestCall.sol
File metadata and controls
31 lines (25 loc) · 872 Bytes
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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.27;
contract TestCall {
string public message;
uint public x;
event Log(string message);
fallback() external {
emit Log("fallback trigger");
}
receive() external payable { }
function foo(string memory _message, uint _x) external payable returns(bool, uint) {
message = _message;
x = _x;
return (true, 9999);
}
}
contract Test {
bytes public data;
function testFoo(address addr, string calldata message, uint x) external payable {
// 如果用call去调用,参数中是uint的话,需要写完整为uint256 否则会报错
(bool success, bytes memory _data) = addr.call{ value: 200 }(abi.encodeWithSignature("foo(string,uint256)", message, x));
require(success, "call failure");
data = _data;
}
}