To my understanding, Yes!
Of course you have to do the abi.encodeWithSignature beforehand and add b as input as type address.
You can also specify the amount of gas and the msg.value as shown in the code below.
Side note:
When you call abi.encodeWithSignature the signature has to exactly match, e.g. uint instead of uint256 will lead to a failed call, although it is usually implied.
This contract for example enables you to call a function with one uint as input and specify the msg.value and gas:
pragma solidity "0.8.4";
contract externalcaller{
function encodeforcall(string calldata signature, uint input)
pure
public
returns(bytes memory)
{
return abi.encodeWithSignature(signature, input);
}
function call(string calldata signature, uint input, address b,
uint _gas, uint _weiamount)
external
payable
returns
(
bool,
bytes memory
)
{
bytes memory _calldata = encodeforcall(signature, input);
(bool success, bytes memory data) =
b.call{gas: _gas, value: weiamount}(_calldata);
return (success, data);
}
}
contract callee{
uint constant b = 1312;
function getbplusa(uint256 a) public payable returns(uint){
return b+a;
}
}