Solidity encodeWithSignature – How to Concatenate encodeWithSignature with Another Data Type in Solidity

abisolidity

There are a abi.encodeWithSignature("foo((bytes))", info), but in addition to calling the function in another contract I want to send more data as an address to retrieve with msg.data, for example. It is possible?

Best Answer

I'm not really sure of what your are looking for but if you want to send more parameters than required in the signature you can do something like that

function send(bytes memory info, address moreInfo) public {
    (bool success,) = address(this).call(abi.encodePacked(abi.encodeWithSignature("foo((bytes))", info), moreInfo));
}
    
function foo(bytes memory info) public {
    address moreInfo = address(0);
    if (msg.data.length >= 24) { // you should check msg.sender too
        assembly {
            moreInfo := shr(96,calldataload(sub(calldatasize(),20)))
        }
    }
    // ...
}
Related Topic