### Install Viem for Tempo
Source: https://viem.sh/tempo/index
Installs the Viem package, which is a prerequisite for using the Tempo extension. No specific dependencies are required beyond Node.js and npm.
```bash
npm i viem
```
--------------------------------
### Example Fee Payer Service Setup
Source: https://viem.sh/tempo/transports/withFeePayer
Illustrates a client-side setup for an example fee payer service, demonstrating how the `withFeePayer` transport interacts with a local fee payer server.
```APIDOC
## POST /
### Description
Client-side setup for an example fee payer service using `withFeePayer`.
### Method
POST
### Endpoint
/
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```typescript
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { tempoTestnet } from 'viem/chains'
import { withFeePayer } from 'viem/tempo'
const client = createWalletClient({
account: privateKeyToAccount('0x...'),
chain: tempoTestnet,
transport: withFeePayer(
http(),
http('http://localhost:3000'),
),
})
const hash = await client.sendTransactionSync({
feePayer: true,
to: '0x0000000000000000000000000000000000000000',
})
```
### Response
#### Success Response (200)
- **hash** (string) - The transaction hash.
#### Response Example
```json
{
"hash": "0x..."
}
```
```
--------------------------------
### Example Fee Payer Client Setup (TypeScript)
Source: https://viem.sh/tempo/transports/withFeePayer
Illustrates a client-side setup for a fee payer service using `withFeePayer`. This example configures the `WalletClient` to send sponsored transactions to a local fee payer service running on `http://localhost:3000`. It depends on `viem` and `viem/tempo`.
```typescript
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { tempoTestnet } from 'viem/chains'
import { withFeePayer } from 'viem/tempo'
const client = createWalletClient({
account: privateKeyToAccount('0x...'),
chain: tempoTestnet,
transport: withFeePayer(
http(),
http('http://localhost:3000'),
),
})
const hash = await client.sendTransactionSync({
feePayer: true,
to: '0x0000000000000000000000000000000000000000',
})
```
--------------------------------
### Configure Viem Client with Tempo
Source: https://viem.sh/tempo/index
Sets up a Viem client extended with Tempo actions. This involves importing necessary functions and chain configurations from Viem and Tempo. The client is configured with an account, the Tempo testnet chain, and extended with `publicActions`, `walletActions`, and `tempoActions`.
```typescript
import { createClient, http, publicActions, walletActions } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { tempoTestnet } from 'viem/chains'
import { tempoActions } from 'viem/tempo'
export const client = createClient({
account: privateKeyToAccount('0x...'),
chain: tempoTestnet,
transport: http(),
})
.extend(publicActions)
.extend(walletActions)
.extend(tempoActions())
```
--------------------------------
### Configure Viem Client with Tempo Fee Token
Source: https://viem.sh/tempo/index
Demonstrates how to configure a Viem client with a specific fee token for the Tempo chain. This is achieved by extending the `tempoTestnet` chain with a `feeToken` property, allowing for custom fee token configurations.
```typescript
export const client = createClient({
chain: tempoTestnet.extend({
feeToken: '0x20c0000000000000000000000000000000000001',
}),
// ...
})
```
--------------------------------
### Use Tempo-Specific Actions for Token Metadata
Source: https://viem.sh/tempo/index
Demonstrates the usage of Tempo-specific actions, specifically `client.token.getMetadata`, to retrieve metadata for a given token on the Tempo network. This includes fetching the token's name, symbol, decimals, and total supply.
```typescript
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
)
```
--------------------------------
### Use Viem Actions with Tempo Properties
Source: https://viem.sh/tempo/index
Shows how to use regular Viem actions, such as `sendTransactionSync`, with Tempo-specific properties like `calls` for batch transactions, `feePayer` for fee sponsorship, and `nonceKey` for concurrent transactions. This leverages the extended client configured with Tempo actions.
```typescript
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,
})
```
--------------------------------
### Create viem Transport with Fee Payer Routing (TypeScript)
Source: https://viem.sh/tempo/transports/withFeePayer
Demonstrates how to configure a viem `WalletClient` to use the `withFeePayer` transport. This setup directs regular transactions to a default transport and sponsored transactions to a fee payer service. It requires `viem` and `viem/tempo`.
```typescript
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { tempoTestnet } from 'viem/chains'
import { withFeePayer } from 'viem/tempo'
const client = createWalletClient({
account: privateKeyToAccount('0x...'),
chain: tempoTestnet,
transport: withFeePayer(
http(), // ← Default Transport
http('https://sponsor.example.com'), // ← Fee Payer Transport
),
})
// Regular transaction
const receipt1 = await client.sendTransactionSync({
to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
})
// Sponsored transaction
const receipt2 = await client.sendTransactionSync({
feePayer: true,
to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
})
```
--------------------------------
### Watch Whitelist Updates with viem
Source: https://viem.sh/tempo/actions/policy
This viem example demonstrates how to use `client.policy.watchWhitelistUpdated` to listen for whitelist update events. It logs the account, allowed status, policy ID, and updater address when an event occurs. A function is returned to stop watching the events later.
```typescript
import { client } from './viem.config'
const unwatch = client.policy.watchWhitelistUpdated({
onWhitelistUpdated: (args, log) => {
console.log('Account:', args.account)
console.log('Allowed:', args.allowed)
console.log('Policy ID:', args.policyId)
console.log('Updater:', args.updater)
},
})
// Later, stop watching
unwatch()
```
--------------------------------
### Watch Rebalance Swap Events with viem
Source: https://viem.sh/tempo/actions/amm
This example demonstrates how to use `client.amm.watchRebalanceSwap` to listen for rebalance swap events. It logs details of the swap, such as amounts and addresses. The function returns an `unwatch` function to stop listening.
```typescript
import { client } from './viem.config'
const unwatch = client.amm.watchRebalanceSwap({
onRebalanceSwap: (args, log) => {
console.log('Amount in:', args.amountIn)
console.log('Amount out:', args.amountOut)
console.log('Swapper:', args.swapper)
console.log('User token:', args.userToken)
console.log('Validator token:', args.validatorToken)
},
})
// Later, stop watching
unwatch()
```
--------------------------------
### Reward Actions API
Source: https://viem.sh/tempo/actions
Manages reward distribution, allowing users to claim rewards, set recipients, and start new reward streams.
```APIDOC
## Reward Actions
### `reward.claim`
**Description:** Claims accumulated rewards for the caller.
### `reward.getTotalPerSecond`
**Description:** Gets the total reward per second rate for all active streams.
### `reward.getUserRewardInfo`
**Description:** Gets reward information for a specific account.
### `reward.setRecipient`
**Description:** Sets or changes the reward recipient for a token holder.
### `reward.start`
**Description:** Starts a new reward stream that distributes tokens to opted-in holders.
### `reward.watchRewardRecipientSet`
**Description:** Watches for reward recipient set events.
### `reward.watchRewardScheduled`
**Description:** Watches for reward scheduled events.
```
--------------------------------
### Instantiate Account from WebCrypto P256 Key Pair
Source: https://viem.sh/tempo/accounts/account
Creates an Account instance from a WebCrypto P256 key pair. This is the primary way to use a P256 key with viem. It requires the `viem/tempo` and `ox` libraries.
```typescript
import { Account } from 'viem/tempo'
import { WebCryptoP256 } from 'ox'
const keyPair = await WebCryptoP256.createKeyPair()
const account = Account.fromWebCryptoP256(keyPair)
console.log('Address:', account.address)
```
--------------------------------
### withFeePayer Usage
Source: https://viem.sh/tempo/transports/withFeePayer
Demonstrates how to create a wallet client with the `withFeePayer` transport, allowing for both regular and sponsored transactions.
```APIDOC
## POST /
### Description
Creates a transport that routes transactions to a fee payer service when a `feePayer` is requested on an action.
### Method
POST
### Endpoint
/
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```typescript
import { createWalletClient, http } from 'viem'
import { privateKeyToAccount } from 'viem/accounts'
import { tempoTestnet } from 'viem/chains'
import { withFeePayer } from 'viem/tempo'
const client = createWalletClient({
account: privateKeyToAccount('0x...'),
chain: tempoTestnet,
transport: withFeePayer(
http(), // ← Default Transport
http('https://sponsor.example.com'), // ← Fee Payer Transport
),
})
// Regular transaction
const receipt1 = await client.sendTransactionSync({
to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
})
// Sponsored transaction
const receipt2 = await client.sendTransactionSync({
feePayer: true,
to: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
})
```
### Response
#### Success Response (200)
- **receipt** (object) - Transaction receipt.
#### Response Example
```json
{
"hash": "0x..."
}
```
```
--------------------------------
### Import Tempo Chains (JavaScript)
Source: https://viem.sh/tempo/chains
Imports available Tempo network configurations (devnet, localnet, testnet) from the 'viem/chains' library. These are essential for interacting with Tempo networks using Viem.
```javascript
import {
tempoDevnet,
tempoLocalnet,
tempoTestnet,
} from 'viem/chains'
```
--------------------------------
### Account.fromWebCryptoP256
Source: https://viem.sh/tempo/accounts/account
Instantiates an Account from a WebCrypto P256 key pair.
```APIDOC
## POST /accounts/fromWebCryptoP256
### Description
Instantiates an Account from a WebCrypto P256 key pair.
### Method
POST
### Endpoint
/accounts/fromWebCryptoP256
### Parameters
#### Request Body
- **keyPair** (object) - Required - The WebCrypto P256 key pair from `WebCryptoP256.createKeyPair()`. It should contain `publicKey` and `privateKey`.
- **options** (object) - Optional - Options for the account.
- **options.access** (Address | Account) - Optional - Parent account to access.
### Request Example
```json
{
"keyPair": {
"publicKey": "0x...",
"privateKey": "CryptoKey..."
},
"options": {
"access": "0x..."
}
}
```
### Response
#### Success Response (200)
- **account** (Account) - The created Account object.
#### Response Example
```json
{
"account": {
"address": "0x...",
"keyType": "P256",
"publicKey": "0x...",
"source": "webcrypto",
"type": "local",
"assignKeyAuthorization": "function",
"sign": "function",
"signAuthorization": "function",
"signKeyAuthorization": "function",
"signMessage": "function",
"signTransaction": "function",
"signTypedData": "function"
}
}
```
```
--------------------------------
### Token Actions API
Source: https://viem.sh/tempo/actions
Encompasses all actions related to TIP-20 tokens, including creation, minting, burning, transfers, approvals, and role management.
```APIDOC
## Token Actions
### `token.approve`
**Description:** Approves a spender to transfer TIP-20 tokens on behalf of the caller.
### `token.burn`
**Description:** Burns TIP-20 tokens from the caller's balance.
### `token.burnBlocked`
**Description:** Burns TIP-20 tokens from a blocked address.
### `token.changeTransferPolicy`
**Description:** Changes the transfer policy for a TIP-20 token.
### `token.create`
**Description:** Creates a new TIP-20 token and assigns the admin role to the calling account.
### `token.getAllowance`
**Description:** Gets the amount of tokens that a spender is approved to transfer on behalf of an owner.
### `token.getBalance`
**Description:** Gets the token balance of an address.
### `token.getMetadata`
**Description:** Gets the metadata for a TIP-20 token, including name, symbol, decimals, currency, and total supply.
### `token.grantRoles`
**Description:** Grants one or more roles to an address.
### `token.mint`
**Description:** Mints new TIP-20 tokens to a recipient.
### `token.pause`
**Description:** Pauses a TIP-20 token, preventing all transfers.
### `token.renounceRoles`
**Description:** Renounces one or more roles from the caller's address.
### `token.revokeRoles`
**Description:** Revokes one or more roles from an address.
### `token.setRoleAdmin`
**Description:** Sets the admin role for another role.
### `token.setSupplyCap`
**Description:** Sets the supply cap for a TIP-20 token.
### `token.transfer`
**Description:** Transfers TIP-20 tokens from the caller to a recipient.
```
--------------------------------
### Create Access Key with WebCrypto P256
Source: https://viem.sh/tempo/accounts/account
Generates an access key account from a WebCrypto P256 key pair, linked to a parent account. This allows the access key to perform actions on behalf of the parent account, with optional expiry and limits.
```typescript
import { Account, WebCryptoP256 } from 'viem/tempo'
import { client } from './viem.config'
// Create root account
const account = Account.fromSecp256k1(
'0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80'
)
// Create access key
const keyPair = await WebCryptoP256.createKeyPair()
const accessKey = Account.fromWebCryptoP256(keyPair, { access: account })
// Sign a key authorization
const keyAuthorization = await account.signKeyAuthorization(accessKey, {
expiry: Math.floor(Date.now() / 1000) + 86400, // 24 hour expiry
})
// Attach to next transaction
const receipt = await client.sendTransactionSync({
account: accessKey,
keyAuthorization,
to: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
})
// Now any subsequent transaction can be used with `accessKey`
// WITHOUT the `keyAuthorization` parameter!
```
--------------------------------
### Faucet Actions API
Source: https://viem.sh/tempo/actions
Provides functionality to fund accounts with testnet tokens using the faucet.
```APIDOC
## Faucet Actions
### `faucet.fund`
**Description:** Funds an account with testnet tokens.
```
--------------------------------
### POST /faucet/fundSync
Source: https://viem.sh/tempo/actions/faucet
Funds an account with an initial amount of tokens on Tempo's testnet and waits for the transactions to be included in a block before returning.
```APIDOC
## POST /faucet/fundSync
### Description
Funds an account with an initial amount of tokens on Tempo's testnet and waits for the transactions to be confirmed. Returns an array of transaction receipts.
### Method
POST
### Endpoint
/faucet/fundSync
### Parameters
#### Request Body
- **account** (Account | Address) - Required - The account to fund with testnet tokens.
- **timeout** (number) - Optional - Timeout in milliseconds to wait for transaction confirmation. Defaults to 10000.
### Request Example
```json
{
"account": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef",
"timeout": 5000
}
```
### Response
#### Success Response (200)
- **receipts** (readonly TransactionReceipt[]) - An array of transaction receipts after the transactions are confirmed.
#### Response Example
```json
{
"receipts": [
{ "blockNumber": 123n, "..." },
{ "blockNumber": 123n, "..." }
]
}
```
```
--------------------------------
### Fund Account with Testnet Tokens (TypeScript)
Source: https://viem.sh/tempo/actions/faucet
Funds a specified account with an initial amount of tokens on Tempo's testnet using the 'faucet.fund' method. This method returns transaction hashes asynchronously. Requires a pre-configured viem client.
```typescript
import { client } from './viem.config'
const hashes = await client.faucet.fund({
account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
})
console.log('Transaction hashes:', hashes)
```
--------------------------------
### withFeePayer Parameters
Source: https://viem.sh/tempo/transports/withFeePayer
Details the parameters accepted by the `withFeePayer` function, including the default transport, relay transport, and optional policy settings.
```APIDOC
## withFeePayer Parameters
### Parameters
#### defaultTransport
- **Type:** `Transport`
- **Description:** The default transport to use for regular (non-sponsored) transactions.
#### relayTransport
- **Type:** `Transport`
- **Description:** 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`
- **Description:** Options for `withFeePayer` usage.
##### `policy` (optional)
- **Type:** `'sign-only' | 'sign-and-broadcast'`
- **Default:** `'sign-only'`
- **Description:** 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.
```
--------------------------------
### Asynchronous Token Withdrawal with viem.js
Source: https://viem.sh/tempo/actions/dex
Withdraws tokens asynchronously from the Stablecoin DEX, returning the transaction hash immediately. Users must manually wait for the transaction to be included using `client.waitForTransactionReceipt`. This is suitable for performance optimization. Requires the 'viem' library and a pre-configured client.
```typescript
import { parseUnits } from 'viem'
import { client } from './viem.config'
const hash = await client.dex.withdraw({
amount: parseUnits('100', 6),
token: '0x20c0000000000000000000000000000000000001',
})
const receipt = await client.waitForTransactionReceipt({ hash })
```
--------------------------------
### POST /faucet/fund
Source: https://viem.sh/tempo/actions/faucet
Funds an account with an initial amount of tokens on Tempo's testnet. This method returns transaction hashes immediately after submission.
```APIDOC
## POST /faucet/fund
### Description
Funds an account with an initial amount of tokens on Tempo's testnet. Returns an array of transaction hashes.
### Method
POST
### Endpoint
/faucet/fund
### Parameters
#### Request Body
- **account** (Account | Address) - Required - The account to fund with testnet tokens.
### Request Example
```json
{
"account": "0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef"
}
```
### Response
#### Success Response (200)
- **hashes** (readonly Hash[]) - An array of transaction hashes for the funding transactions.
#### Response Example
```json
{
"hashes": ["0x...", "0x..."]
}
```
```
--------------------------------
### AMM Actions API
Source: https://viem.sh/tempo/actions
This section details the available actions for interacting with the Automated Market Maker (AMM), including managing liquidity, retrieving pool information, and handling swaps.
```APIDOC
## AMM Actions
### `amm.burn`
**Description:** Burns liquidity tokens and receives the underlying token pair.
### `amm.getLiquidityBalance`
**Description:** Gets the liquidity balance for an address in a specific pool.
### `amm.getPool`
**Description:** Gets the reserves for a liquidity pool.
### `amm.mint`
**Description:** Mints liquidity tokens by providing a token pair.
### `amm.rebalanceSwap`
**Description:** Performs a rebalance swap between user and validator tokens.
### `amm.watchBurn`
**Description:** Watches for liquidity burn events.
### `amm.watchFeeSwap`
**Description:** Watches for fee swap events.
### `amm.watchMint`
**Description:** Watches for liquidity mint events.
### `amm.watchRebalanceSwap`
**Description:** Watches for rebalance swap events.
```
--------------------------------
### Stablecoin DEX Actions API
Source: https://viem.sh/tempo/actions
Provides functionalities for interacting with the Stablecoin Decentralized Exchange (DEX), including trading, order management, and balance inquiries.
```APIDOC
## Stablecoin DEX Actions
### `dex.buy`
**Description:** Buys a specific amount of tokens from the Stablecoin DEX orderbook.
### `dex.cancel`
**Description:** Cancels an order from the orderbook.
### `dex.createPair`
**Description:** Creates a new trading pair on the DEX.
### `dex.getBalance`
**Description:** Gets a user's token balance on the Stablecoin DEX.
### `dex.getBuyQuote`
**Description:** Gets the quote for buying a specific amount of tokens.
### `dex.getOrder`
**Description:** Gets an order's details from the orderbook.
### `dex.getTickLevel`
**Description:** Gets the price level information at a specific tick.
### `dex.getSellQuote`
**Description:** Gets the quote for selling a specific amount of tokens.
### `dex.place`
**Description:** Places a limit order on the orderbook.
### `dex.placeFlip`
**Description:** Places a flip order that automatically flips when filled.
### `dex.sell`
**Description:** Sells a specific amount of tokens from the Stablecoin DEX orderbook.
### `dex.watchFlipOrderPlaced`
**Description:** Watches for flip order placed events.
### `dex.watchOrderCancelled`
**Description:** Watches for order cancelled events.
### `dex.watchOrderFilled`
**Description:** Watches for order filled events.
### `dex.watchOrderPlaced`
**Description:** Watches for order placed events.
### `dex.withdraw`
**Description:** Withdraws tokens from the DEX to the caller's wallet.
```
--------------------------------
### Synchronous Token Withdrawal with viem.js
Source: https://viem.sh/tempo/actions/dex
Withdraws tokens synchronously from the Stablecoin DEX to the connected wallet. This method waits for the transaction to be included before returning the receipt. It requires the 'viem' library and a pre-configured client.
```typescript
import { parseUnits } from 'viem'
import { client } from './viem.config'
const { receipt } = await client.dex.withdrawSync({
amount: parseUnits('100', 6),
token: '0x20c0000000000000000000000000000000000001',
})
console.log('Transaction hash:', receipt.transactionHash)
```
--------------------------------
### Watch Reward Recipient Set Events with viem
Source: https://viem.sh/tempo/actions/reward
This snippet demonstrates how to use `reward.watchRewardRecipientSet` to monitor changes in reward recipients. It requires importing the client and token, and provides a callback function to handle the event data. The function returns an unwatch callback to stop the event listener.
```typescript
import { client, token } from './viem.config'
const unwatch = client.reward.watchRewardRecipientSet({
onRewardRecipientSet: (args, log) => {
console.log('Holder:', args.holder)
console.log('Recipient:', args.recipient)
},
token,
})
// Later, stop watching
unwatch()
```
--------------------------------
### Set Default Fee Token for Tempo Chain (JavaScript)
Source: https://viem.sh/tempo/chains
Demonstrates how to extend a Tempo chain (e.g., tempoTestnet) to set a default fee token. This configuration ensures all transactions on this chain will use the specified token as the fee token unless overridden at the transaction level.
```javascript
import { tempoTestnet } from 'viem/chains'
const chain = tempoTestnet.extend({
feeToken: '0x20c0000000000000000000000000000000000001',
})
```
--------------------------------
### Fund Account and Wait for Confirmation (TypeScript)
Source: https://viem.sh/tempo/actions/faucet
Funds a specified account with testnet tokens and waits for the transactions to be included in a block before returning using 'faucet.fundSync'. This method returns transaction receipts upon confirmation. An optional timeout parameter can be provided.
```typescript
import { client } from './viem.config'
const receipts = await client.faucet.fundSync({
account: '0xdeadbeefdeadbeefdeadbeefdeadbeefdeadbeef',
})
console.log('Receipts:', receipts)
```
--------------------------------
### Optional Filters for Nonce Increment Events
Source: https://viem.sh/tempo/actions/nonce
Describes the optional `args` object that can be passed to `watchNonceIncremented` to filter events by specific account addresses or nonce keys. This allows for more targeted monitoring.
```typescript
type Args = {
/** Address of the account to filter by */
account?: Address | Address[] | null
/** Nonce key to filter by */
nonceKey?: bigint | bigint[] | null
}
```
--------------------------------
### Optional Arguments for watchRewardRecipientSet
Source: https://viem.sh/tempo/actions/reward
Allows for optional filtering of reward recipient set events by specifying the holder or recipient addresses. This helps in narrowing down the events being monitored.
```typescript
type Args = {
/** Filter events by holder address */
holder?: Address
/** Filter events by recipient address */
recipient?: Address
}
```
--------------------------------
### Watch User Token Set Events with Viem (TypeScript)
Source: https://viem.sh/tempo/actions/fee
Sets up a listener for user token set events emitted by the Fee Manager. It takes an `onUserTokenSet` callback and optional filters, and returns an `unwatch` function to stop listening. This function is useful for reacting to changes in user fee token assignments.
```typescript
import { client } from './viem.config'
const unwatch = client.fee.watchSetUserToken({
onUserTokenSet: (args, log) => {
console.log('User:', args.user)
console.log('New fee token:', args.token)
},
})
// Later, stop watching
unwatch()
```
--------------------------------
### Fee Actions API
Source: https://viem.sh/tempo/actions
Manages user preferences for fee tokens, allowing users to set and retrieve their default fee token.
```APIDOC
## Fee Actions
### `fee.getUserToken`
**Description:** Gets the user's default fee token preference.
### `fee.setUserToken`
**Description:** Sets the user's default fee token preference.
### `fee.watchSetUserToken`
**Description:** Watches for user token set events.
```
--------------------------------
### Nonce Actions API
Source: https://viem.sh/tempo/actions
Handles nonce management for accounts, including retrieving nonce values and monitoring nonce key activity.
```APIDOC
## Nonce Actions
### `nonce.getNonce`
**Description:** Gets the nonce for an account and nonce key.
### `nonce.getNonceKeyCount`
**Description:** Gets the number of active nonce keys for an account.
### `nonce.watchActiveKeyCountChanged`
**Description:** Watches for active key count changed events.
### `nonce.watchNonceIncremented`
**Description:** Watches for nonce incremented events.
```
--------------------------------
### Watch Nonce Incremented Events with viem
Source: https://viem.sh/tempo/actions/nonce
This code snippet demonstrates how to use the `client.nonce.watchNonceIncremented` function from viem to listen for nonce incremented events. It logs the account, nonce key, and new nonce whenever an event occurs. A returned function allows for stopping the watch.
```typescript
import { client } from './viem.config'
const unwatch = client.nonce.watchNonceIncremented({
onNonceIncremented: (args, log) => {
console.log('Account:', args.account)
console.log('Nonce key:', args.nonceKey)
console.log('New nonce:', args.newNonce)
},
})
// Later, stop watching
unwatch()
```
--------------------------------
### Whitelist Update Event Arguments and Types
Source: https://viem.sh/tempo/actions/policy
This TypeScript code defines the structure for arguments and callback functions related to whitelist update events. It specifies the types for account, policy ID, and updater, as well as the signature for the `onWhitelistUpdated` callback and optional filter arguments.
```typescript
type ReturnType = () => void
declare function onWhitelistUpdated(args: Args, log: Log): void
type Args = {
/** Address of the account */
account: Address
/** Whether the account is allowed */
allowed: boolean
/** ID of the policy */
policyId: bigint
/** Address that updated the whitelist */
updater: Address
}
type Args = {
/** Filter by policy ID */
policyId?: bigint | bigint[] | null
/** Filter by updater address */
updater?: Address | Address[] | null
/** Filter by account address */
account?: Address | Address[] | null
}
```
--------------------------------
### policy.watchWhitelistUpdated
Source: https://viem.sh/tempo/actions/policy
Watches for whitelist update events on the TIP403 Registry. It returns a function to unsubscribe from the event.
```APIDOC
## POST /policy/watchWhitelistUpdated
### Description
Watches for whitelist update events on the TIP403 Registry. Returns a function to unsubscribe from the event.
### Method
POST
### Endpoint
/policy/watchWhitelistUpdated
### Parameters
#### Request Body
- **onWhitelistUpdated** (function) - Required - Callback to invoke when a whitelist is updated.
- **args** (object) - Optional - Filter arguments for the watch.
- **policyId** (bigint | bigint[] | null) - Optional - Filter by policy ID.
- **updater** (Address | Address[] | null) - Optional - Filter by updater address.
- **account** (Address | Address[] | null) - Optional - Filter by account address.
- **fromBlock** (bigint) - Optional - Block to start listening from.
- **onError** (function) - Optional - The callback to call when an error occurred when trying to get for a new block.
- **poll** (true) - Optional - Whether to use polling.
- **pollingInterval** (number) - Optional - Polling frequency (in ms). Defaults to Client's pollingInterval config.
### Request Example
```json
{
"onWhitelistUpdated": "(args, log) => { ... }",
"args": {
"policyId": 123n,
"updater": "0x..."
},
"fromBlock": 1000n,
"onError": "(error) => { ... }",
"poll": true,
"pollingInterval": 1000
}
```
### Response
#### Success Response (200)
- **unwatch** (function) - A function to unsubscribe from the event.
#### Response Example
```json
{
"unwatch": "() => void"
}
```
```
--------------------------------
### Return Type for watchRewardRecipientSet
Source: https://viem.sh/tempo/actions/reward
The `watchRewardRecipientSet` function returns a function that can be called to unsubscribe from the event listener. This ensures proper cleanup of resources.
```typescript
type ReturnType = () => void
```
--------------------------------
### onUserTokenSet Callback Parameters (TypeScript)
Source: https://viem.sh/tempo/actions/fee
Defines the arguments passed to the `onUserTokenSet` callback. It includes the `user` and `token` addresses involved in the event. The callback is invoked whenever a user's fee token is successfully set.
```typescript
declare function onUserTokenSet(args: Args, log: Log): void
type Args = {
/** Address of the user */
user: Address
/** Address of the new fee token */
token: Address
}
```
--------------------------------
### Check TIP-20 Token Role with Viem (TypeScript)
Source: https://viem.sh/tempo/actions/token
This snippet demonstrates how to use the `client.token.hasRole` function from Viem to check if an account has a specific role for a TIP-20 token. It requires the `client` instance, the account's address, the desired role, and the token's address. The function returns a boolean indicating role ownership.
```typescript
import { client } from './viem.config'
const hasRole = await client.token.hasRole({
account: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEbb',
role: 'issuer',
token: '0x20c0000000000000000000000000000000000011',
})
console.log('Has issuer role:', hasRole)
```
--------------------------------
### Policy Actions API
Source: https://viem.sh/tempo/actions
Manages transfer policies for token access control, allowing creation, modification, and authorization checks.
```APIDOC
## Policy Actions
### `policy.create`
**Description:** Creates a new transfer policy for token access control.
### `policy.getData`
**Description:** Gets the data for a transfer policy, including its type and admin address.
### `policy.isAuthorized`
**Description:** Checks if an address is authorized by a transfer policy.
### `policy.modifyBlacklist`
**Description:** Modifies the blacklist for a blacklist-type transfer policy.
### `policy.modifyWhitelist`
**Description:** Modifies the whitelist for a whitelist-type transfer policy.
### `policy.setAdmin`
**Description:** Sets the admin for a transfer policy.
### `policy.watchAdminUpdated`
**Description:** Watches for policy admin update events.
### `policy.watchBlacklistUpdated`
**Description:** Watches for blacklist update events.
### `policy.watchCreate`
**Description:** Watches for policy creation events.
### `policy.watchWhitelistUpdated`
**Description:** Watches for whitelist update events.
```
--------------------------------
### onRewardRecipientSet Callback Signature
Source: https://viem.sh/tempo/actions/reward
Defines the signature for the `onRewardRecipientSet` callback function, which is invoked when a reward recipient is set. It receives arguments detailing the holder and the new recipient, along with the event log.
```typescript
declare function onRewardRecipientSet(args: Args, log: Log): void
type Args = {
/** Token holder address who set their reward recipient */
holder: Address
/** New reward recipient address (zero address indicates opt-out) */
recipient: Address
}
```
--------------------------------
### amm.watchRebalanceSwap
Source: https://viem.sh/tempo/actions/amm
Watches for rebalance swap events on the Fee AMM and provides a callback function to handle the event data.
```APIDOC
## POST /amm/watchRebalanceSwap
### Description
Watches for rebalance swap events on the Fee AMM. Returns a function to unsubscribe from the event.
### Method
POST
### Endpoint
/amm/watchRebalanceSwap
### Parameters
#### Query Parameters
- **userToken** (Address | bigint) - Optional - Address or ID of the user token to filter events.
- **validatorToken** (Address | bigint) - Optional - Address or ID of the validator token to filter events.
#### Request Body
- **onRebalanceSwap** (function) - Required - Callback to invoke when a rebalance swap occurs. It receives `args` (including `userToken`, `validatorToken`, `swapper`, `amountIn`, `amountOut`) and `log`.
- **args** (object) - Optional - Filter parameters for the event. Can include `userToken`, `validatorToken`, `swapper` (Address | Address[] | null).
- **fromBlock** (bigint) - Optional - Block to start listening from.
- **onError** (function) - Optional - The callback to call when an error occurred when trying to get for a new block.
- **poll** (true) - Optional - Whether to use polling.
- **pollingInterval** (number) - Optional - Polling frequency (in ms). Defaults to Client's pollingInterval config.
### Request Example
```json
{
"onRebalanceSwap": "(args, log) => { ... }",
"args": {
"userToken": "0x...",
"validatorToken": "0x..."
},
"fromBlock": 1000000,
"onError": "(error) => { ... }",
"poll": true,
"pollingInterval": 1000
}
```
### Response
#### Success Response (200)
- **unwatch** (function) - A function that can be called to unsubscribe from the event.
#### Response Example
```json
{
"unwatch": "() => void"
}
```
```
--------------------------------
### reward.watchRewardRecipientSet
Source: https://viem.sh/tempo/actions/reward
Watches for reward recipient set events when token holders change their reward recipient. It returns a function to unsubscribe from the event.
```APIDOC
## POST /reward/watchRewardRecipientSet
### Description
Watches for reward recipient set events when token holders change their reward recipient. Returns a function to unsubscribe from the event.
### Method
POST
### Endpoint
/reward/watchRewardRecipientSet
### Parameters
#### Request Body
- **onRewardRecipientSet** (function) - Required - Callback to invoke when a reward recipient is set. It receives `args` and `log` as parameters.
- **args** (object) - Optional - Filters for the event.
- **holder** (Address) - Optional - Filter events by holder address.
- **recipient** (Address) - Optional - Filter events by recipient address.
- **token** (Address) - Required - Address of the TIP-20 token to watch.
### Request Example
```json
{
"onRewardRecipientSet": "(args, log) => { ... }",
"token": "0x...",
"args": {
"holder": "0x...",
"recipient": "0x..."
}
}
```
### Response
#### Success Response (200)
- **unwatch** (function) - A function that can be called to unsubscribe from the event.
#### Response Example
```json
{
"unwatch": "() => void"
}
```
```
--------------------------------
### Optional Filters for watchSetUserToken (TypeScript)
Source: https://viem.sh/tempo/actions/fee
Specifies the optional filter parameters for the `watchSetUserToken` function. These filters allow you to narrow down the events being watched by specifying particular user or token addresses.
```typescript
type Args = {
/** Address of the user to filter by */
user?: Address | Address[] | null
/** Address of the token to filter by */
token?: Address | Address[] | null
}
```
--------------------------------
### Token hasRole
Source: https://viem.sh/tempo/actions/token
Checks if an account has a specific role for a TIP-20 token.
```APIDOC
## GET /token/hasRole
### Description
Checks if an account has a specific role for a TIP-20 token.
### Method
GET
### Endpoint
/token/hasRole
### Parameters
#### Query Parameters
- **account** (Address) - Required - Address to check for the role.
- **role** ("defaultAdmin" | "pause" | "unpause" | "issuer" | "burnBlocked") - Required - Role to check.
- **token** (Address | bigint) - Required - Address or ID of the TIP-20 token.
- **blockNumber** (bigint) - Optional - Block number to read the state from.
- **blockOverrides** (BlockOverrides) - Optional - Block overrides to apply to the state.
- **blockTag** (BlockTag) - Optional - Block tag to read the state from.
- **stateOverride** (StateOverride) - Optional - State override to apply.
### Response
#### Success Response (200)
- **hasRole** (boolean) - Whether the account has the role.
#### Response Example
```json
{
"hasRole": true
}
```
```
--------------------------------
### Nonce Incremented Event Callback Signature
Source: https://viem.sh/tempo/actions/nonce
Defines the signature for the `onNonceIncremented` callback function, which is invoked when a nonce is incremented. It includes the arguments detailing the account, nonce key, and the new nonce value, along with the log object.
```typescript
declare function onNonceIncremented(args: Args, log: Log): void
type Args = {
/** Address of the account */
account: Address
/** Nonce key that was incremented */
nonceKey: bigint
/** New nonce value after increment */
newNonce: bigint
}
```
--------------------------------
### fee.watchSetUserToken
Source: https://viem.sh/tempo/actions/fee
Watches for user token set events on the Fee Manager. This function provides a callback to process events related to user token updates.
```APIDOC
## POST /websites/viem_sh_tempo/fee/watchSetUserToken
### Description
Watches for user token set events on the Fee Manager. Provides a callback to process events related to user token updates.
### Method
POST
### Endpoint
/websites/viem_sh_tempo/fee/watchSetUserToken
### Parameters
#### Query Parameters
- **onUserTokenSet** (function) - Required - Callback to invoke when a user token is set. It receives `args` and `log` as parameters.
- **args** (object) - Optional - Filters for the event.
- **user** (Address | Address[] | null) - Optional - Address of the user to filter by.
- **token** (Address | Address[] | null) - Optional - Address of the token to filter by.
- **fromBlock** (bigint) - Optional - Block to start listening from.
- **onError** (function) - Optional - Callback to call when an error occurred when trying to get for a new block. It receives an `error` object.
- **poll** (true) - Optional - Whether to use polling.
- **pollingInterval** (number) - Optional - Polling frequency (in ms). Defaults to Client's pollingInterval config.
### Request Example
```json
{
"onUserTokenSet": "(args, log) => { console.log('User:', args.user); console.log('New fee token:', args.token); }",
"fromBlock": 12345n,
"onError": "(error) => { console.error(error); }",
"poll": true,
"pollingInterval": 1000
}
```
### Response
#### Success Response (200)
- **unwatch** (function) - A function to unsubscribe from the event.
#### Response Example
```json
{
"unwatch": "() => void"
}
```
```
--------------------------------
### onError Callback for watchSetUserToken (TypeScript)
Source: https://viem.sh/tempo/actions/fee
Defines the `onError` callback function for `watchSetUserToken`. This callback is invoked if any errors occur while attempting to retrieve new block information for event watching. It receives an `Error` object as its argument.
```typescript
declare function onError(error: Error): void
```
--------------------------------
### nonce.watchNonceIncremented
Source: https://viem.sh/tempo/actions/nonce
Watches for nonce incremented events. This event is emitted whenever a transaction is executed using a specific nonce key.
```APIDOC
## POST /nonce/watchNonceIncremented
### Description
Watches for nonce incremented events. This event is emitted whenever a transaction is executed using a specific nonce key.
### Method
POST
### Endpoint
/nonce/watchNonceIncremented
### Parameters
#### Query Parameters
- **fromBlock** (bigint) - Optional - Block to start listening from.
- **poll** (true) - Optional - Whether to use polling.
- **pollingInterval** (number) - Optional - Polling frequency (in ms). Defaults to Client's pollingInterval config.
#### Request Body
- **onNonceIncremented** (function) - Required - Callback to invoke when a nonce is incremented. Arguments: `args` (object with `account`, `nonceKey`, `newNonce`), `log` (object).
- **args** (object) - Optional - Filters for the event. Can include `account` (Address | Address[] | null) and `nonceKey` (bigint | bigint[] | null).
- **onError** (function) - Optional - Callback to call when an error occurred when trying to get for a new block. Arguments: `error` (Error).
### Request Example
```json
{
"onNonceIncremented": "(args, log) => { console.log(args); }",
"args": {
"account": "0x...",
"nonceKey": 1n
},
"onError": "(error) => { console.error(error); }"
}
```
### Response
#### Success Response (200)
- **ReturnType** (function) - A function to unsubscribe from the event.
#### Response Example
```javascript
// Returns a function to unsubscribe
const unwatch = () => {};
```
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.