This is an implementation of Meta Transactions.
We define MetaMsg and encode it with EIP712.
MetaMsg has 8 fields:
- sender: the sender of Meta Transaction
- to: the contract address
- value: number of wei sent with Meta Transaction
- nonce: nonce of the sender record by the contract
- refer: dependent Meta Transaction
- expire: the time at which a transaction expires
- gasPayload: function signature and arguements encode in Solidity ABI. This used for repaying the submitter/relayer.
- payload: function signature and arguements encode in Solidity ABI
MetaMsg in solidity:
string private constant MetaMsg_TYPE = "MetaMsg(address sender,address to,uint256 value,uint256 nonce,bytes32 refer,uint256 expire,bytes32 gasPayload,bytes32 payload)";
bytes32 private constant MetaMsg_TYPEHASH = keccak256(abi.encodePacked(MetaMsg_TYPE));
struct MetaMsg{
address sender;
address to;
uint256 value;
uint256 nonce;
bytes32 refer;
uint256 expire;
bytes32 gasPayload;
bytes32 payload;
}
Demo is here.