How to encode function with parameters and execute it within solidity executeCall
Lets start with this example for safeTransferFrom function and its parameters. Go to remix and add this code, then compile it
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity ^0.8.17;
contract Encode {
address from = 0x55C21585007bC89202Bc7eed9B315c8eaB4190A8;
address to = 0xB1620c0547744DeDD30F40a863c09D1964532F8C;
uint id = 1;
function encodeWithSignature(
) external returns (bytes memory) {
return abi.encodeWithSignature("safeTransferFrom(address,address,uint256)", from, to, id);
}
}
Replace parameters in encodeWithSignature with your function that you want to call and parameters used in it.
Output of above will be following bytecode
0x42842e0e00000000000000000000000055c21585007bc89202bc7eed9b315c8eab4190a8000000000000000000000000b1620c0547744dedd30f40a863c09d1964532f8c0000000000000000000000000000000000000000000000000000000000000001
With that code you can go to etherscan and fill data for executeCall like below.
First field is ether value you want to send to the contract where you are calling executeCall (as its payable function), to field is what external contract address you want to call, then there is value field and that is amount of ether you want to send to that external contract. Finally data is where you pass that generated bytecode. Make a write and this will be executed