In order to be able to relay transaction we need a centralized back-end able to relay the transactions on behalf of users.
Example of relaying a transaction
Reading a player structure (simple GET API endpoit)
The role of the back-end in a wallet-less dApp
In the previous section (Build a gas-less transaction), we learned how to use Moonbeam's callPermit in order to relay a transaction and make it gassless. In order to go one step further and removing the need to sign a transaction, the transaction is going to be generated by the mirror wallet and dispatched by the contract's owner (or any authorized address defined in a particular modifier).
The backend is going to generate the data to sign and execute it on behalf of the user, following for instance a web2 POST call.
Example of a simple Express POST function
app.post('/doTx',async (req, res) => {let infos =awaitreq.bodylet sendTxn =awaitprepareCall(infos)if (await sendTxn ==true) {awaitres.status(200).json({ 'ok':true,'message':'Tx successfully sent!' }) }else {awaitres.status(200).json({ 'ok':false,'message':'There was a problem during the tx' }) }})
Example of a function that encodes, sign, relay/executes a transaction