import { Contract, ethers } from 'ethers'; import Web3 from 'web3'; import { HttpProviderOptions } from 'web3-core-helpers'; import { BlockTransactionString, Transaction, TransactionReceipt } from 'web3-eth'; import { Interfaces, Models } from '@open-rights-exchange/chain-js'; import { EthereumAddress, EthereumBlockNumber, EthereumChainEndpoint, EthereumChainInfo, EthereumChainSettings, EthereumSymbol, EthereumTxResult } from './models'; export declare class EthereumChainState implements Interfaces.ChainState { private ethChainInfo; private _activeEndpoint; private _chainInfo; private _chainSettings; private _endpoints; private _isConnected; private _web3; constructor(endpoints: EthereumChainEndpoint[], settings?: EthereumChainSettings); /** Return chain URL endpoints */ get activeEndpoint(): EthereumChainEndpoint; /** * Return chain ID */ get chainId(): string; /** Return chain info - e.g. head block number */ get chainInfo(): EthereumChainInfo; /** Return chain settings */ get chainSettings(): EthereumChainSettings; /** Return chain URL endpoints */ get endpoints(): EthereumChainEndpoint[]; /** Whether any information has been retrieved from the chain yet * A value here confirms that the network is working * */ get isConnected(): boolean; /** * Connect to chain endpoint to verify that it is operational and to get latest block info */ connect(): Promise; get ethersJsonRpcProvider(): ethers.providers.JsonRpcProvider; /** Map endpoint options to web3 HttpProviderOptions type */ mapOptionsToWeb3HttpProviderOptions(endpoint: EthereumChainEndpoint): HttpProviderOptions; /** Retrieve lastest chain info including head block number and time */ getChainInfo(): Promise; /** Choose the best Chain endpoint based on health and response time */ private selectEndpoint; /** Retrieve a specific block from the chain */ getBlock(blockNumber: EthereumBlockNumber): Promise; /** Retrieve a the current price of gas from the chain in units of Wei */ getCurrentGasPriceFromChain(): Promise; /** return (string) of the last retrieved gas price - rounded up to GWEI */ get currentGasPriceInGwei(): string; /** return (string) of the last retrieved gas price in WEI */ get currentGasPriceInWei(): string; /** Confirm that we've connected to the chain - throw if not */ assertIsConnected(): void; /** Get transaction count for an address * Useful to calculate transaction nonce propery */ getTransactionCount(address: EthereumAddress, defaultBlock: EthereumBlockNumber): Promise; /** Fetches data from a contract table */ fetchContractData(): Promise; /** Fetches data from a contract table */ fetchContractTable(): Promise; /** Get the balance for an account from the chain * If tokenAddress is provided, returns balance for ERC20 token * If symbol = 'eth', returns Eth balance (in units of Ether) * Returns a string representation of the value to accomodate large numbers */ fetchBalance(account: EthereumAddress, symbol: EthereumSymbol, tokenAddress?: EthereumAddress): Promise<{ balance: string; }>; /** Utilizes native web3 method to get ETH token balance for an account (in Ether) */ getEthBalance(address: EthereumAddress): Promise; /** Retrieve account balance and other info from ERC20 contract */ getErc20TokenBalance(contract: Contract, account: EthereumAddress): Promise<{ balance: string; tokenName?: string; tokenSymbol?: string; }>; /** Whether a callable method exists on an ethereum contract */ isMethodCallable(contract: Contract, methodName: string): boolean; /** Return a transaction if its included in a block */ findBlockInTransaction: (block: BlockTransactionString, transactionId: string) => Promise; /** Submits the transaction to the chain and waits only until it gets a transaction hash * Does not wait for the transaction to be finalized on the chain */ sendTransactionWithoutWaitingForConfirm(signedTransaction: string): Promise; /** Retrieve the default settings for chain communications */ static get defaultCommunicationSettings(): { blocksToCheck: number; checkInterval: number; getBlockAttempts: number; }; /** Broadcast a signed transaction to the chain /* if ConfirmType.None, returns the transaction hash without waiting for further tx receipt /* if ConfirmType.After001, waits for the transaction to finalize on chain and then returns the tx receipt */ sendTransaction(signedTransaction: string, waitForConfirm?: Models.ConfirmType, communicationSettings?: Models.ChainSettingsCommunicationSettings): Promise; private awaitTransaction; /** While processing awaitTransaction, check if we've reached our limits to wait * Otherwise, schedule next check */ private checkIfAwaitConditionsReached; /** block has reached the confirmation level requested */ hasReachedConfirmLevel: (transactionBlockNumber: number, waitForConfirm: Models.ConfirmType) => Promise; /** Gets transaction receipt for an executed transaction (by transaction hash) */ getExecutedTransactionById(id: string): Promise; /** Gets an executed or pending transaction (by transaction hash) * Throws if transaction is not on chain */ fetchTransaction(transactionId: string): Promise<{ status: Models.TransactionStatus; transaction: Transaction; }>; /** Return instance of Web3js API */ get web3(): Web3; }