When we call a function on an external contract, we need to put calldata as an argument.
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.10;
contract test1 {
mapping (address => uint256) public _count;
function countNum(address sender) public {
_count[sender] ++;
}
}
contract test2 {
function call(address _address,bytes memory data) public {
_address.call(data);
}
function getdata1(bytes memory data,address from) public view returns(bytes memory) {
return abi.encodePacked(data,from);
}
function getdata2(address _spender) public pure returns(bytes memory) {
return abi.encodeWithSignature("countNum(address)", _spender);
}
}
I called countNum() of contract test1 from call() in contract test2.
The code inside getdata1() and getdata2() uses different abi. getdata1() use encodePacked, getdata2() use encodeWithSignature. The return values of the two functions are different.
However, when both result values are put in call() , Both successfully called the countNum() function.
The two data are different values, why were both able to succeed?
.. and Thank you so much for attaching the link to the related content...
getdata1
asdata
?