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
83 lines (82 loc) • 3.14 kB
TypeScript
import type { EvmRpcExplorer, RpcFeeData } from './EvmRpcExplorer';
import { BaseEvmTransaction } from '../EvmConnector/BaseEvmTransaction';
import type { SignableTxParams } from '../EvmConnector/BaseEvmTransaction';
import { BroadcastedEvmRpcTransaction } from './BroadcastedEvmRpcTransaction';
/** Fee parameters in wei for an EVM RPC transaction. */
export interface EvmRpcFee {
/** 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;
/** Gas limit override. When omitted the auto-estimated value is kept. */
gasLimit?: bigint;
}
/**
* An unsigned EVM transaction prepared by {@link EvmRpcConnector.transfer}.
*
* @example
* ```ts
* const network = cg.networks.evmRpc({ rpcUrl: '...', chainId: 56, name: 'BSC', symbol: 'BNB' });
* const conn = cg.connect(network, wallet);
* const tx = await conn.transfer(network.amount('0.1'), '0xRecipient...');
*
* // Inspect the current fee
* const fee = tx.currentFee();
*
* // Override with a custom fee and optional gas limit
* tx.setFee({ maxFeePerGas: 5_000_000_000n, maxPriorityFeePerGas: 1_000_000_000n, gasLimit: 50_000n });
*
* // Sign and broadcast
* const broadcasted = await tx.signAndBroadcast();
* ```
*/
export declare class EvmRpcTransaction extends BaseEvmTransaction<BroadcastedEvmRpcTransaction> {
private readonly explorer;
private readonly supportsEip1559;
/** @internal */
constructor(params: {
explorer: EvmRpcExplorer;
fromAddress: string;
toAddress: string;
valueWei: bigint;
data: string;
nonce: bigint;
gasLimit: bigint;
chainId: bigint;
balanceWei: bigint;
feeData: RpcFeeData;
getPrivateKey: () => Promise<Uint8Array>;
});
/**
* Returns the current fee parameters that will be used for signing.
*
* For EIP-1559 chains both `maxFeePerGas` and `maxPriorityFeePerGas` are
* meaningful. For legacy chains `maxFeePerGas` represents the gas price and
* `maxPriorityFeePerGas` is `0n`.
*/
currentFee(): Readonly<EvmRpcFee>;
/**
* Overrides the fee for this transaction.
*
* @throws {@link TransactionAlreadySentError} if the transaction has already been sent.
*/
setFee(fee: EvmRpcFee): void;
protected signTransaction(privateKey: Uint8Array, params: SignableTxParams): string;
protected broadcast(signedRaw: string): Promise<string>;
protected recordNonceUsed(): void;
protected buildBroadcasted(transactionId: string): BroadcastedEvmRpcTransaction;
/**
* Fetches all required on-chain data (nonce, gas, fees, balance) and
* constructs the transaction.
*
* @internal — used by {@link EvmRpcConnector.transfer}.
*/
static create(params: {
explorer: EvmRpcExplorer;
fromAddress: string;
toAddress: string;
valueWei: bigint;
data?: string;
getPrivateKey: () => Promise<Uint8Array>;
}): Promise<EvmRpcTransaction>;
}