-
Notifications
You must be signed in to change notification settings - Fork 39
docs: deprecate Handler.feePayer in favor of Handler.relay #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,149 +1,42 @@ | ||
| --- | ||
| title: Handler.feePayer | ||
| description: Server handler that sponsors transaction fees for users. | ||
| title: Handler.feePayer (Deprecated) | ||
| description: Deprecated — use Handler.relay with feePayer option instead. | ||
| --- | ||
|
|
||
| # `Handler.feePayer` | ||
| # `Handler.feePayer` (Deprecated) | ||
|
|
||
| Creates a server handler that acts as a fee payer for transactions, enabling you to subsidize gas costs for users by signing transactions with a dedicated fee payer account on your backend. | ||
|
|
||
| :::info | ||
| [See the guide](/guide/payments/sponsor-user-fees) | ||
| :::warning | ||
| `Handler.feePayer` has been deprecated. Use [`Handler.relay`](/accounts/server/handler.relay) with the [`feePayer`](/accounts/server/handler.relay#feepayer) option instead. | ||
| ::: | ||
|
|
||
| ## Usage | ||
|
|
||
| ```ts | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
| import { Handler } from 'accounts/server' | ||
|
|
||
| const handler = Handler.feePayer({ | ||
| account: privateKeyToAccount('0x...'), | ||
| }) | ||
| ``` | ||
|
|
||
| Then plug `handler` into your server framework of choice: | ||
|
|
||
| ```ts | ||
| createServer(handler.listener) // Node.js | ||
| Bun.serve(handler) // Bun | ||
| Deno.serve(handler) // Deno | ||
| app.all('*', c => handler.fetch(c.request)) // Elysia | ||
| app.use(handler.listener) // Express | ||
| app.use(c => handler.fetch(c.req.raw)) // Hono | ||
| export const GET = handler.fetch // Next.js | ||
| export const POST = handler.fetch // Next.js | ||
| ``` | ||
|
|
||
| ## Parameters | ||
|
|
||
| ### account | ||
|
|
||
| - **Type:** `LocalAccount` | ||
| - **Required** | ||
| ## Migration | ||
|
|
||
| The account to use as the fee payer. This account will sign all transactions and pay the gas fees. | ||
| Replace `Handler.feePayer` calls with `Handler.relay` and nest the `account` under `feePayer`: | ||
|
|
||
| ```ts twoslash | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
| import { Handler } from 'accounts/server' | ||
|
|
||
| const handler = Handler.feePayer({ | ||
| account: privateKeyToAccount('0x...'), // [!code focus] | ||
| }) | ||
| ```diff | ||
| - const handler = Handler.feePayer({ | ||
| - account: privateKeyToAccount('0x...'), | ||
| - }) | ||
| + const handler = Handler.relay({ | ||
| + feePayer: { | ||
| + account: privateKeyToAccount('0x...'), | ||
| + }, | ||
| + }) | ||
| ``` | ||
|
|
||
| ### chains | ||
|
|
||
| - **Type:** `readonly [Chain, ...Chain[]]` | ||
| - **Default:** `[tempo, tempoModerato]` | ||
|
|
||
| Supported chains. The handler resolves the client based on the `chainId` in the incoming transaction. | ||
|
|
||
| ```ts twoslash | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
| import { tempo } from 'viem/chains' | ||
| import { Handler } from 'accounts/server' | ||
|
|
||
| const handler = Handler.feePayer({ | ||
| account: privateKeyToAccount('0x...'), | ||
| chains: [tempo], // [!code focus] | ||
| }) | ||
| All other options (`chains`, `transports`, `path`, `onRequest`) remain the same — `validate` moves inside `feePayer`: | ||
|
|
||
| ```diff | ||
| - const handler = Handler.feePayer({ | ||
| - account: privateKeyToAccount('0x...'), | ||
| - validate: (request) => request.from !== blocked, | ||
| - }) | ||
| + const handler = Handler.relay({ | ||
| + feePayer: { | ||
| + account: privateKeyToAccount('0x...'), | ||
| + validate: (request) => request.from !== blocked, | ||
| + }, | ||
| + }) | ||
| ``` | ||
|
|
||
| ### onRequest | ||
|
|
||
| - **Type:** `(request: RpcRequest) => Promise<void>` | ||
| - **Optional** | ||
|
|
||
| Callback called before processing each request. Useful for logging, rate limiting, or custom validation. | ||
|
|
||
| ```ts twoslash | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
| import { Handler } from 'accounts/server' | ||
|
|
||
| const handler = Handler.feePayer({ | ||
| account: privateKeyToAccount('0x...'), | ||
| onRequest: async (request) => { // [!code focus] | ||
| console.log('Processing request:', request.method) // [!code focus] | ||
| }, // [!code focus] | ||
| }) | ||
| ``` | ||
|
|
||
| ### path | ||
|
|
||
| - **Type:** `string` | ||
| - **Default:** `'/'` | ||
|
|
||
| Path where the handler listens for requests. | ||
|
|
||
| ```ts twoslash | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
| import { Handler } from 'accounts/server' | ||
|
|
||
| const handler = Handler.feePayer({ | ||
| account: privateKeyToAccount('0x...'), | ||
| path: '/fee-payer', // [!code focus] | ||
| }) | ||
| ``` | ||
|
|
||
| ### transports | ||
|
|
||
| - **Type:** `Record<number, Transport>` | ||
| - **Default:** `http()` for each chain | ||
|
|
||
| Transports keyed by chain ID. | ||
|
|
||
| ```ts twoslash | ||
| import { http } from 'viem' | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
| import { tempo } from 'viem/chains' | ||
| import { Handler } from 'accounts/server' | ||
|
|
||
| const handler = Handler.feePayer({ | ||
| account: privateKeyToAccount('0x...'), | ||
| transports: { // [!code focus] | ||
| [tempo.id]: http('https://rpc.tempo.xyz'), // [!code focus] | ||
| }, // [!code focus] | ||
| }) | ||
| ``` | ||
|
|
||
|
|
||
| ### validate | ||
|
|
||
| - **Type:** `(request: TransactionRequest) => boolean | Promise<boolean>` | ||
| - **Optional** | ||
|
|
||
| Validates whether to sponsor a transaction. When omitted, all transactions are sponsored. Return `false` to reject sponsorship — the handler will re-fill without `feePayer` so gas/nonce are correct for self-payment. | ||
|
|
||
| ```ts twoslash | ||
| import { privateKeyToAccount } from 'viem/accounts' | ||
| import { Handler } from 'accounts/server' | ||
|
|
||
| const blocked = '0x...' | ||
|
|
||
| const handler = Handler.feePayer({ | ||
| account: privateKeyToAccount('0x...'), | ||
| validate: (request) => request.from !== blocked, // [!code focus] | ||
| }) | ||
| ``` | ||
| See [`Handler.relay`](/accounts/server/handler.relay) for the full API reference. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think we might need to update this service to the new Relay now. It's in https://github.com/tempoxyz/tempo-apps/tree/main/apps/fee-payer