Here is an example;
function invoke(address _target, bytes memory _data) internal returns (bytes memory) {
// External contracts can be compiled with different Solidity versions
// which can cause "revert without reason" when called through,
// for example, a standard IERC20 ABI compiled on the latest version.
// This low-level call avoids that issue.
bool success;
bytes memory _res;
// solhint-disable-next-line avoid-low-level-calls
(success, _res) = _target.call(_data);
if (!success && _res.length > 0) {
// solhint-disable-next-line no-inline-assembly
assembly {
returndatacopy(0, 0, returndatasize())
revert(0, returndatasize())
}
} else if (!success) {
revert("VM: wallet invoke reverted");
}
return _res;
}
The target id the address of the contract you are calling,
The data is the function call and argument encoded like this;
bytes memory _data = abi.encodeWithSignature(
"swap(address,address,uint256,uint256,uint256[],uint256)",
fromToken,
toToken,
amount,
minReturn,
distribution,
flag
);
>=
prefix instead of^
. But note it is not always possible to do that, you might have to rewrite that contract to adhere to the latest version of Solidity.