What is relay in ethereum?For doing transactions, any difference? I am not sure the concept of relay, it looks like one account can pay gas for transaction on another account.
1 Answer
Relays are not part of the protocol. They are an emerging pattern for user-facing UI's that simplify user-onboarding by adding flexible payment options for the gas. Users can transfer tokens and interact with contracts without having any ether.
Suppose Alice wants to send a transaction to a Contract using Bob to relay the transaction.
- Alice signs the transaction.
- Alice sends the signed transaction to Bob, off-chain.
- Bob forms a new transaction, with Alice's transaction attached as
data:
- Bob sends the signed transaction, with gas, to Ethereum.
The Contract could be constructed to expect this, and even though the message came from Bob, it can check the data payload's signature and see that the payload was signed by Alice.
It can also execute business logic such as sending Bob a certain about of Ether or Tokens, as authorized by Alice. In other words, Alice's transaction can include, implicitly, her authorization to draw funds from another source (other than her wallet, which has no money), and compensate Bob for his trouble.
That is the basis for a business model to incentivize operators to stand up relays.
Hope it helps.
-
Thanks whether relay must be a contract? Or accoun1 can sign a transaction even account1 has no ether, then the signed message passed to account2, and account2 put this raw data in the data field of tx and send 9 ether? This data in account2 was signed by account1. In this case account2 will pay the gas for account1? As I heard, the private key that sign the transaction will pay the gas? Thanks– LouisCommented Mar 27, 2020 at 16:06
-
Bob forms a new transaction, with Alice's transaction attached as data. This means the whole signed raw data of Alice transaction? Any sample code for relay? It will developed in web3 or in solidity contract?– LouisCommented Mar 27, 2020 at 16:08
-
The relay is an off-chain service because Alice can't/doesn't want to pay for gas. Think API. Alice can sign a txn without sending it to Ethereum. She gets a signed payload that can be given to someone else who is willing to pay for gas. Commented Mar 27, 2020 at 17:57
-
1When the relay sends a transaction, it will be from the Relay, signed by the relay (normal), but it can contain
data:
that is, itself, another transaction signed by someone else. If the receiving contract can parse that, it can figure out who signed the payload regardless of who relayed it. A lot is possible when "if it can parse it" because if it can do that, it can do a LOT of things to support the notion of these meta-transactions. Commented Mar 27, 2020 at 17:59 -
For example if I want to transfer 30 usdt from account1 to account2, 1st I make tx ={ to: xx gaslimit: xx data: data1} here data1 is the hex data of functions.transfer(toAdd,30) then use sign to change this to a rawdata1, then make another tx2 like{ to: to2, data:rawdata1} , I think here whether to2 should be a different contract to get data from this rawdata1 to handle it? Any sample code ? Thanks– LouisCommented Mar 28, 2020 at 0:58