Encoding function call data from upgradeable contract itself

https://docs.openzeppelin.com/upgrades/2.8/creating-upgradeable-from-solidity#encoding_call_data
This particular section of the article shows how to encode the function call data from node and then pass it to contract. However, I have a use case where I have to encode the call data from contract itself. Is that possible?

P.S. I had asked about this before here but had no response. So I am just rephrasing my question in a different way.

1 Like

Hello @sharma66mahesh! You can use Solidity’s native ABI Encoding and Decoding Functions.

Here is an example from OpenZeppelin Contracts:

    bytes memory returndata = to.functionCall(abi.encodeWithSelector(
        IERC721Receiver(to).onERC721Received.selector,
        _msgSender(),
        from,
        tokenId,
        _data
    ), "ERC721: transfer to non ERC721Receiver implementer");

I’m closing Is there a way to encode/decode the initializer function with its arguments as a duplicate.

2 Likes