Version: 25.2.0

View .md

dApp Best Practices Checklist

Written by Claude Barde & Maxwell Ward

Use this best practices checklist while building a Tezos dApp and before shipping to production. Each section covers common architectural pitfalls, TypeScript patterns verified against @taquito/* with strict: true, and ready-to-use prompts you can hand to a coding agent to audit your repository automatically.

Quick Summary Checklist

AreaCheckWhy it matters
RPC & InfrastructureUse a managed or dedicated RPC endpoint via environment configPublic community nodes are rate-limited and have no SLA during traffic spikes.
RPC & InfrastructureReuse ContractAbstraction promises across callsCalling Tezos.wallet.at(address) repeatedly re-fetches the contract’s script and entrypoints every time.
Performance & DataSet MichelCodecPacker on TezosToolkit when using big_map or PACKPacks Michelson data locally instead of calling the node’s pack_data endpoint, cutting big_map lookup round-trips by 50%.
Performance & DataGroup multi-step flows with the Batch APIPrevents counter_in_the_past errors, reduces wallet confirmation prompts, and executes dependent calls atomically.
Performance & DataKeep values in BigNumber and validate inputs with @taquito/utilsAvoids JavaScript Number precision loss or scientific notation bugs and catches invalid addresses before hitting the wallet.
Wallet IntegrationRegister a dedicated Reown projectId and lock down its domain allowlistRequired by Reown Terms of Service; the shared fallback projectId is deprecated and will be removed.
Wallet IntegrationShare a single BeaconWallet instance and re-call Tezos.setWalletProvider(wallet) on account switchPrevents duplicate pairing modals and clears cached public key / PKH state across wallet, preparation, and estimation providers.
Wallet IntegrationCall wallet.disconnect() on logout, not wallet.clearActiveAccount()clearActiveAccount() leaves beacon:matrix-selected-node in localStorage, which can block future connections if a relay rotates.
Transactions & UXPrefer wallet/dynamic estimation over brittle hard-coded gas and storage limitsHard-coded limits break when protocol constants change or when a call allocates new storage (such as a first-time big_map entry).
Transactions & UXAwait op.confirmation(), check await op.status() === 'applied', and handle BeaconErrorop.confirmation() only waits for block inclusion; checking op.status() and typed errors catches backtracked operations, simulation failures, and user cancellations.

Infrastructure & RPC Resilience

1. Use a reliable RPC endpoint

Public RPC endpoints listed on RPC Nodes are convenient for development and testnets, but production dApps should run their own Octez node or use a managed RPC provider with load balancing and an SLA.

Verify before launch:

  • Configure the RPC URL via environment variables (for example import.meta.env.VITE_TEZOS_RPC_URL) rather than hard-coding a single host in source files, and make sure no deprecated hosts (such as *.tezos.ecadinfra.com) remain in config files.
  • CORS headers on your RPC endpoint allow requests from your production apex domain (https://example.com) and any subdomain (https://app.example.com).
  • Network alignment matches between new TezosToolkit(rpcUrl) and the network: { type: ... } passed to BeaconWallet.
  • Keep local forging enabled: When using Tezos.wallet, the user’s wallet forges operations. If your application also signs directly via Tezos.contract, keep Taquito’s default LocalForger rather than switching to RpcForger on an untrusted node.

2. Reuse ContractAbstraction instances

Every call to Tezos.wallet.at(address) or Tezos.contract.at(address) fetches the contract’s Michelson script and entrypoints from the RPC node. Avoid calling .at(address) inside component render loops, reactive watchers, or on every button click.

Cache the resolved ContractAbstraction promise per (rpcUrl, address) in your application store:

import { TezosToolkit, MichelCodecPacker, type WalletContract } from '@taquito/taquito';

export const Tezos = new TezosToolkit(
  import.meta.env.VITE_TEZOS_RPC_URL ?? 'https://rpc.tzkt.io/mainnet'
);

// Pack Michelson values locally instead of making an RPC round-trip
Tezos.setPackerProvider(new MichelCodecPacker());

const contractCache = new Map<string, Promise<WalletContract>>();

export function getWalletContract(address: string): Promise<WalletContract> {
  let cached = contractCache.get(address);
  if (!cached) {
    cached = Tezos.wallet.at(address).catch((err) => {
      contractCache.delete(address);
      throw err;
    });
    contractCache.set(address, cached);
  }
  return cached;
}
Note

If several independent components mount at once and query the same RPC endpoints simultaneously, you can optionally wrap new RpcClient(rpcUrl) in RpcClientCache with its default 1000ms TTL to deduplicate burst reads. Avoid multi-second TTLs on RpcClientCache: because it caches 'head' reads (getStorage, getBalance) purely by wall-clock time, a long TTL can return stale pre-confirmation state when you refresh right after await op.confirmation().


Performance & Data Handling

1. Enable local packing (MichelCodecPacker)

By default, TezosToolkit uses RpcPacker, which sends an HTTP POST to /chains/main/blocks/head/helpers/scripts/pack_data every time your dApp packs data (including every key lookup on a BigMapAbstraction). Enabling MichelCodecPacker performs PACK serialization locally in JavaScript and cuts big_map lookup round-trips in half:

import { TezosToolkit, MichelCodecPacker } from '@taquito/taquito';

const Tezos = new TezosToolkit(rpcUrl);
Tezos.setPackerProvider(new MichelCodecPacker());

2. Batch sequential operations

Each Tezos manager account maintains an incrementing on-chain counter. Firing two .send() calls concurrently without waiting for block inclusion causes the second operation to fail with a counter error. Whenever a user action requires multiple operations (such as an FA2 update_operators approval followed by a contract call), group them with the Batch API so the user signs once and the operations execute atomically:

const fa2Contract = await getWalletContract(fa2Address);
const marketContract = await getWalletContract(marketAddress);

const batch = Tezos.wallet
  .batch()
  .withContractCall(
    fa2Contract.methodsObject.update_operators([
      {
        add_operator: {
          owner: userAddress,
          operator: marketAddress,
          token_id: tokenId,
        },
      },
    ])
  )
  .withContractCall(
    marketContract.methodsObject.buy({
      token_id: tokenId,
      price: priceInMutez,
    })
  );

const batchOp = await batch.send();
await batchOp.confirmation(1);

3. Guard UI lifecycle hooks and use indexers for bulk queries

Framework hooks (useEffect in React, watch / onMounted in Vue, $effect in Svelte) can easily trigger request storms if dependencies are unstable:

  • Do not poll the RPC node on every component render. Poll at block intervals (or subscribe via Confirmation & Event Streams) and unsubscribe block streams when components unmount.
  • Use an indexer API (such as TzKT) when listing historical transactions, paginating big_map keys, or aggregating token balances across many contracts, rather than issuing dozens of sequential RPC requests from the browser.

4. Handle BigNumber, token decimals, and address validation safely

Michelson int and nat values have arbitrary precision. Taquito returns numeric storage fields as bignumber.js instances. Converting them with Number(value) or parseInt(value, 10) risks silent precision loss above Number.MAX_SAFE_INTEGER (9,007,199,254,740,991) or scientific notation in UI inputs.

Validate user-supplied addresses with @taquito/utils and scale mutez or token amounts with BigNumber.shiftedBy() before constructing operations:

import BigNumber from 'bignumber.js';
import { isValidAddress, isValidContractAddress } from '@taquito/utils';

// 1. Validate addresses before calling the RPC or wallet
if (!isValidAddress(recipientInput)) {
  throw new Error('Enter a valid Tezos address.');
}
if (!isValidContractAddress(tokenContractInput)) {
  throw new Error('Enter a valid smart contract address (KT1...).');
}

// 2. Convert mutez (6 decimals) and FA1.2/FA2 token amounts without float rounding bugs
const balanceMutez = new BigNumber('12500000'); // 12.5 tez from RPC or storage
const displayTez = balanceMutez.shiftedBy(-6).toFixed(); // '12.5'

const rawTokenBalance = new BigNumber('1500000000000000000'); // 1.5 tokens (18 decimals)
const displayToken = rawTokenBalance.shiftedBy(-18).toFixed(); // '1.5'

Wallet Integration

1. Configure your own WalletConnect (Reown) projectId and domain allowlist

Warning

Every production dApp using @taquito/beacon-wallet must register its own projectId at Reown Cloud and pass it via walletConnectOptions.projectId. The legacy shared fallback projectId is deprecated, violates the Reown Terms of Service, and will be removed in the next minor release. Without your own projectId, WalletConnect pairings (such as Kukai Mobile and scanning the Kukai QR code) will stop working.

Follow the full setup steps in Wallet API: WalletConnect Project ID:

  1. Create a free project in Reown Cloud and pass walletConnectOptions: { projectId } to new BeaconWallet(...).
  2. Lock down your Domain Allowlist in Reown Cloud before going live. Include both your apex domain (https://example.com) and wildcard subdomains (https://*.example.com), as wildcards do not match the apex origin.
  3. Verify pairing from both an allowed production origin and an unallowed origin (which should fail with "Origin not allowed.").
  4. Fail your production CI build if the environment variable holding your projectId is missing.

2. Share a single BeaconWallet instance and reset provider caches on account change

Instantiate BeaconWallet once at the application root (for example, in a React Context, Vue Pinia store, or Svelte store) and reuse it everywhere. Creating multiple BeaconWallet instances causes duplicate event listeners, conflicting localStorage state, and broken operation signing.

Taquito caches the active account’s public key hash (pkh) and public key (pk) inside the wallet, preparation, and estimation providers. When the user switches accounts in their wallet, you must call Tezos.setWalletProvider(wallet) again to clear those caches (see Wallet API: The Wallet instance):

import { TezosToolkit } from '@taquito/taquito';
import { BeaconEvent, BeaconWallet } from '@taquito/beacon-wallet';
import { NetworkType } from '@taquito/beacon-wallet/types';

export const Tezos = new TezosToolkit(
  import.meta.env.VITE_TEZOS_RPC_URL ?? 'https://rpc.tzkt.io/mainnet'
);

export const wallet = new BeaconWallet({
  name: 'My Production dApp',
  iconUrl: 'https://example.com/icon.svg',
  network: { type: NetworkType.MAINNET },
  walletConnectOptions: {
    projectId: import.meta.env.VITE_REOWN_PROJECT_ID,
  },
});

Tezos.setWalletProvider(wallet);

// Call once during app startup BEFORE calling wallet.requestPermissions()
export async function initWalletListeners(): Promise<() => void> {
  return wallet.subscribeToEvent(BeaconEvent.ACTIVE_ACCOUNT_SET, async (account) => {
    // Re-registering the provider clears cached PKH/PK in wallet, prepare, and estimate providers
    Tezos.setWalletProvider(wallet);

    if (account) {
      const info = await wallet.getWalletInfo();
      console.log('Active account:', account.address, 'via', info?.name);
    } else {
      console.log('Wallet disconnected');
    }
  });
}

3. Use wallet.disconnect() on logout, not clearActiveAccount()

When a user clicks “Disconnect” or “Log out” in your UI, always call await wallet.disconnect():

  • await wallet.disconnect() notifies the paired wallet, clears the active account, and tears down active transports. You can still reconnect later on the same BeaconWallet instance by calling await wallet.requestPermissions().
  • await wallet.clearActiveAccount() only clears the active account pointer and leaves beacon:matrix-selected-node in localStorage. If that Matrix relay node later goes offline, returning users can be stuck unable to pair until they manually clear browser storage. Reserve clearActiveAccount() strictly for switching accounts within an active session.

4. Test across all three Beacon transport families

Before launching, test your connect, sign, and disconnect flows across each transport family supported by @taquito/beacon-wallet and Wallets:

  • Browser extension (postMessage): Temple browser extension.
  • Matrix P2P relay: Kukai Web, Temple Mobile, or Umami.
  • WalletConnect v2: Kukai Mobile (iOS) or scanning the Kukai QR code.
  • Hardware wallet signing: Ledger connected through Temple or Kukai (verify that long signing prompts do not time out in your UI).

Transaction Lifecycle, Limits & Error UX

1. Avoid brittle hard-coded gas and storage limits

Hard-coding fee, gasLimit, and storageLimit in .send({ ... }) saves an estimation RPC call, but breaks easily in production when:

  • A Tezos protocol upgrade adjusts gas weights or minimum fees.
  • A user’s execution path allocates new storage (for example, minting a user’s first entry in a big_map or sending tez to an unallocated implicit account, which burns storage for allocation).

Recommended practice:

  • For standard Tezos.wallet calls, omit explicit limits in .send() so the connected wallet estimates gas, storage, and fees automatically.
  • If you need to preview or customize transaction limits before sending a wallet contract call, convert the call with .toTransferParams() and pass it to Tezos.estimate.transfer(...) rather than hard-coding magic numbers:
const transferParams = await contract.methodsObject.myEntrypoint(args).toTransferParams();
const estimate = await Tezos.estimate.transfer(transferParams);

2. Wait for confirmations and verify op.status() === 'applied'

When .send() resolves, the operation has only been broadcast to the network, not included in a block. Furthermore, await op.confirmation(1) on a WalletOperation resolves once the block is confirmed even if the operation was backtracked, failed, or skipped. For critical state updates, verify await op.status() === 'applied' after confirmation (or await op.contract() when originating a contract).

Tip

Beacon’s built-in UI (enableToasts: true by default) automatically displays progress toasts while waiting for a wallet acknowledgement and if a late response arrives. If you suppress built-in toasts (uiOptions: { enableToasts: false }) or configure a custom requestTimeoutMs, subscribe to BeaconEvent.WAITING_FOR_WALLET_ACK (supported on extension and Matrix transports) and BeaconEvent.LATE_RESPONSE_RECEIVED as shown in Wallet API: Transport connection health.

3. Display actionable error messages for wallet, RPC, and FAILWITH failures

Users should never face a silent failure or [object Object] when an operation is rejected, backtracked, or cancelled. Distinguish between:

  • User cancellation in the wallet (AbortedBeaconError)
  • Simulation or invalid transaction errors surfaced through Beacon (TransactionInvalidBeaconError with isTezosRpcError, where with is a Micheline object such as { string: 'FA2_INSUFFICIENT_BALANCE' })
  • Direct smart contract FAILWITH errors (TezosOperationError)
import { TezosOperationError } from '@taquito/taquito';
import {
  AbortedBeaconError,
  isBeaconError,
  isTezosRpcError,
  TransactionInvalidBeaconError,
} from '@taquito/beacon-wallet';

function extractRpcErrorDetail(data: unknown): string | undefined {
  if (!Array.isArray(data)) return undefined;
  const last = data.filter(isTezosRpcError).at(-1);
  if (!last) return undefined;
  const w = last.with;
  if (typeof w === 'object' && w !== null) {
    if ('string' in w && typeof w.string === 'string') return w.string;
    if ('int' in w && (typeof w.int === 'string' || typeof w.int === 'number')) {
      return String(w.int);
    }
    return JSON.stringify(w);
  }
  return last.id;
}

try {
  const op = await contract.methodsObject.transfer(params).send();
  await op.confirmation(1);
  const status = await op.status();
  if (status !== 'applied') {
    throw new Error(`Transaction was not applied on-chain (status: ${status}).`);
  }
} catch (err) {
  if (err instanceof AbortedBeaconError) {
    showToast('Transaction cancelled in wallet.');
  } else if (err instanceof TransactionInvalidBeaconError) {
    const detail = extractRpcErrorDetail(err.data) ?? err.description;
    showErrorModal('Transaction rejected by network simulation', detail);
  } else if (isBeaconError(err)) {
    showErrorModal(err.title, err.description);
  } else if (err instanceof TezosOperationError) {
    // See "Catching FAILWITH errors" for non-string Michelson error payloads
    showErrorModal('Contract execution failed', err.message);
  } else {
    reportToErrorTracker(err); // e.g. Sentry or BugSnag
    showErrorModal(
      'Transaction failed',
      err instanceof Error ? err.message : 'Please try again or check your connection.'
    );
  }
}

Coding Agent Audit Prompts

If you use an AI coding agent (such as Claude Code, Cursor, Gemini, Codex, or GitHub Copilot), paste the prompts below to audit your codebase against these production best practices before launch.

Full dApp Best Practices Audit Prompt

Copy and paste this prompt into your coding agent at the root of your repository:

Audit production code in this Tezos / Taquito dApp repository (skip tests, scripts, and mocks unless they ship in the client bundle). Report ONLY confirmed issues present in the codebase (Critical, High, Medium, Low) with exact `file:line` references and minimal diffs. Omit rules that pass or do not apply, and do not modify files until I review the report.

Check for these concrete failure modes:

1. TezosToolkit & BeaconWallet lifecycle:
   - Multiple `TezosToolkit` or `BeaconWallet` instances created inside component renders or click handlers instead of a shared singleton/store/context, or browser-only `BeaconWallet` initialization executed unconditionally during SSR.
   - Mismatched network configuration between `TezosToolkit` RPC URL and `BeaconWallet` `network.type` (or dead RPC hosts such as `*.tezos.ecadinfra.com` and deprecated testnets).
   - `BeaconEvent.ACTIVE_ACCOUNT_SET` not subscribed before `requestPermissions()`, missing `Tezos.setWalletProvider(wallet)` inside that handler (leaving stale cached `pkh`/`pk` in `wallet`, `prepare`, and `estimate`), or stacking duplicate `subscribeToEvent` listeners without calling the returned unsubscribe function on teardown.
   - Logout handlers calling `wallet.clearActiveAccount()` instead of `await wallet.disconnect()`.

2. WalletConnect (Reown) configuration:
   - `new BeaconWallet(...)` omitting `walletConnectOptions.projectId` (relying on the deprecated shared fallback `projectId` instead of an environment variable).

3. RPC usage & performance bottlenecks:
   - `BigMapAbstraction.get()` or `packData` usage without `Tezos.setPackerProvider(new MichelCodecPacker())`.
   - `Tezos.wallet.at()` or `Tezos.contract.at()` called inside render loops, reactive watchers (`useEffect`, `watch`, `$effect`), or repeated action handlers for the same static contract without reusing the `ContractAbstraction` promise.
   - Unthrottled RPC polling in UI lifecycle hooks or block subscriptions not cleaned up on unmount.
   - Explicit `RpcForger` configured against untrusted RPC endpoints (only relevant if `Tezos.contract` signing is used).

4. Operation batching, limits & confirmation handling:
   - Sequential `.send()` calls in a single user flow that race on the account counter instead of using `Tezos.wallet.batch()`.
   - Hardcoded `fee`, `gasLimit`, or `storageLimit` values in production `.send()` calls that risk breaking on storage allocation or protocol upgrades.
   - `.send()` calls that update final UI state immediately on broadcast without awaiting `op.confirmation()` (or `op.contract()` for originations), or critical flows on `WalletOperation` that never check `await op.status() === 'applied'`.

5. Precision, validation & error handling:
   - `Number(...)`, `parseInt(...)`, or floating-point math applied to mutez, tez, token balances, or arbitrary-precision `BigNumber` contract storage values instead of `BigNumber` (`shiftedBy`) or `@taquito/utils`.
   - Unvalidated user-supplied addresses passed to transfers or contract calls without `isValidAddress` / `isValidContractAddress` from `@taquito/utils`.
   - Wallet/contract `try / catch` blocks that treat `AbortedBeaconError` (user cancellation) as an unexpected crash, render raw `TransactionInvalidBeaconError` Micheline `with` objects as strings (`[object Object]`), or swallow errors silently.

Focused Prompt: Wallet & Beacon Session Audit

Use this shorter prompt when reviewing or refactoring your wallet connection layer:

Inspect production files importing `@taquito/beacon-wallet` or `@ecadlabs/beacon-*`. Report only confirmed bugs with `file:line` references and minimal fixes:
1. `BeaconWallet` instantiated more than once, or initialized during SSR without a browser guard.
2. Missing `walletConnectOptions.projectId` from an environment variable, or `network.type` mismatch with the configured `TezosToolkit` RPC.
3. `BeaconEvent.ACTIVE_ACCOUNT_SET` subscribed after `requestPermissions()`, missing `Tezos.setWalletProvider(wallet)` on account switch, or leaking `subscribeToEvent` listeners across store resets.
4. Logout calling `wallet.clearActiveAccount()` instead of `await wallet.disconnect()`.
5. Missing `AbortedBeaconError` / `isBeaconError` handling around `requestPermissions()` and `.send()`, or (if `requestTimeoutMs` or `uiOptions: { enableToasts: false }` is configured) unhandled `BeaconEvent.LATE_RESPONSE_RECEIVED`.

Focused Prompt: RPC, Batching & Precision Audit

Use this prompt to hunt down performance bottlenecks, counter collisions, and number precision bugs:

Inspect production files importing `@taquito/taquito`, `@taquito/rpc`, or `bignumber.js`. Report only confirmed bugs with `file:line` references and minimal fixes:
1. Dead or hardcoded public RPC URLs (such as `*.tezos.ecadinfra.com`), repeated uncached `.at(address)` calls in reactive hooks/loops, or `big_map` lookups without `MichelCodecPacker`.
2. Back-to-back `.send()` calls from the same account that should use `Tezos.wallet.batch()`.
3. Hardcoded `fee`, `gasLimit`, or `storageLimit` in production `.send()` calls, or `Tezos.estimate.contractCall()` passed a `Wallet` contract method instead of `Tezos.estimate.transfer(method.toTransferParams())`.
4. State treated as final before `await op.confirmation()` (or `await op.contract()`), or assuming `WalletOperation.confirmation()` throws on backtracked operations without checking `await op.status() === 'applied'`.
5. `Number()` / `parseInt()` / float math on mutez, token balances, or `BigNumber` storage fields, or unvalidated user address inputs missing `isValidAddress` / `isValidContractAddress`.

Drop-in AGENTS.md / CLAUDE.md / Cursor Rules Snippet

Add the following block to your repository’s AGENTS.md, CLAUDE.md, or .cursor/rules/taquito.mdc so AI coding agents generate modern @taquito/* code automatically:

## Tezos & Taquito Guidelines

- **Canonical packages:** Always use official `@taquito/*` packages (`@taquito/taquito`, `@taquito/beacon-wallet`, `@taquito/utils`, `@taquito/michel-codec`, `@taquito/tzip12`, `@taquito/tzip16`) and `bignumber.js`. Never substitute unmaintained legacy packages (`@airgap/beacon-sdk`, `conseiljs`) or downstream rebranded forks (`@tezos-x/octez.js`, `@tezos-x/octez.connect`).
- **Machine-readable docs:** Fetch `https://taquito.io/llms.txt` (index and golden-path reference), `https://taquito.io/llms-full.txt` (full corpus), or append `.md` to any doc page (e.g. `https://taquito.io/docs/next/wallet_API.md`).
- **Networks & RPCs:** Use `mainnet`, `shadownet`, or `tallinnnet` (e.g. `https://rpc.tzkt.io/mainnet`, `https://rpc.tzkt.io/shadownet`). Never use retired RPC hosts (`*.tezos.ecadinfra.com`, `mainnet.api.tez.ie`, `mainnet.smartpy.io`) or retired testnets (`ghostnet`, `ithacanet`, `hangzhounet`).
- **Singleton & Wallet setup:**
  - Instantiate `TezosToolkit` and `BeaconWallet` once per app session and configure `Tezos.setPackerProvider(new MichelCodecPacker())`.
  - Pass `network: { type: NetworkType.MAINNET }` (from `@taquito/beacon-wallet/types`) and `walletConnectOptions: { projectId }` in `new BeaconWallet(...)`, never in `requestPermissions()`.
  - Subscribe to `BeaconEvent.ACTIVE_ACCOUNT_SET` before `requestPermissions()` and call `Tezos.setWalletProvider(wallet)` inside the handler to clear cached `pkh`/`pk` state across `wallet`, `prepare`, and `estimate`.
  - Call `await wallet.disconnect()` on logout, never `wallet.clearActiveAccount()`.
- **Contracts, Batching & Confirmations:**
  - Cache `Tezos.wallet.at(address)` promises instead of re-fetching contract scripts on every render or click.
  - Call entrypoints via `contract.methodsObject.<entrypoint>(params)` (pass `UnitValue` for `unit` entrypoints), never legacy positional `contract.methods.<entrypoint>(...)`.
  - Group sequential operations with `Tezos.wallet.batch()`.
  - After `await op.confirmation(1)`, check `await op.status() === 'applied'` before treating state updates as final.
- **Precision & Validation:** Keep numeric storage values in `BigNumber` (`amount.shiftedBy(-decimals).toFixed()`) and validate user address inputs with `isValidAddress` / `isValidContractAddress` from `@taquito/utils`.