I am getting this error after adding ERC2771Context and MinimalForwarder from open-zeppelin to my smart contract:

TypeError: Immutable variables cannot be read before they are initialized.
  --> @openzeppelin/contracts/metatx/ERC2771Context.sol:21:29:
21 |         return forwarder == _trustedForwarder;
   |                             ^^^^^^^^^^^^^^^^^

Error HH600: Compilation failed

What am I missing?

2 Answers 2


Did you set the address of the minimalforwarder as a constructor parameter in your contract's deploy script? If not please pass the address of the minimal forwarder contract as a constructor argument in your deploy script.

If you want more reference on MetaTransactions check out my ERC20MetaTx Employee registry code: https://github.com/praveen-agiratech/AgiraMetaTx it has easy to follow readme guide

Video tutorial I followed: https://www.youtube.com/watch?v=Bhz5LJbq9YY

I hope these will give you an idea about how to use MetaTx in your contracts.


Problem was that I was inheriting Ownable before ERC2771Context. As Ownable uses Context and Context defines _msgSender(), you must inherit ERC2771Context BEFORE Ownable in your smart contracts.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.