Let's say I have a contract called contractA
.
It has the function:
function bla(address test) {
// way 1. test.call(abi.encodeWithSignature("first4bytes", arg1, arg2))
// way 2. testAddrInterface(test).functName()
}
As you can see, in the way 2 example, I just use the interface so that I can call functName
on it directly instead of using way 1.
I've seen lots of places that people use way 1. Why ? what's wrong with Way 2? if you tell me way 2 contains more code and is more gas costly, I will ask: are the interfaces still included in the final code and is this the only reason why Way 1 is better ?
call
.call
a function by its string prototype, the actual decision of "where to jump" occurs only during runtime.call
allows you to actually execute a function without knowing its return-value type (as you can read at the bottom of the answer to the question that I linked above).