Skip to content
LogoLogo

withFeePayer

Creates a transport that routes transactions to a fee payer service when a feePayer is requested on an action.

Usage

import { ,  } from 'viem'
import {  } from 'viem/accounts'
import {  } from 'viem/chains'
import {  } from 'viem/tempo'
 
const  = ({
  : ('0x...'),
  : ,
  : (
    (),                               // โ† Default Transport
    ('https://sponsor.example.com'),  // โ† Fee Payer Transport
  ), 
})
 
// Regular transaction
const  = await .sendTransactionSync({
  : '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
})
 
// Sponsored transaction
const  = await .sendTransactionSync({ 
  : true, 
  : '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb', 
}) 

Example Fee Payer Service

Below is an end-to-end example of a client/server fee payer setup.

See server.ts for the server-side implementation. It uses Handler.feePayer provided by tempo.ts/server to handle fee payer requests.

import { ,  } from 'viem'
import {  } from 'viem/accounts'
import {  } from 'viem/chains'
import {  } from 'viem/tempo'
 
const  = ({
  : ('0x...'),
  : ,
  : (
    (), 
    ('http://localhost:3000'), 
  ), 
})
 
const  = await .sendTransactionSync({
  : true,
  : '0x0000000000000000000000000000000000000000',
})

Return Type

type ReturnType = Transport<'feePayer'>

Parameters

defaultTransport

  • Type: Transport

The default transport to use for regular (non-sponsored) transactions.

relayTransport

  • Type: Transport

The relay transport to use for sponsored transactions. This should point to a fee payer service that will sign and submit the transaction with a fee payer signature.

Parameters (optional)

  • Type: withFeePayer.Parameters

Options for withFeePayer usage.

policy (optional)

  • Type: 'sign-only' | 'sign-and-broadcast'
  • Default: 'sign-only'

Controls how the fee payer handles sponsored transactions:

  • 'sign-only': Fee payer co-signs the transaction and returns it to the client transport, which then broadcasts it via the default transport.

  • 'sign-and-broadcast': Fee payer co-signs and broadcasts the transaction directly. The fee payer service handles both signing and submission to the blockchain.