elranu
February 25, 2021, 5:54pm
1
Hi,
I´m looking for a full code example of a Meta-transaction using the Relayer and the web browser. The meta-transaction example should be signed on the front-end with Metamask with eip712. I have checked https://github.com/spalladino/workshop-defender-meta-txs And this example does not have the front-end code.
Can you recommend me an example or a library? so I can join both parts web/backend. As GSN examples.
Thanks!
Mariano
1 Like
Hey @elranu ! The frontend code is in the app
folder, the function you want in particular is:
async function sendMetaTx(registry, provider, signer, name) {
console.log(`Sending register meta-tx to set name=${name}`);
const url = process.env.REACT_APP_WEBHOOK_URL;
if (!url) throw new Error(`Missing relayer url`);
const forwarder = createInstance(provider);
const from = await signer.getAddress();
const data = registry.interface.encodeFunctionData('register', [name]);
const to = registry.address;
const request = await signMetaTxRequest(signer.provider, forwarder, { to, from, data });
return fetch(url, {
method: 'POST',
body: JSON.stringify(request),
headers: { 'Content-Type': 'application/json' },
mode: 'no-cors',
});
}
Also, note that we have migrated the workshops code to a single repo under the OpenZeppelin org on github at https://github.com/OpenZeppelin/workshops
1 Like
elranu
February 25, 2021, 7:02pm
3
Sorry, I read directly the scripts I didn´t see the app.
Thanks!
Mariano
1 Like
No worries! Let me know if you have any questions about how it works!
1 Like
Hi @elranu ,
Welcome to the community
There is also a video recording of the workshop, I found this helpful when setting up my relayer along with the code from the workshop.
1 Like