UNPKG

@abstraxn/relayer

Version:

Abstraxn Relayer package for handling gas-less transactions, facilitating smart contract interactions, and relaying user transactions efficiently.

90 lines (89 loc) 2.41 kB
import { ChainId } from "@abstraxn/core-types"; import { BytesLike, Interface, InterfaceAbi, JsonRpcError, Provider, Signer, TransactionReceipt } from "ethers"; export interface RelayerConfig { relayerUrl: string; chainId: ChainId; signer: Signer; provider: Provider; webSocket?: WebSocketConfig; } export type BuildRelayerTxParams<T extends any[] = any[]> = { contractAddress: string; abi: Interface | InterfaceAbi; method: string; args: T; }; export type BuildRelayerTxResponse = { userAddress: string; functionSignature: BytesLike; signature: BytesLike; data: BytesLike; chainId: ChainId; contractAddress: string; }; export type SendRelayerTxParams = { userAddress: string; functionSignature: BytesLike; signature: BytesLike; chainId: ChainId; contractAddress: string; }; export type RelayerResponse = { message: string; transactionId: string; }; export type SendRelayerResponse = { jsonrpc: string; id: number; message: string; result: string; error?: JsonRpcError; }; export type RelayerTxStatus = { state: string; transactionHash?: string; txReceipt?: TransactionReceipt; }; export type GetRelayerTxStatusResponse = { jsonrpc: string; id: number; result: RelayerTxStatus; error?: JsonRpcError; }; export interface TransactionStatusUpdate { txId: string; status: 'initiated' | 'pending' | 'confirmed' | 'failed' | 'rejected'; hash?: string; blockHash?: string; blockNumber?: number; receipt?: any; reason?: string; timestamp: string; gasUsed?: string; effectiveGasPrice?: string; } export interface TransactionCreatedEvent { txId: string; status: 'initiated'; chainId: ChainId; to: string; timestamp: string; message: string; } export interface WebSocketConfig { enabled?: boolean; autoConnect?: boolean; reconnection?: boolean; timeout?: number; } export interface RelayerWebSocketEvents { onTransactionUpdate?: (update: TransactionStatusUpdate) => void; onTransactionCreated?: (event: TransactionCreatedEvent) => void; onConnect?: () => void; onDisconnect?: () => void; onError?: (error: Error) => void; } export interface SendRelayerTxWithWebSocketParams extends SendRelayerTxParams { enableRealTimeUpdates?: boolean; webSocketEvents?: RelayerWebSocketEvents; }