142 lines
3.6 KiB
Plaintext

# Getting Started
## Overview
[Tempo](https://tempo.xyz) is a purpose-built Layer 1 blockchain optimized for payments.
It enshrines features like [token management](https://docs.tempo.xyz/protocol/tip20/overview), [Fee AMM](https://docs.tempo.xyz/protocol/fees), and a [stablecoin DEX](https://docs.tempo.xyz/protocol/exchange) directly into the protocol, as well as a [Tempo transaction type](https://docs.tempo.xyz/protocol/transactions) with support for batch calls, fee sponsorship, configurable fee tokens, concurrent transactions, access keys, and scheduled execution.
## Setup
Setup the Tempo extension for Viem by following the steps below.
::::steps
### Install
To use the Tempo extension, ensure that you have Viem installed.
:::code-group
```bash [npm]
npm i viem
```
```bash [pnpm]
pnpm i viem
```
:::
### Configure
Next, we will configure a [Viem Client](/docs/clients/custom).
In the snippet below, we will set up a Tempo chain, and extend our client with `tempoActions`.
```ts twoslash [viem.config.ts]
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::tip
It is also possible to set up a default fee token by adding a `feeToken` property to the chain.
```ts
export const client = createClient({
chain: tempoModerato.extend({ // [!code hl]
feeToken: '0x20c0000000000000000000000000000000000001', // [!code hl]
}), // [!code hl]
// ...
})
```
:::
### 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](https://docs.tempo.xyz/protocol/transactions#properties)
like `calls` (batch transactions), `feePayer` (fee sponsorship), `nonceKey` (concurrent transactions) and more!
:::code-group
```ts twoslash [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,
})
```
```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::
:::tip
[See all Viem Actions](/docs/actions/public/introduction)
:::
### Use Tempo Actions
You can also use [Tempo-specific Actions](/tempo/actions):
:::code-group
```ts twoslash [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
)
// @log: Alpha USD Metadata: Alpha USD, AlphaUSD, 6, 1000000000000000000000n
```
```ts twoslash [viem.config.ts] filename="viem.config.ts"
// [!include ~/snippets/tempo/viem.config.ts:setup]
```
:::
:::tip
[See all Tempo Actions](/tempo/actions)
:::
### Next Steps
After you have set up Tempo with Viem, you can now:
- Follow a guide on how to [use accounts](https://docs.tempo.xyz/guide/use-accounts), [make payments](https://docs.tempo.xyz/guide/payments), [issue stablecoins](https://docs.tempo.xyz/guide/issuance) and [exchange stablecoins](https://docs.tempo.xyz/guide/stablecoin-exchange).
- Use the [suite of Tempo Actions](/tempo/actions)
::::