- Uses sample code from OpenZeppelin Defender workshop
- only need to deploy
Verifier
contract from generatedverifier.sol
- use
snarkjs generatecall
in the circom root folder to generate call data that returnstrue
when submitted to theVerifier
contract
Code for the workshop on Meta-Transactions using OpenZeppelin Defender.
This project consists of a sample names registry contract, that accepts registrations for names either directly or via a meta-transaction, along with a client dapp, plus the meta-transaction relayer implementation.
Live demo running at defender-metatx-workshop-demo.openzeppelin.com.
curl
-X GET
-H 'Accept: application/json'
-H 'Content-Type: application/json'
-H "X-Api-Key: AM8iFEdNdPftCCWUwcKgQDwEPzbq65Yu"
-H "Authorization: Bearer 5dZKF4qtTDAjJVe7KZsfSiYNko1K7MGmgxmUp21p2CrzxgvRMKC5sPrfoF4e1m9b"
"https://defender-api.openzeppelin.com/relayer/relayers/summary"
0x446008101d998584837e01c3bbc0d3055e37b189 ## relayer ?
0xBb0582EaD520EDE2996D62A5e44A3d86e056991B,100000000000000,0x00
yarn hardhat run scripts/deploy-multisigWithVerifier.js --network mumbai
MinimalForwarder: 0x9B6CB4DD4836b2AB59fe84938f062e4504c90F83 MultiSigWalletMetaTxnWithVerifier: 0x93f80F3b22907d01098B2Ac0311A35d4FDD46736
36081fc7cc32451b2ac9667bfb9815f61e5d8ac07c88db19c913742820939495
MinimalForwarder: 0xC32D8793ef43238878171fa83e1A975b1ffb5173 MultiSigWalletMetaTxnWithVerifierNew: 0xFeF4977cB4620714D45e00f759CE82FE0A28e378
36081fc7cc32451b2ac9667bfb9815f61e5d8ac07c88db19c913742820939495, 0x446008101d998584837e01c3bbc0d3055e37b189
relayer: 0x446008101d998584837e01c3bbc0d3055e37b189 factory owner: 0x264dABD1fbF0da59Cb22E0B4b6146aA26dA669BF factory: 0xAaA2F4E5eEAD0b3adf1beC7a1C64D22719B8dbD8 multiSig #1: 0xa611EEE4c541CC8B64644C515203AcE64D5b3186
executeTransaction
["0x2f858a529883884b2a751df3f3e59ad973e93e45031859a95b924841ff8a47cd", "0x170c243fa23e03642f00b30bfce669275bd154965ce93bd76b58daa1ebf90569"],[["0x29c23a513200cf1c60e726f7351fb330762078fecceaa38d52a305fa79635360", "0x1078e87b7862eb0621157f2410b2f4c6c5dadb34b03e1c9a59a166ab28f86ee6"],["0x006e79abb7cbd637f0fff563d6825771fadf3aef4ed2d86fa287e2c5d0b1d77f", "0x2dbcf92f9caabe2c19b7d4a67f0f72881e74f921b2142ac5809cac6435735906"]],["0x03df054693625be70b38e321d1bb677bccb9c7aa45d9be80cb5e4550638a8b06", "0x062fb5f6c67291e07b672fe0dae51c0ce786687a44393adf56520b3038c805cb"],["0x0000000000000000000000000000000000000000000000000000000000000001","0x00000000000000000000000000000000000000000000000057f76ebf9af4dcaa","0x00000000000000000000000000000000000000000000000027a829f96d033294","0x0000000000000000000000000000000000000000000000005fc544d55cdee823","0x00000000000000000000000000000000000000000000000027a84712e4b22c41","0x304f7e195262eb4e09a76bf88f3c0e0146c55e8a8c0c37704c38a9bb51a7f9b2"],
36081fc7cc32451b2ac9667bfb9815f61e5d8ac07c88db19c913742820939495,
0xBb0582EaD520EDE2996D62A5e44A3d86e056991B,
160000000000000,
"0x00"
app
: React code for the client dapp, bootstrapped with create-react-app.autotasks/relay
: Javascript code for the meta-transaction relay, to be run as a Defender Autotask, compiled using rollup.contracts
: Solidity code for the Registry contract, compiled with hardhat.scripts
: Custom scripts for common tasks, such as uploading Autotask code, signing sample meta-txs, etc.src
: Shared code for signing meta-txs and interacting with the Forwarder contract.test
: Tests for contracts and autotask.
yarn deploy
: Compiles and deploys the Registry and Forwarder contracts to xDAI, and writes their addresses indeploy.json
.yarn sign
: Signs a meta-tx requesting the registration ofNAME
, using the private key defined inPRIVATE_KEY
, and writes it totmp/request.json
.yarn events
: Lists all theRegistered
events from the deployed contract on xDAI.yarn invoke
: Invokes the relay Autotask viaWEBHOOK_URL
with the contents oftmp/request.json
generated byyarn sign
.yarn upload
: Compiles and uploads the Autotask code toAUTOTASK_ID
.yarn relay
: Runs the relay Autotask script locally, using the Defender Relayer forRELAY_API_KEY
.yarn test
: Runs tests for contracts and Autotask using hardhat.
Expected .env
file in the project root:
PRIVATE_KEY
: Private key used for deploying contracts and signing meta-txs locally.RELAYER_API_KEY
: Defender Relayer API key, used for sending txs withyarn relay
.RELAYER_API_SECRET
: Defender Relayer API secret.AUTOTASK_ID
: Defender Autotask ID to update when runningyarn upload
.TEAM_API_KEY
: Defender Team API key, used for uploading autotask code.TEAM_API_SECRET
: Defender Team API secret.
Expected .env
file in /app
:
REACT_APP_WEBHOOK_URL
: Webhook of the Autotask to invoke for relaying meta-txs.REACT_APP_QUICKNODE_URL
: Optional URL to Quicknode for connecting to the xDAI network from the dapp.
To run the workshop code yourself on the xDai network you will need to sign up to Defender and apply for mainnet access, or change the code to use a public testnet.
First fork the repository and then Git Clone your fork to your computer and install dependencies
$ git clone https://github.com/OpenZeppelin/workshops.git
$ cd workshops/01-defender-meta-txs/
$ yarn
Create a .env
file in the project root
PRIVATE_KEY="Private key used for deploying contracts and signing meta-txs locally"
RELAYER_API_KEY="Defender Relayer API key, used for sending txs with yarn relay"
RELAYER_API_SECRET="Defender Relayer API secret"
AUTOTASK_ID="Defender Autotask ID to update when running yarn upload"
TEAM_API_KEY="Defender Team API key, used for uploading autotask code"
TEAM_API_SECRET="Defender Team API secret"
Store the value of a new private key in our projects .env
file and fund the address with xDai (You can use a faucet).
Deploy the MinimalForwarder and Registry contracts to xDai
$ yarn deploy
Create a relayer using Defender Relay on xDai.
Fund your xDai relayer (You can use a faucet).
Create an API key for your relayer and store the relayer API key and API secret in our projects .env
file.
Sign a request to register a name, this will create a request in tmp/request.json
that we can then view
$ NAME=alice yarn sign
$ cat tmp/request.json
We can then use the script to send the request to our relayer, and view the transaction on Blockscout. We can also view the name registrations.
$ yarn relay
$ yarn events
Create an Autotask in Defender, with a webhook trigger and connected to our xDai relayer. We can leave the code as is as we will update it using a script.
Once the Autotask is created get the Autotask ID from the URL (https://defender.openzeppelin.com/#/autotask/[AUTO_TASK_ID]) and store it in our projects .env
file.
To update our Autotask we need a Team API key. From the right hand menu in Defender, select Team API Keys, then Create API Key, with Capabilities to Update Autotasks code and a note such as Update Autotask code. Copy the Team API key and secret and store it in our projects .env
file.
We can then update our Autotask code programmatically by uploading our code:
$ yarn upload
We can sign another name for the registry and then send a request to the Autotask webhook to relay and finally view the registry.
$ NAME=alice yarn sign
$ curl -XPOST 'Your Autotask Webhook URI goes here' -H 'Content-type: application/json' -d '@tmp/request.json'
$ yarn events
Copy the Autotask Webhook URI and store in our apps .env
file (in the app
directory).
We can then install dependencies using yarn
and run the app.
$ yarn
$ yarn start
- Open app: http://localhost:3000/
- Connect MetaMask to xDai network and change to xDai network
- Enter a name to register and sign the metatransaction in MetaMask
- Your name will be registered, showing the address that created the metatransaction and the name.