Yashotantra Academy logo
← Node.js theorytheory 0/50 · 0%
level 1
Curious · 0 XP
streak
0d
perfect
0
badges
0

100 XP to Apprentice

Web3 integration · hard

49. Building a relayer/signer service

A backend that submits transactions on behalf of users.

1 min read3 questionsup to 50 XPtopic 49/50

Read in another language

AI translates the explanation and quiz text while preserving code and answer scoring.

A relayer service holds a hot wallet's key (ideally in a secrets manager, not plain env vars) and submits transactions on behalf of users — common for gasless UX, batching, or automated on-chain actions. It must track nonces itself, since sending multiple transactions in quick succession from the same address risks nonce collisions if you just query "next nonce" from the node each time.

js
class NonceManager {
  constructor(startNonce) { this.nonce = startNonce; }
  next() { return this.nonce++; } // reserve synchronously before any await
}

async function relayTransaction(nonceManager, buildAndSignTx, sendRawTx) {
  const nonce = nonceManager.next();
  const signedTx = await buildAndSignTx(nonce);
  return sendRawTx(signedTx);
}

Production relayers also need retry/replacement logic for stuck transactions (bumping gas price and resubmitting with the same nonce), and careful handling of failures so a rejected transaction doesn't permanently "burn" a nonce and stall every later transaction.

How to study this topic

  1. 1. Read the explanation once end to end, skipping the code.
  2. 2. Re-read the code snippets and say out loud what each line does.
  3. 3. Answer the quiz without scrolling back — that is the real check.
  4. 4. Read every explanation, even for the answers you got right.

Scoring

  • · Up to 30 XP from quiz accuracy.
  • · +15 XP for a perfect first attempt.
  • · +5 XP while a 3-day streak is running.
  • · 75% or higher marks the topic complete.

Check your understanding

  1. 1. Why can't a relayer safely just query 'next nonce' from the node before every send?

  2. 2. What happens if a transaction with a given nonce gets stuck or rejected without being replaced?

  3. 3. Where should a relayer's private key ideally be stored?

Badges

First light
Pass your first topic
Sharp shooter
3 perfect first-try quizzes
On a roll
Study 3 days in a row
Week warrior
Study 7 days in a row
Grinder
Earn 500 XP
Deep diver
Earn 1500 XP