The Relayer, a crucial system component, bridges email communication and blockchain transactions, ensuring secure information processing.
Below is a diagram of the Relayer infrastructure and its component interactions.
To build the Relayer, you need to understand its three main components:
Before building the Relayer, ensure that you have the following prerequisites installed:
build-essential
or equivalent for your operating system)For Ubuntu users, you can install build-essential
by running:
sudo apt-get update
sudo apt-get install build-essential
For macOS users, you can install the necessary tools by installing Xcode Command Line Tools:
xcode-select --install
To run the prover locally, follow these steps:
Prepare the Environment: Ensure your system has Node.js, npm, and Python 3 installed. The prover relies on specific npm packages and Python modules to function correctly.
npm install -g snarkjs@latest
pip install -r requirements.txt
Run the curl commands and script in the prover/local_setup.sh
file.
Start the prover
python3 packages/prover/local.py
The prover leverages Modal, a cost-effective, serverless computing platform activated as needed, for generating zk proofs. Visit site here: https://modal.com
Set Up Modal Tokens: Follow the instructions in /Relayer.Dockerfile
to set up your Modal tokens.
Start the Prover Service: Run the following command to start the Prover service using Modal:
modal run python packages/prover/local.py
Database Setup Steps:
docker run --rm --name email-wallet-db -e POSTGRES_PASSWORD=p@ssw0rd -e POSTGRES_USER=emailwallet -e POSTGRES_DB=emailwallet -p 5432:5432 postgres
.env
:
DATABASE_URL=postgresql://emailwallet:p@ssw0rd@localhost:5432/emailwallet
Note: The system triggers on emails with accountCode
in the subject, for new account setups. Reply-email functionality for account transport will be deprecated.
.env
file in packages/relayer
by taking a copy from .env.example
.cp packages/relayer/.env.example packages/relayer/.env
.env
fileRegarding to use thegraph, you need to get your own TheGraph API key.
After that, you can replace the subgraph url in the env file with your TheGraph API key.
See this URL https://thegraph.com/studio/apikeys/
CORE_CONTRACT_ADDRESS= # Address of the deployed wallet contract.
PRIVATE_KEY= # Private key for Relayer's account.
CHAIN_RPC_PROVIDER=http://127.0.0.1:8545
CHAIN_ID=11155111 # Chain ID of the testnet.
# IMAP + SMTP (Settings will be provided by your email provider)
IMAP_DOMAIN_NAME=imap.gmail.com
IMAP_PORT=993
AUTH_TYPE=password
SMTP_DOMAIN_NAME=smtp.gmail.com
LOGIN_ID= # IMAP login id - usually your email address.
LOGIN_PASSWORD="" # IMAP password - usually your email password.
PROVER_ADDRESS="http://0.0.0.0:8080" # local or modal URL
FEE_PER_GAS=0 # Fee per gas in wei.
DATABASE_URL= "postgres://test@localhost/emailwallet_test"
RELAYER_EMAIL_ADDR=
RELAYER_HOSTNAME="example.com"
WEB_SERVER_ADDRESS="127.0.0.1:4500"
CIRCUITS_DIR_PATH= #Path to email-wallet/packages/circuits
SUBGRAPH_URL=https://gateway-arbitrum.network.thegraph.com/api/[api-key]/subgraphs/id/AFNg1WfLo4dv1tfixaKCvWTVnFGEsVhVKx2Kef1dbt9G # Please replace [api-key] with your TheGraph API key
INPUT_FILES_DIR_PATH= #Path to email-wallet/packages/relayer/input_files
EMAIL_TEMPLATES_PATH= #Path to email templates, e.g. ./packages/relayer/eml_templates/
ONBOARDING_TOKEN_ADDR=
ONBOARDING_TOKEN_AMOUNT=100
ONBOARDING_TOKEN_DISTRIBUTION_LIMIT=10
ONBOARDING_REPLY="You received 100 TEST!"
CANISTER_ID="i73e6-2qaaa-aaaan-qepxa-cai"
PEM_PATH="./.ic.pem"
IC_REPLICA_URL="https://a4gq6-oaaaa-aaaab-qaa4q-cai.raw.icp0.io/?id=i73e6-2qaaa-aaaan-qepxa-cai"
JSON_LOGGER=false
cd ../../
docker buildx build -t email_wallet_v1_relayer:latest-arm -f Relayer.Dockerfile . \
--build-arg modal_token_id=${MODAL_TOKEN_ID} \
--build-arg modal_token_secret=${MODAL_TOKEN_SECRET}
docker buildx build -t email_wallet_v1_relayer:latest -f Relayer.Dockerfile . \
--build-arg modal_token_id=${MODAL_TOKEN_ID} \
--build-arg modal_token_secret=${MODAL_TOKEN_SECRET} \
--platform=linux/arm64
docker run \
-p 80:80 \
-v $(pwd)/.env:/email-wallet/packages/relayer/.env \
email_wallet_v1_relayer:latest
Update Contract ABIs: Ensure the contract ABIs are up to date in packages/relayer/abi/
directory.
cargo run --release -- setup
This step registers the relayer’s details on the blockchain, preparing it for operation.
cargo run --release
Send 1 ETH to another@email.com
. Relayer will deploy wallet for you for the first time and you will need to fund it externally as the wallet have no balance.cd ../../
docker buildx build -t email_wallet_v1_relayer:latest-arm -f Relayer.Dockerfile . \
--build-arg modal_token_id=${MODAL_TOKEN_ID} \
--build-arg modal_token_secret=${MODAL_TOKEN_SECRET}
cd ../../
docker buildx build -t email_wallet_v1_relayer:latest -f Relayer.Dockerfile . \
--build-arg modal_token_id=${MODAL_TOKEN_ID} \
--build-arg modal_token_secret=${MODAL_TOKEN_SECRET} \
--platform=linux/arm64
Create .env
in the execution directory with reference to env_example
.
docker run \
-p 80:80 \
-v $(pwd)/.env:/email-wallet/packages/relayer/.env \
-e SETUP=false
email_wallet_v1_relayer:latest
The Relayer’s incentive is transaction fees collected from the sender.
Specifically, the Relayer operator can set a fee per gas in wei to the ENV file.
However, that value must be less maxFeePerGas
parameter defined in our contract, which is 2 gwei now.
When the Relayer posts the email-triggered transaction along with the ZK proof of email, our contract calculates the total amount of fee in wei as follows:
validateEmailOp
, the fee is zero.Note that our contract catches any errors during the execution of the transaction in Step 2 instead of making the transaction fail because the Relayer cannot always simulate if the execution returns errors in general cases before posting it on-chain. Therefore, the Relayer can always collect the fee as long as the transaction passes the validation in Step 1. This design refers to the bundler’s fee mechanism in ERC-4337.