Hi everyone
I want to get external function with abi.encode from another contract and use it to other contract so could you explain me how to do that?
for exampele: I want to get func1 from myContract :
(myContract memory function(uint) returns(address) func1) = abi.decode(_data,(myContract.func1(uint));
Is this line correct or not?If not could you edit that in correct way?
thanks for your attention.
Good question but it doesn't seem to be possible. I think this should work if abi.decode supported function types, but it doesn't compile:
contract FooScript is Script {
function run() public {
bytes memory d = abi.encode(this.test);
function (bytes memory) external x = abi.decode(d, (function (bytes memory) external));
}
function test(bytes memory a) public {
console.logBytes(a);
}
}
thanks frangio,
Due to the your answer we can use other contract functions in two ways:
1.inheritance for public and internal functions
2.import contact and we have contract's address like:
myContract("0x...").func1(uint);
for external functions
are these only two ways to use functions from another contract or we have something else?
I don't understand what you want to achieve.
An external function pointer is pair of an address and a function selector. You can use that to invoke a function if you know its signature.
If you already know the function name/parameters then you can simply create an interface for it that defines that function and then use that in your contract.
okey I got it.thanks frangio,CryptoWorld