Make ERC2771Context _trustedForwarder internal

I want to add a setter to change the trusted forwarder in contract, but the variable is declared private so after construction I cannot change it.

contract SeteableTF is ERC2771Context, Ownable {
    function setTrustedForwarder(address trustedForwarder) onlyOwner {
        _trustedForwarder = trustedForwarder;
    }
}

Modify the base ERC2771Context contract and add this setTrustedForwarder function in it.

But then I won't use the library but a copy of the source code.

Do you need to use the library? If it doesn't have what you need then make it do what you want it to do lol.

The idea was to suggest something to improve the library so everybody can use it. But for sure in the meanwhile I can copy the file and change it.

Hi @adji, Thank you for your suggestion to improve the library.

We use private variables so that we can have tighter control in the way that the values are modified. For example, we can guarantee that balances and total supply in ERC20 are modified together, and that this modification emits an event. This is a general convention that we follow.

In this particular case, since it's such a simple contract I would encourage you to copy the contract and modify it for your needs.

1 Like