diff --git a/src/pages/guide/tempo-transaction/index.mdx b/src/pages/guide/tempo-transaction/index.mdx index 4413ac5c..fae06cc6 100644 --- a/src/pages/guide/tempo-transaction/index.mdx +++ b/src/pages/guide/tempo-transaction/index.mdx @@ -52,6 +52,12 @@ If you're integrating with Tempo, we **strongly recommend** using Tempo Transact icon="lucide:clock" title="Scheduled Transactions" /> + ## Integration Guides diff --git a/src/snippets/tempo-tx-properties.mdx b/src/snippets/tempo-tx-properties.mdx index 82eabd60..b0fc566c 100644 --- a/src/snippets/tempo-tx-properties.mdx +++ b/src/snippets/tempo-tx-properties.mdx @@ -675,3 +675,75 @@ the transaction can be included in a block. ``` + +### Expiring Nonces + +Expiring nonces allow transactions to automatically expire if not executed within a specified time window. +By using the special `'expiring'` nonce key, Tempo will generate a unique nonce key based on the transaction's +validity window (`validAfter` and `validBefore`), ensuring the transaction can only be executed during that period +and cannot be replayed afterward. + +This is useful for time-sensitive operations like limit orders, auctions, or any transaction that should +become invalid after a deadline. + +
+ + + + + :::code-group + + ```tsx twoslash [example.ts] + // @noErrors + import { client } from './viem.config' + + const hash = await client.sendTransaction({ + data: '0xdeadbeef', + nonceKey: 'expiring', // [!code hl] + to: '0xcafebabecafebabecafebabecafebabecafebabe', + validAfter: Math.floor(Date.now() / 1000), // [!code hl] + validBefore: Math.floor(Date.now() / 1000) + 3600, // expires in 1 hour // [!code hl] + }) + ``` + + ```tsx twoslash [viem.config.ts] + // [!include ~/snippets/viem.config.ts:setup] + ``` + + ::: + + + + + + :::code-group + + ```tsx twoslash [example.ts] + // @noErrors + import { useSendTransaction } from 'wagmi' + + const { sendTransaction } = useSendTransaction() + + sendTransaction({ + data: '0xdeadbeef', + nonceKey: 'expiring', // [!code hl] + to: '0xcafebabecafebabecafebabecafebabecafebabe', + validAfter: Math.floor(Date.now() / 1000), // [!code hl] + validBefore: Math.floor(Date.now() / 1000) + 3600, // expires in 1 hour // [!code hl] + }) + ``` + + ```tsx twoslash [wagmi.config.ts] + // @noErrors + // [!include ~/snippets/wagmi.config.ts:setup] + ``` + + ::: + + + + +:::tip +Expiring nonces combine the benefits of [scheduled transactions](#scheduled-transactions) with automatic replay protection. +Once the `validBefore` timestamp passes, the transaction becomes permanently invalid. +:::