<!-- tempo-docs-context -->
> Source: [/docs/network/examples](https://tempo.xyz/developers/docs/network/examples.md)
> Section: [Tempo EVM](https://tempo.xyz/developers/docs/development.md). Build on Tempo EVM: wallets and keys, transactions and fees, TIP-20 Tokens, contracts, exchange, network details, nodes, protocol specifications, and changelog.
> [Documentation index](https://tempo.xyz/developers/llms.txt) · [Docs skill](https://tempo.xyz/developers/SKILL.md)

> Tempo MCP: Use `search`, `find_pages`, `read_page`, and `code` at `https://mcp.tempo.xyz` for Tempo and related documentation.
> If an indexed page is missing or reflects an older site, read this site’s [documentation index](https://tempo.xyz/developers/llms.txt) and Markdown pages directly.

# Network examples

Set up the clients used in the Network guides. These examples use a funded test account on Moderato and AlphaUSD for transaction fees. Keep private keys on your server.

For Viem and Python, set `TEMPO_PRIVATE_KEY` to the account's private key. Set `TEMPO_RECIPIENT` to another test address you control for the CLI and server examples. Use the [faucet](https://tempo.xyz/developers/docs/quickstart/faucet) to fund the sender. The examples use 1,000,000 base units for one AlphaUSD.

<span id="typescript-setup" />

## Viem setup

Use an ESM project (`"type": "module"` in `package.json`). Install `viem` and a TypeScript runner with `pnpm add viem` and `pnpm add -D tsx`. Save this file as `network.config.ts` beside the example you run:

```ts [network.config.ts]
import { getAddress } from 'viem'
import { Account, createClient } from 'viem/tempo'

const privateKey = process.env.TEMPO_PRIVATE_KEY
const recipientAddress = process.env.TEMPO_RECIPIENT
if (!privateKey || !/^0x[0-9a-fA-F]{64}$/.test(privateKey))
  throw new Error('Set TEMPO_PRIVATE_KEY to your funded test account private key')
if (!recipientAddress) throw new Error('Set TEMPO_RECIPIENT to an address you control')

export const alphaUsd = '0x20c0000000000000000000000000000000000001'
export const betaUsd = '0x20c0000000000000000000000000000000000002'
export const recipient = getAddress(recipientAddress)
export const client = createClient({
  account: Account.fromSecp256k1(privateKey as `0x${string}`),
  testnet: true,
  feeToken: alphaUsd,
})
```

The complete transaction example below builds one call, fills transaction fields, signs, submits, and checks the receipt. Run it with `pnpm exec tsx transaction.ts`.

```ts [transaction.ts]
import { alphaUsd, client, recipient } from './network.config'

const call = client.token.transfer.call({
  token: alphaUsd,
  to: recipient,
  amount: 1_000_000n,
})
const request = await client.prepareTransactionRequest({ calls: [call] })

const serializedTransaction = await client.signTransaction(request)
const hash = await client.sendRawTransaction({ serializedTransaction })

const receipt = await client.waitForTransactionReceipt({ hash })
if (receipt.status !== 'success') throw new Error('Transaction reverted')
console.log(receipt.transactionHash)
```

For fee examples, import `formatUnits` from `viem`. For Exchange examples, import `Addresses` from `viem/tempo`. Import `client`, `alphaUsd`, `betaUsd`, and `recipient` from `./network.config` as needed.

### Sponsored transactions

Import `createClient`, `http`, and `withRelay` from `viem/tempo`, then configure a client that uses the public testnet sponsor:

```ts
const sponsored = createClient({
  account: client.account,
  testnet: true,
  feeToken: alphaUsd,
  transport: withRelay(http(), http('https://sponsor.moderato.tempo.xyz')),
})
```

The [fee examples](https://tempo.xyz/developers/docs/network/fees#sponsor-fees) use this `sponsored` client. The sender still needs the tokens it transfers.

## Wagmi setup

Use Wagmi actions inside a browser application with a connected Tempo wallet. Install `wagmi`, `viem`, and `@tanstack/react-query`. Save the configuration below as `network.wagmi.config.ts`; it selects Moderato and requests testnet sponsorship when an action passes `feePayer: true`.

```ts [network.wagmi.config.ts]
import { tempoModerato } from 'viem/chains'
import { createConfig, http } from 'wagmi'
import { tempoWallet } from 'wagmi/connectors'

export const alphaUsd = '0x20c0000000000000000000000000000000000001'
export const betaUsd = '0x20c0000000000000000000000000000000000002'
const chain = tempoModerato.extend({ feeToken: alphaUsd })
export const config = createConfig({
  chains: [chain],
  connectors: [tempoWallet({ feePayer: 'https://sponsor.moderato.tempo.xyz' })],
  transports: { [chain.id]: http() },
})
```

Follow [Connect a wallet](https://tempo.xyz/developers/docs/accounts/integrate) for the providers and connect button. Pass this `config` to your `WagmiProvider`. Get `accountAddress` from the connected wallet and `recipient` from your validated form. Run write actions in an event handler after the user reviews them.

The main snippets use these imports as needed:

```ts
import { formatUnits } from 'viem'
import { Actions as ViemActions, Addresses } from 'viem/tempo'
import { estimateGas, getGasPrice } from 'wagmi/actions'
import { waitForTransactionReceipt } from 'wagmi/actions'
import { Actions } from 'wagmi/tempo'
import { alphaUsd, betaUsd, config } from './network.wagmi.config'
```

`Actions` uses the connected signer; `ViemActions.token.transfer.call` only encodes the call. The [wallet payment demo](https://tempo.xyz/developers/docs/guide/payments/send-a-payment#send-payment-demo) shows React hooks for pending state and confirmation.

### Machine payment clients

Machine payments use `Mppx` and `tempo` from `mppx/client`; install `mppx` with `viem`. The Viem tab uses the payer `account` from the [MPP client guide](https://tempo.xyz/developers/docs/guide/machine-payments/client#define-the-mpp-payer-account). The Wagmi tab imports `getConnectorClient` from `wagmi/actions` and uses a connected wallet with this separate mainnet configuration:

```ts
import { tempo as tempoMainnet } from 'viem/chains'
import { createConfig, http } from 'wagmi'
import { getConnectorClient } from 'wagmi/actions'
import { tempoWallet } from 'wagmi/connectors'

export const mppConfig = createConfig({
  chains: [tempoMainnet],
  connectors: [tempoWallet()],
  transports: { [tempoMainnet.id]: http() },
})
```

Use `mppConfig` for that app's `WagmiProvider` and connect flow. Mainnet service payments require mainnet funds. For a testnet service, select Moderato instead; keep the wallet and service on the same network. Pass the service's URL as `paidUrl` when calling the [machine payment example](https://tempo.xyz/developers/docs/agents#pay-for-an-api).

## CLI setup

Install the latest [Foundry](https://tempo.xyz/developers/docs/sdk/foundry#get-started-with-foundry) with Tempo support. The snippets use `cast` for contract calls and transactions; `--interactive` prompts for the test account's signing key. The Exchange quote command also uses `jq` to read the JSON result.

Set the account and recipient addresses to test accounts you control, then configure the shared values:

```bash
export RPC_URL=https://rpc.moderato.tempo.xyz
export SENDER="$TEMPO_SENDER_ADDRESS"
export TOKEN=0x20c0000000000000000000000000000000000001
export BETA_TOKEN=0x20c0000000000000000000000000000000000002
export FACTORY=0x20fc000000000000000000000000000000000000
export DEX=0xdec0000000000000000000000000000000000000
```

Fund `SENDER` with the [faucet](https://tempo.xyz/developers/docs/quickstart/faucet). `TOKEN` is AlphaUSD for these examples; token issuance saves its new address separately as `DEMO_TOKEN`. The [Foundry Tempo guide](https://www.getfoundry.sh/guides/tempo) documents current CLI options, including fee tokens and remote sponsorship.

## Python setup

Install `pytempo` with `pip install pytempo`. Save these blocks, in order, as `network_config.py` beside your script. The examples use pytempo 0.6.1 and web3.py 7.

```python [network_config.py]
import os
from web3 import Web3
from pytempo import Call, TempoTransaction
from pytempo.contracts import ALPHA_USD, BETA_USD, TIP20

w3 = Web3(Web3.HTTPProvider("https://rpc.moderato.tempo.xyz"))
account = w3.eth.account.from_key(os.environ["TEMPO_PRIVATE_KEY"])
recipient = Web3.to_checksum_address(os.environ["TEMPO_RECIPIENT"])
```

`make_transaction` fills the chain ID, nonce, fee token, and gas limit for a list of calls. It estimates the complete batch, adds a 20% gas buffer, and sets a maximum gas price at twice the current suggestion. Review those choices for your application. `submit` signs, broadcasts, and checks execution status.

```python [network_config.py]
def make_transaction(calls, fee_token=ALPHA_USD):
    rpc_calls = [{
        "to": Web3.to_checksum_address(bytes(call.to)),
        "data": "0x" + call.data.hex(),
        "value": hex(call.value),
    } for call in calls]
    gas_request = {
        "type": "0x76", "from": account.address,
        "feeToken": fee_token, "calls": rpc_calls,
    }
    gas = int(w3.manager.request_blocking("eth_estimateGas", [gas_request]), 16)
    return TempoTransaction.create(
        chain_id=w3.eth.chain_id,
        gas_limit=(gas * 12 + 9) // 10,
        max_fee_per_gas=w3.eth.gas_price * 2,
        max_priority_fee_per_gas=0,
        nonce=w3.eth.get_transaction_count(account.address),
        fee_token=fee_token,
        calls=tuple(calls),
    )


def submit(tx):
    signed = tx.sign(account.key.hex())
    tx_hash = w3.eth.send_raw_transaction(signed.encode())
    receipt = w3.eth.wait_for_transaction_receipt(tx_hash)
    if receipt["status"] != 1:
        raise RuntimeError("Transaction reverted")
    return receipt
```

For token creation and Exchange examples, add the contract bindings below. The factory ABI uses the six-argument [`createToken` overload](https://tempo.xyz/developers/docs/protocol/tip20/spec#tip20factory); Exchange uses the ABI supplied by pytempo.

```python [network_config.py]
from pytempo.contracts import (
    STABLECOIN_DEX_ABI, STABLECOIN_DEX_ADDRESS, TIP20_FACTORY_ADDRESS,
)

factory_abi = [
    {
        "type": "function", "name": "createToken", "stateMutability": "nonpayable",
        "inputs": [{"name": name, "type": kind} for name, kind in [
            ("name", "string"), ("symbol", "string"), ("currency", "string"),
            ("quoteToken", "address"), ("admin", "address"), ("salt", "bytes32"),
        ]],
        "outputs": [{"name": "token", "type": "address"}],
    },
    {
        "type": "function", "name": "getTokenAddress", "stateMutability": "pure",
        "inputs": [{"name": "sender", "type": "address"}, {"name": "salt", "type": "bytes32"}],
        "outputs": [{"name": "token", "type": "address"}],
    },
]
factory = w3.eth.contract(address=TIP20_FACTORY_ADDRESS, abi=factory_abi)
dex = w3.eth.contract(address=STABLECOIN_DEX_ADDRESS, abi=STABLECOIN_DEX_ABI)
```

Use the main guide's imports, or import the shared names you need from `network_config`. The [Python SDK](https://tempo.xyz/developers/docs/sdk/python) covers custom transactions, fee sponsorship, and access keys.

## HTTP requests

JSON-RPC reads use the same endpoint as SDKs. Set `RPC_URL=https://rpc.moderato.tempo.xyz`. Requests below do not use an API key.

For gas estimation, set `TEMPO_SENDER_ADDRESS` to the funded account address, then set `SENDER` and `CALL_DATA` below. You can generate the calldata with [Cast](https://tempo.xyz/developers/docs/sdk/foundry):

```bash
export RPC_URL=https://rpc.moderato.tempo.xyz
export SENDER="$TEMPO_SENDER_ADDRESS"
export TOKEN=0x20c0000000000000000000000000000000000001
export CALL_DATA=$(cast calldata 'transfer(address,uint256)' "$TEMPO_RECIPIENT" 1000000)
```

For transaction submission, set `SIGNED_TX` to the hex-encoded signed transaction from the TypeScript or Python signing step. For receipt lookup, set `TX_HASH` to the returned transaction hash. JSON-RPC broadcasts signed transactions; the signing key stays in your application or wallet.

The [JSON-RPC reference](https://tempo.xyz/developers/docs/protocol/rpc) documents method behavior. The [hosted API](https://tempo.xyz/developers/docs/api) is a separate interface for indexed data and services.
