What exactly is the function of Defender's Relay when using metatransactions?

So I'm new to Defender and Relay. I'm trying to create a very simple contract to learn the new concepts. I have been going through the sample codes in the workshop but I can't tell where Relay comes into the picture.

I do know what Relay is for and I've seen a client library for using it but I got confused when I saw signing functions in the sample workshop codes and they weren't using the relay client library. I thought Relay will handle the signing, so why do we have to do the signing ourselves? It's either I am missing something or they are two approaches to achieve the same result. I just need some clarifications please.

I will also appreciate links to resources that will help me understand better. Thanks

Hey @isoteriksoftware! First of all, if you haven't watched the video for the meta transactions workshop, I strongly suggest you go through it first, instead of jumping directly to the sample code.

When using meta-txs, in general, you have three parties: the user, the app, and the relayer. Your goal is to get the user to send a transaction to the application. However, you don't want the user to pay any gas. So, instead of having the user send the tx themselves, you ask them to sign a message using their private key (each user needs their own wallet with their own private key!). Then, in your contracts, the application manually verifies the message signature to see who's the sender of the message.

The missing part here is getting the signed message to the application contract. That's where the relayer comes in. The relayer is a service that just takes users' signed messages, wraps them in a transaction, and sends it to the application contract, paying the gas for it. You can use a Defender Relayer for it, an OpenGSN one, or anything that suits your needs.

Hope this helps clarify it! You can also check out the OpenGSN documentation about meta-txs.

1 Like

@spalladino thanks alot. I think I have a clearer picture now. You're the best!

1 Like