UNPKG

@abstract-foundation/agw-client

Version:
60 lines 1.87 kB
import { InvalidParameterError, isHex, TransactionReceiptNotFoundError, } from "viem"; import { getTransactionReceipt } from "viem/actions"; /** * Returns the status of a call batch that was sent via `sendCalls`. * * - Docs: https://viem.sh/docs/actions/wallet/getCallsStatus * - JSON-RPC Methods: [`wallet_getCallsStatus`](https://eips.ethereum.org/EIPS/eip-5792) * * @param client - Client to use * @returns Status of the calls. {@link GetCallsStatusReturnType} * * @example * import { createWalletClient, custom } from 'viem' * import { mainnet } from 'viem/chains' * import { getCallsStatus } from 'viem/actions' * * const client = createWalletClient({ * chain: mainnet, * transport: custom(window.ethereum), * }) * const { receipts, status } = await getCallsStatus(client, { id: '0xdeadbeef' }) */ export async function getCallsStatus(client, parameters) { if (!isHex(parameters.id)) { throw new InvalidParameterError({ param: "id" }); } let receipt; try { receipt = await getTransactionReceipt(client, { hash: parameters.id, }); } catch (error) { if (error instanceof TransactionReceiptNotFoundError) { receipt = undefined; } else { throw error; } } const [status, statusCode] = (() => { if (!receipt) return ["pending", 100]; if (receipt.status === "success") return ["success", 200]; if (receipt.status === "reverted") return ["failure", 500]; return [undefined, 400]; })(); return { atomic: true, chainId: client.chain.id, receipts: receipt ? [receipt] : undefined, status: status, id: parameters.id, statusCode, version: "2.0.0", }; } //# sourceMappingURL=getCallsStatus.js.map