UNPKG

chaingate

Version:

Multi-chain cryptocurrency SDK for TypeScript — unified API for Bitcoin, Ethereum, Litecoin, Dogecoin, Bitcoin Cash, Polygon, Arbitrum, and any EVM-compatible chain. Create wallets, query balances, send transactions, and manage tokens and NFTs across UTXO

113 lines (112 loc) 4.12 kB
import type { EvmExplorer } from '../../Explorer/EvmExplorer'; import { BaseEvmTransaction } from './BaseEvmTransaction'; import type { SignableTxParams } from './BaseEvmTransaction'; import { BroadcastedEvmTransaction } from './BroadcastedEvmTransaction'; /** Fee tier names. */ export type EvmFeeTier = 'low' | 'normal' | 'high' | 'maximum'; /** EIP-1559 fee parameters in wei. */ export interface EvmFee { /** Max fee per gas (base fee cap + tip) in wei. */ maxFeePerGas: bigint; /** Max priority fee per gas (tip) in wei. */ maxPriorityFeePerGas: bigint; /** Gas limit override. When omitted the auto-estimated value is kept. */ gasLimit?: bigint; } /** A recommended fee tier with estimated confirmation time and balance check. */ export interface EvmRecommendedFee extends EvmFee { /** Estimated seconds until confirmation. */ estimatedConfirmationSecs: number; /** Whether the wallet has enough funds to cover the transfer amount plus this fee. */ enoughFunds: boolean; /** Additional wei needed when `enoughFunds` is `false`. */ missingFunds?: bigint; /** `true` when on-chain gas estimation failed and a heuristic was used instead. */ gasEstimationFailed?: boolean; } /** All recommended fee tiers. */ export interface EvmRecommendedFees { low: EvmRecommendedFee; normal: EvmRecommendedFee; high: EvmRecommendedFee; maximum: EvmRecommendedFee; } /** * An unsigned EVM transaction prepared by {@link EvmConnector.transfer}. * * @example * ```ts * const amount = cg.networks.ethereum.amount('0.1'); * const tx = await eth.transfer(amount, '0xRecipient...'); * * // Inspect recommended fees * const fees = tx.recommendedFees(); * console.log(fees.normal.maxFeePerGas); * * // Override with a specific tier * tx.setFee(fees.high); * * // Or set a manual fee with optional gas limit override * tx.setFee({ maxFeePerGas: 30_000_000_000n, maxPriorityFeePerGas: 2_000_000_000n, gasLimit: 50_000n }); * * // Sign and broadcast * const broadcasted = await tx.signAndBroadcast(); * console.log(broadcasted.transactionId); * * // Wait for confirmation * const cancel = broadcasted.onConfirmed((details) => { * console.log('Confirmed in block', details.blockHeight); * }); * * // Stop waiting at any time: * cancel(); * ``` */ export declare class EvmTransaction extends BaseEvmTransaction<BroadcastedEvmTransaction> { private readonly explorer; private readonly feeRates; /** @internal */ constructor(params: { explorer: EvmExplorer; fromAddress: string; toAddress: string; valueWei: bigint; data: string; nonce: bigint; gasLimit: bigint; chainId: bigint; balanceWei: bigint; feeRates: EvmRecommendedFees; getPrivateKey: () => Promise<Uint8Array>; }); /** * Returns all recommended fee tiers (low, normal, high, maximum). * * Each tier includes `maxFeePerGas`, `maxPriorityFeePerGas` (both in wei), * and `estimatedConfirmationSecs`. */ recommendedFees(): EvmRecommendedFees; /** * Sets the fee for this transaction. * * Pass a tier object from {@link recommendedFees} or an object with manual * `maxFeePerGas`, `maxPriorityFeePerGas` (in wei), and an optional * `gasLimit` override. * * @throws {@link TransactionAlreadySentError} if the transaction has already been sent. */ setFee(fee: EvmRecommendedFee | EvmFee): void; protected signTransaction(privateKey: Uint8Array, params: SignableTxParams): string; protected broadcast(signedRaw: string): Promise<string>; protected recordNonceUsed(): void; protected buildBroadcasted(transactionId: string): BroadcastedEvmTransaction; /** @internal — used by EvmConnector.transfer to build the transaction. */ static create(params: { explorer: EvmExplorer; fromAddress: string; toAddress: string; valueWei: bigint; data?: string; getPrivateKey: () => Promise<Uint8Array>; }): Promise<EvmTransaction>; }