Skip to content

Setup

Setup the Tempo extension for Viem by following the steps below.

Install

To install the Tempo extension, you will need to install Viem and Tempo:

npm
npm i tempo.ts viem

Configure

Next, we will configure a Viem Client.

viem.config.ts
import { tempo } from 'tempo.ts/chains'
import { tempoActions } from 'tempo.ts/viem'
import { createClient, http, publicActions, walletActions } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
 
export const client = createClient({
  account: privateKeyToAccount('0x...'),
  chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
  transport: http(),
})
  .extend(publicActions)
  .extend(walletActions)
  .extend(tempoActions())

Use Viem Actions

Once we have configured our Viem client with Tempo, we can then use regular Viem actions (e.g. sendTransactionSync) that are decorated with Tempo properties like calls (batch transactions), feePayer (fee sponsorship), nonceKey (concurrent transactions) and more!

example.ts
import { client } from './viem.config'
 
const receipt = await client.sendTransactionSync({
  calls: [
    {
      data: '0xcafebabe00000000000000000000000000000001',
      to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef'
    },
    {
      data: '0xdeadbeef00000000000000000000000000000002',
      to: '0xfeedfacefeedfacefeedfacefeedfacefeedface'
    },
    {
      data: '0xfeedface00000000000000000000000000000003',
      to: '0xfeedfacefeedfacefeedfacefeedfacefeedface'
    },
  ],
  feePayer: '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
  nonceKey: 1337n,
})

Use Tempo Actions

You can also use Tempo-specific Actions:

example.ts
import { client } from './viem.config'
 
const alphaUsd = '0x20c0000000000000000000000000000000000001'
 
const metadata = await client.token.getMetadata({ 
  token: alphaUsd 
})
 
console.log(
  'Alpha USD Metadata:', 
  metadata.name,
  metadata.symbol,
  metadata.decimals,
  metadata.totalSupply
)
Alpha USD Metadata: Alpha USD, AlphaUSD, 6, 1000000000000000000000n

Next Steps

After you have set up Tempo with Viem, you can now: