I've been messing around with the abi.encode... functions and I think I have a good grasp of the differences, except abi.encode and abi.encodeWithSelector. Because, they give similar but slightly different results, so I'm not sure when to use one or the other.
abi.encodeWithSelector(bytes4(keccak256("add(uint256,uint256)")), 10,10); abi.encode(bytes4(keccak256("add(uint256,uint256)")), 10, 10); The output of encodeWithSelector is
0x771602f7000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a and the output of encode is
0x771602f700000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000a and when I use delegatecall the return value of encodeWithSelector is 20, as expected, but encode is 42949672960