Skip to content
This repository was archived by the owner on Jun 11, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-fee-payer-token.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tempo.ts": patch
---

Fixed fee payer signing to preserve the configured Tempo fee token.
46 changes: 43 additions & 3 deletions src/server/Handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import { Hono } from 'hono'
import type { RpcRequest } from 'ox'
import * as Base64 from 'ox/Base64'
import * as Hex from 'ox/Hex'
import { sendTransactionSync } from 'viem/actions'
import { withFeePayer } from 'viem/tempo'
import { prepareTransactionRequest, sendTransactionSync, signTransaction } from 'viem/actions'
import { Transaction, withFeePayer } from 'viem/tempo'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test } from 'vitest'

import { accounts, getClient, http } from '../../test/server/config.js'
import { accounts, chain, getClient, http } from '../../test/server/config.js'
import { createServer, type Server } from '../../test/server/utils.js'
import * as Handler from './Handler.js'
import * as Kv from './Kv.js'
Expand Down Expand Up @@ -1046,6 +1046,46 @@ describe('feePayer', () => {
`)
})

test('behavior: eth_signRawTransaction uses configured fee token', async () => {
const feeToken = '0x20c0000000000000000000000000000000000001'
const chain_ = chain.extend({ feeToken })
const client = getClient({
account: userAccount,
chain: chain_,
})
const handler = Handler.feePayer({
account: feePayerAccount,
client: getClient({ chain: chain_ }),
})
const request = await prepareTransactionRequest(client, {
account: userAccount,
chain: chain_,
feePayer: true,
to: '0x0000000000000000000000000000000000000000',
})
const partial = await signTransaction(client, {
...request,
account: userAccount,
feePayer: true,
} as never)

const response = await handler.fetch(
new Request('http://localhost', {
body: JSON.stringify({
id: 1,
jsonrpc: '2.0',
method: 'eth_signRawTransaction',
params: [partial],
}),
method: 'POST',
}),
)
const data = (await response.json()) as { result: `0x76${string}` }
const transaction = Transaction.deserialize(data.result)

expect(transaction.feeToken).toBe(feeToken)
})

test('behavior: eth_sendRawTransaction', async () => {
const client = getClient({
account: userAccount,
Expand Down
4 changes: 4 additions & 0 deletions src/server/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,9 @@ export function feePayer(options: feePayer.Options) {
})
throw new Error('No client or chain provided')
})()
const feeToken = (
client as unknown as { chain?: (Chain & { feeToken?: `0x${string}` }) | undefined }
).chain?.feeToken

const router = from(options)

Expand Down Expand Up @@ -569,6 +572,7 @@ export function feePayer(options: feePayer.Options) {
const serializedTransaction = await signTransaction(client, {
...transaction,
account,
...(feeToken ? { feeToken } : {}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve explicit null fee token settings

When the fee payer client is configured with chain.extend({ feeToken: null }) to opt into protocol-selected fee tokens, this truthiness guard treats that explicit setting as absent. In that scenario, if the deserialized user transaction already contains a concrete feeToken, the earlier ...transaction spread keeps that token and the fee payer signs using it instead of preserving the configured null preference.

Useful? React with 👍 / 👎.

feePayer: account,
})

Expand Down
Loading