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

50 lines (49 loc) 2.75 kB
import { Connector } from '../Connector'; import type { AddressOptions } from '../Connector'; import type { Wallet } from '../../Wallet/Wallet'; import { Amount } from '../../utils/Amount'; import type { EvmAddressType, AddressTypeConfig } from '../../ChainGate/networks/types'; /** Minimal network descriptor shape required by EVM-style connectors. */ export interface EvmNetworkLike { defaultAddressType: EvmAddressType; addressTypes: Partial<Record<EvmAddressType, AddressTypeConfig>>; publicKeyToAddress(publicKey: Uint8Array): string; toString(): string; } /** Parameters for {@link BaseEvmConnector.createTransaction}. */ export interface CreateEvmTransactionParams { fromAddress: string; toAddress: string; valueWei: bigint; data?: string; getPrivateKey: () => Promise<Uint8Array>; } /** Shared base for EVM-style connectors. */ export declare abstract class BaseEvmConnector<TExplorer, TNetwork extends EvmNetworkLike, TTransaction> extends Connector<Wallet, TExplorer, TNetwork> { protected readonly defaultDerivationPath: string; /** @internal */ constructor(wallet: Wallet, explorer: TExplorer, network: TNetwork); /** * Returns the EVM address for this wallet. * * - **HD wallets** derive at `{derivationPath}/{index}` (defaults to `m/44'/60'/0'/0/0`). * - **Single-key wallets** return the address for the wallet's public key. Only index `0` is valid. * - **XpubWallet** derives at `m/0/{index}`. */ address(options?: AddressOptions): Promise<string>; /** Creates a native coin transfer transaction. */ transfer(amount: Amount, toAddress: string, options?: AddressOptions): Promise<TTransaction>; /** Creates an ERC-721 NFT transfer transaction using `safeTransferFrom`. */ transferNft(contractAddress: string, tokenId: string, toAddress: string, options?: AddressOptions): Promise<TTransaction>; /** Creates an ERC-1155 token transfer transaction using `safeTransferFrom`. */ transferErc1155(contractAddress: string, tokenId: string, amount: bigint, toAddress: string, options?: AddressOptions): Promise<TTransaction>; /** Creates a transaction that calls a smart contract with arbitrary calldata. */ callContract(contractAddress: string, data: string, amount: Amount, options?: AddressOptions): Promise<TTransaction>; /** Subclass hook: returns the chain-specific transaction implementation. */ protected abstract createTransaction(params: CreateEvmTransactionParams): Promise<TTransaction>; /** * Returns a function that extracts the private key from the wallet. * @internal */ protected createPrivateKeyGetter(index: number, derivationPath?: string): () => Promise<Uint8Array>; }