eth-forwarder-sample
demonstrates ERC-2771 (Meta-Transactions) using Forwarder and Recipient smart contracts. It is inspired by the MetaTxDemo project, which provides additional examples of meta-transactions.
This project serves as a sample for learning Ethereum meta-transactions. It deploys two smart contracts, Forwarder and Recipient, that conform to the ERC-2771 standard.
-
Clone the repository:
git clone https://github.com/nabeo114/eth-forwarder-sample.git cd eth-forwarder-sample
-
Install dependencies:
-
Hardhat:
cd hardhat npm install
-
Frontend:
cd ../frontend npm install
-
Configure the
.env
file:Create a
.env
file in thehardhat
directory with the following variables:INFURA_API_KEY=your_infura_api_key_here ACCOUNT_PRIVATE_KEY=your_private_key_here KEYSTORE_PASSWORD=your_keystore_password_here
Note:
- The
ACCOUNT_PRIVATE_KEY
will be used to deploy the Forwarder and Recipient contracts and also act as the relayer for meta-transactions. - Contracts are deployed on the Polygon Amoy testnet. Ensure the
ACCOUNT_PRIVATE_KEY
is funded with MATIC tokens using the Polygon Faucet. INFURA_API_KEY
: Obtain this from Infura after creating an account.KEYSTORE_PASSWORD
: Used to encrypt the keystore; you can set this to any desired string.
- The
-
Create accounts and deploy the smart contracts:
cd hardhat npm run account npm run deploy
-
Set up the frontend:
cd ../frontend npm start
- Relayer and User Accounts: The demo creates one relayer account (using the
ACCOUNT_PRIVATE_KEY
in the.env
file) and two user accounts. - ERC20 Token Minting: ERC20 tokens can be minted to user accounts.
- Token Transfers: Transfers between user accounts are performed by the relayer account.