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
81 lines (80 loc) • 3.02 kB
TypeScript
/** Fee parameters in wei. */
export interface BaseEvmFee {
/** Max fee per gas in wei (EIP-1559) or gas price in wei (legacy). */
maxFeePerGas: bigint;
/** Max priority fee per gas in wei (EIP-1559 only, ignored for legacy). */
maxPriorityFeePerGas: bigint;
/** Optional gas limit override. When omitted the auto-estimated value is kept. */
gasLimit?: bigint;
}
/** Normalized parameters passed to {@link BaseEvmTransaction.signTransaction}. */
export interface SignableTxParams {
chainId: bigint;
nonce: bigint;
/** Max fee per gas (EIP-1559) or gas price (legacy). */
maxFeePerGas: bigint;
/** Max priority fee per gas. Ignored by legacy signers. */
maxPriorityFeePerGas: bigint;
gasLimit: bigint;
to: string;
value: bigint;
data: string;
}
/** Shared base for unsigned EVM transactions. */
export declare abstract class BaseEvmTransaction<TBroadcasted> {
protected readonly fromAddress: string;
protected readonly toAddress: string;
protected readonly valueWei: bigint;
protected readonly data: string;
protected readonly nonce: bigint;
protected gasLimit: bigint;
protected readonly chainId: bigint;
protected readonly balanceWei: bigint;
protected readonly getPrivateKey: () => Promise<Uint8Array>;
protected _currentFee: {
maxFeePerGas: bigint;
maxPriorityFeePerGas: bigint;
};
protected sent: boolean;
/** @internal */
protected constructor(params: {
fromAddress: string;
toAddress: string;
valueWei: bigint;
data: string;
nonce: bigint;
gasLimit: bigint;
chainId: bigint;
balanceWei: bigint;
getPrivateKey: () => Promise<Uint8Array>;
initialFee: {
maxFeePerGas: bigint;
maxPriorityFeePerGas: bigint;
};
});
/** Returns whether the wallet has enough funds for value + fee at the current gas limit. */
enoughFunds(): boolean;
/**
* Applies a fee override to this transaction.
*
* @throws {@link TransactionAlreadySentError} if the transaction has already been sent.
* @internal
*/
protected applyFee(fee: BaseEvmFee): void;
/**
* Signs the transaction with the wallet's private key and broadcasts it.
*
* @returns A subclass-specific `Broadcasted*Transaction` that tracks confirmation.
* @throws {@link TransactionAlreadySentError} if the transaction has already been sent.
* @throws {@link NotEnoughFundsError} if the wallet does not have enough funds.
*/
signAndBroadcast(): Promise<TBroadcasted>;
/** @internal */
protected abstract signTransaction(privateKey: Uint8Array, params: SignableTxParams): string;
/** @internal */
protected abstract broadcast(signedRaw: string): Promise<string>;
/** @internal */
protected abstract recordNonceUsed(): void;
/** @internal */
protected abstract buildBroadcasted(transactionId: string): TBroadcasted;
}