Skip to content
LogoLogo

Use Your Stablecoin for Fees

Enable users to pay transaction fees using your stablecoin. Tempo supports flexible fee payment options, allowing users to pay fees in any stablecoin they hold.

Demo

Use Your Stablecoin for Fees

demo
1
Create an account, or use an existing one.
2
Add testnet funds to your account.
3
Create & deploy a token to testnet.
4
Grant issuer role on token.
5
Mint 100 tokens to yourself.
6
Add fee liquidity for your token.
7
Send 100 AlphaUSD and pay fees in your token.
pnpx gitpick tempoxyz/tempo-ts/tree/main/examples/issuance

Steps

Create your stablecoin

First, create and mint your stablecoin by following the Create a Stablecoin guide.

Add fee pool liquidity

Before users can pay fees with your token, you need to provide liquidity in the Fee AMM between your token and each of the tokens accepted by validators.

To determine which validator tokens are needed, sample recent blocks and check the miner's preferred fee token using getValidatorToken on the FeeManager contract. For example, on Moderato testnet, validators accept fees in pathUSD and AlphaUSD. On mainnet, this token mix is different and subject to change.

Add liquidity to your token's fee pool for each validator token:

import {  } from 'wagmi/tempo'
import {  } from 'viem'
import {  } from 'wagmi'
 
const {  } = ()
const  = '0x...' // Your issued token address
const  = '0x20c0000000000000000000000000000000000001' // AlphaUSD on testnet
 
const  = ..() 
 
// Add 100 AlphaUSD of liquidity to the fee pool
.({ 
  : ,
  : ,
  : ,
  : ,
  : ('100', 6),
}) 

You can also check your token's fee pool liquidity at any time:

import {  } from 'wagmi/tempo'
 
const { :  } = ..({
  : yourToken,
  : '0x20c0000000000000000000000000000000000001', // AlphaUSD on testnet
})
 
const  =  && . > 0n

If the pool has no liquidity (reserveValidatorToken == 0), you'll need to add liquidity to the fee pool before users can pay fees with your token. See the Create a Stablecoin guide for instructions on minting fee AMM liquidity.

Send payment with your token as fee

Your users can send payments using your issued stablecoin as the fee token:

import React from 'react'
import {  } from 'wagmi/tempo'
import {  } from 'wagmi'
import { , , ,  } from 'viem'
 
export function () {
  const {  } = ()
  const [, ] = React.<string>('')
  const [, ] = React.<string>('')
 
  const  = '0x...' // Your issued token address
  const  = '0x20c0000000000000000000000000000000000001' // AlphaUSD
 
  const { : , :  } =
    ..({ 
      : , 
      : , 
    }) 
 
  const { : , :  } =
    ..({ 
      : , 
      : , 
    }) 
 
  const  = ..({ 
    : { 
      () { 
        () 
        () 
      }, 
    }, 
  }) 
 
  const  =  && ()
 
  const  = () => { 
    if (!) return
    .({ 
      : ('100', 6), 
      :  as `0x${string}`, 
      : , 
      :  ? ((), { : 32 }) : , 
      , // Pay fees with your issued token
    }) 
  } 
 
  return (
    <>
      <>
        <>Recipient address</>
        <
          ="text"
          ={}
          ={() => (..)}
          ="0x..."
        />
      </>
      <>
        <>Memo (optional)</>
        <
          ="text"
          ={}
          ={() => (..)}
          ="INV-12345"
        />
      </>
      <
        ={! || ! || .}
        ={}
        ="button"
      > 
      {. ? 'Sending...' : 'Send'}
      </> 
    </>
  )
}

Users can set your stablecoin as their default fee token at the account level, or specify it for individual transactions. Learn more about how users pay fees in different stablecoins.

How It Works

When users pay transaction fees with your stablecoin, Tempo's fee system automatically handles the conversion if validators prefer a different token. The Fee AMM ensures seamless fee payments across all supported stablecoins.

Users can select your stablecoin as their fee token through:

  • Account-level preference: Set as default for all transactions
  • Transaction-level preference: Specify for individual transactions
  • Automatic selection: When directly interacting with your token contract

Learn more about how users pay fees in different stablecoins and the complete fee token preference hierarchy.

Benefits

  • User convenience: Users can pay fees with the same token they're using
  • Liquidity: Encourages users to hold your stablecoin
  • Flexibility: Works seamlessly with Tempo's fee system

Best Practices

Monitor pool liquidity

Regularly check your token's fee pool reserves to ensure users can consistently pay fees with your stablecoin. Low liquidity can prevent transactions from being processed.

Maintain adequate reserves

Keep sufficient validator token reserves in your fee pool to handle expected transaction volume. Consider your user base size and typical transaction frequency when determining reserve levels.

As fees accrue in your token, the pool will run low on validator tokens and need to be rebalanced. Use rebalanceSwap to replenish validator token reserves when they become depleted.

Test before launch

Before promoting fee payments with your token, thoroughly test the flow on testnet:

  1. Add liquidity to the fee pool
  2. Verify users can set your token as their fee preference
  3. Execute test transactions with various gas costs
  4. Monitor that fee conversions work correctly

Next Steps