Declare Your Variables

Let assign real values to our data structure

Now we have defined our data structure, let's define some variables which will help us implement EIP-712 standard.

mapping(address => uint256) public nonces;
​
bytes32 internal constant EIP712_DOMAIN_TYPEHASH = keccak256(bytes("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)"));
bytes32 internal constant META_TRANSACTION_TYPEHASH = keccak256(bytes("MetaTransaction(uint256 nonce,address from)"));
bytes32 internal DOMAIN_SEPARATOR = keccak256(abi.encode(
EIP712_DOMAIN_TYPEHASH,
keccak256(bytes("Quote")),
keccak256(bytes("1")),
42, // Kovan
address(this)
));

EIP712_DOMAIN_TYPEHASH

Hash made using types of EIP712Domain struct which will be used to verify the types of incoming data included in the signature.

META_TRANSACTION_TYPEHASH

Hash made using types of MetaTransaction struct which will be used to verify the types of incoming data included in the signature.

DOMAIN_SEPARATOR

Define the domain separator hash with real values as per our DApp. Since our DApp is on kovan network, we set chainId as 42 here.

nonces

This is a map of user address and a nonce(number used only once) value. It helps in preventing the replay attack so that user don't end up producing same signatures even if he sign the same data again.