Skip to content

Track Transactions

Package: @decent.xyz/box-hooks
Hook: useDecentScan

Decent operates a scanner that enables developers to easily track and analyze all of their transactions. The useDecentScan hook is built on the Decent Scan API's.

The useDecentScan hook leverages SWR for efficient polling. This does introduce swr as a peer dependency.

Types

TxStatusArgs

Please refer to the ChainId type in the Box Common types glossary.

type TxnStatusArgs = {
  srcTxHash: ChainId;
  srcChainId: string;
};

Sample Request & Implementation

import { useDecentScan, useBoxAction } from "@decent.xyz/box-hooks";
import { BoxActionRequest } from "@decent.xyz/box-common";
import { sendTransaction } from "@wagmi/core";
import { wagmiConfig } from '../your_wagmi_config_path';
 
// wagmi a required prop in v2.1.0 and higher.
// Create a config for your project following these docs:
// https://wagmi.sh/react/api/createConfig
 
export async function sendDecentTransaction({
  txConfig,
}: {
  txConfig: BoxActionRequest;
}) {
  const { actionResponse, isLoading, error } = useBoxAction(txConfig);
 
  const gas = await publicClient?.estimateGas({ 
    account,
    ...tx,
  });
 
  const hash = await sendTransaction(wagmiConfig, {
    ...tx,
    gas,
  });
  return hash;
 
  const { data, isLoading } = useDecentScan({ 
    srcTxHash: hash, 
    srcChainId: txConfig.srcChainId, 
  }); 
}