UNPKG

web3-eth

Version:

Web3 module to interact with the Ethereum blockchain and smart contracts.

914 lines 118 kB
import { SupportedProviders, Address, Bytes, FeeData, Filter, HexString32Bytes, HexString8Bytes, Numbers, BlockNumberOrTag, Transaction, TransactionCall, Web3EthExecutionAPI, TransactionWithFromLocalWalletIndex, TransactionWithToLocalWalletIndex, TransactionWithFromAndToLocalWalletIndex, TransactionForAccessList, DataFormat, DEFAULT_RETURN_FORMAT, Eip712TypedData, FilterParams } from 'web3-types'; import { Web3Context, Web3ContextInitOptions } from 'web3-core'; import { SendTransactionOptions, TransactionMiddleware } from './types.js'; import { LogsSubscription, NewPendingTransactionsSubscription, NewHeadsSubscription, SyncingSubscription } from './web3_subscriptions.js'; export type RegisteredSubscription = { logs: typeof LogsSubscription; newPendingTransactions: typeof NewPendingTransactionsSubscription; pendingTransactions: typeof NewPendingTransactionsSubscription; newHeads: typeof NewHeadsSubscription; newBlockHeaders: typeof NewHeadsSubscription; syncing: typeof SyncingSubscription; }; export declare const registeredSubscriptions: { logs: typeof LogsSubscription; newPendingTransactions: typeof NewPendingTransactionsSubscription; newHeads: typeof NewHeadsSubscription; syncing: typeof SyncingSubscription; pendingTransactions: typeof NewPendingTransactionsSubscription; newBlockHeaders: typeof NewHeadsSubscription; }; /** * * The Web3Eth allows you to interact with an Ethereum blockchain. * * For using Web3 Eth functions, first install Web3 package using `npm i web3` or `yarn add web3` based on your package manager usage. * After that, Web3 Eth functions will be available as mentioned in following snippet. * ```ts * import { Web3 } from 'web3'; * const web3 = new Web3('https://mainnet.infura.io/v3/<YOURPROJID>'); * * const block = await web3.eth.getBlock(0); * * ``` * * For using individual package install `web3-eth` package using `npm i web3-eth` or `yarn add web3-eth` and only import required functions. * This is more efficient approach for building lightweight applications. * ```ts * import { Web3Eth } from 'web3-eth'; * * const eth = new Web3Eth('https://mainnet.infura.io/v3/<YOURPROJID>'); * const block = await eth.getBlock(0); * * ``` */ export declare class Web3Eth extends Web3Context<Web3EthExecutionAPI, RegisteredSubscription> { private transactionMiddleware?; constructor(providerOrContext?: SupportedProviders<any> | Web3ContextInitOptions | string); setTransactionMiddleware(transactionMiddleware: TransactionMiddleware): void; getTransactionMiddleware(): TransactionMiddleware | undefined; /** * @returns Returns the ethereum protocol version of the node. * * ```ts * web3.eth.getProtocolVersion().then(console.log); * > "63" * ``` */ getProtocolVersion(): Promise<string>; /** * Checks if the node is currently syncing. * * @returns Either a {@link SyncingStatusAPI}, or `false`. * * ```ts * web3.eth.isSyncing().then(console.log); * > { * startingBlock: 100, * currentBlock: 312, * highestBlock: 512, * knownStates: 234566, * pulledStates: 123455 * } * ``` */ isSyncing(): Promise<import("web3-types").SyncingStatusAPI>; /** * @returns Returns the coinbase address to which mining rewards will go. * * ```ts * web3.eth.getCoinbase().then(console.log); * > "0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe" * ``` */ getCoinbase(): Promise<string>; /** * Checks whether the node is mining or not. * * @returns `true` if the node is mining, otherwise `false`. * * ```ts * web3.eth.isMining().then(console.log); * > true * ``` */ isMining(): Promise<boolean>; /** * @deprecated Will be removed in the future, please use {@link Web3Eth.getHashRate} method instead. * * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The number of hashes per second that the node is mining with. * * ```ts * web3.eth.getHashrate().then(console.log); * > 493736n * * web3.eth.getHashrate({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log); * > "0x788a8" * ``` */ getHashrate<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(returnFormat?: ReturnFormat): Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>; /** * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The number of hashes per second that the node is mining with. * * ```ts * web3.eth.getHashRate().then(console.log); * > 493736n * * web3.eth.getHashRate({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log); * > "0x788a8" * ``` */ getHashRate<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(returnFormat?: ReturnFormat): Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>; /** * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The gas price determined by the last few blocks median gas price. * * ```ts * web3.eth.getGasPrice().then(console.log); * > 20000000000n * * web3.eth.getGasPrice({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log); * > "0x4a817c800" * ``` */ getGasPrice<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(returnFormat?: ReturnFormat): Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>; /** * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns the current maxPriorityFeePerGas per gas in wei. * * ```ts * web3.eth.getMaxPriorityFeePerGas().then(console.log); * > 20000000000n * * web3.eth.getMaxPriorityFeePerGas({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log); * > "0x4a817c800" * ``` */ getMaxPriorityFeePerGas<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(returnFormat?: ReturnFormat): Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>; /** * Calculates the current Fee Data. * If the node supports EIP-1559, then `baseFeePerGas` and `maxPriorityFeePerGas` will be returned along with the calculated `maxFeePerGas` value. * `maxFeePerGas` is calculated as `baseFeePerGas` * `baseFeePerGasFactor` + `maxPriorityFeePerGas`. * If the node does not support EIP-1559, then the `gasPrice` will be returned and the other values will be undefined. * * @param baseFeePerGasFactor (optional) The factor to multiply the `baseFeePerGas` with when calculating `maxFeePerGas`, if the node supports EIP-1559. This can be a `bigint` for precise calculation or a `number` to support decimals. The default value is 2 (BigInt). * If a `number` is provided, it will be converted to `bigint` with three decimal precision. * @param alternativeMaxPriorityFeePerGas (optional) The alternative `maxPriorityFeePerGas` to use when calculating `maxFeePerGas`, if the node supports EIP-1559 but does not support the method `eth_maxPriorityFeePerGas`. The default value is 1 gwei. * @returns The current fee data. * * @example * web3.eth.calculateFeeData().then(console.log); * > { * gasPrice: 20000000000n, * maxFeePerGas: 60000000000n, * maxPriorityFeePerGas: 20000000000n, * baseFeePerGas: 20000000000n * } * * @example * // Using a `bigint` for baseFeePerGasFactor * web3.eth.calculateFeeData(1n).then(console.log); * > { * gasPrice: 20000000000n, * maxFeePerGas: 40000000000n, * maxPriorityFeePerGas: 20000000000n, * baseFeePerGas: 20000000000n * } * * @example * // Using a `number` for baseFeePerGasFactor (with decimals) * web3.eth.calculateFeeData(1.5).then(console.log); * > { * gasPrice: 20000000000n, * maxFeePerGas: 50000000000n, // baseFeePerGasFactor is converted to BigInt(1.500) * maxPriorityFeePerGas: 20000000000n, * baseFeePerGas: 20000000000n * } * * @example * web3.eth.calculateFeeData(3n).then(console.log); * > { * gasPrice: 20000000000n, * maxFeePerGas: 80000000000n, * maxPriorityFeePerGas: 20000000000n, * baseFeePerGas: 20000000000n * } */ calculateFeeData(baseFeePerGasFactor?: bigint | number, alternativeMaxPriorityFeePerGas?: bigint): Promise<FeeData>; getFeeData: (baseFeePerGasFactor?: bigint | number, alternativeMaxPriorityFeePerGas?: bigint) => Promise<FeeData>; /** * @returns A list of accounts the node controls (addresses are checksummed). * * ```ts * web3.eth.getAccounts().then(console.log); * > ["0x11f4d0A3c12e86B4b5F39B213F7E19D048276DAe", "0xDCc6960376d6C6dEa93647383FfB245CfCed97Cf"] * ``` */ getAccounts(): Promise<string[]>; /** * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The current block number. * * ```ts * web3.eth.getBlockNumber().then(console.log); * > 2744n * * web3.eth.getBlockNumber({ number: FMT_NUMBER.HEX , bytes: FMT_BYTES.HEX }).then(console.log); * > "0xab8" * ``` */ getBlockNumber<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(returnFormat?: ReturnFormat): Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>; /** * Get the balance of an address at a given block. * * @param address The address to get the balance of. * @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) Specifies what block to use as the current state for the balance query. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The current balance for the given address in `wei`. * * ```ts * web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log); * > 1000000000000n * * web3.eth.getBalance("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log); * > "0xe8d4a51000" * ``` */ getBalance<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(address: Address, blockNumber?: BlockNumberOrTag, returnFormat?: ReturnFormat): Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>; /** * Get the storage at a specific position of an address. * * @param address The address to get the storage from. * @param storageSlot The index position of the storage. * @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) Specifies what block to use as the current state for the storage query. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The value in storage at the given position. * * ```ts * web3.eth.getStorageAt("0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234", 0).then(console.log); * > "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234" * * web3.eth.getStorageAt( * "0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234", * 0, * undefined, * { number: FMT_NUMBER.HEX , bytes: FMT_BYTES.UINT8ARRAY } * ).then(console.log); * > Uint8Array(31) [ * 3, 52, 86, 115, 33, 35, 255, 255, * 35, 66, 52, 45, 209, 35, 66, 67, * 67, 36, 35, 66, 52, 253, 35, 79, * 210, 63, 212, 242, 61, 66, 52 * ] * ``` */ getStorageAt<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(address: Address, storageSlot: Numbers, blockNumber?: BlockNumberOrTag, returnFormat?: ReturnFormat): Promise<import("web3-types").ByteTypes[ReturnFormat["bytes"]]>; /** * Get the code at a specific address. * * @param address The address to get the code from. * @param blockNumber ({@link BlockNumberOrTag} defaults to {@link Web3Eth.defaultBlock}) Specifies what block to use as the current state for the code query. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The [data](https://ethereum.org/en/developers/docs/transactions/#the-data-field) at the provided `address`. * * ```ts * web3.eth.getCode("0x033456732123ffff2342342dd12342434324234234fd234fd23fd4f23d4234").then(console.log); * > "0x600160008035811a818181146012578301005b601b6001356025565b8060005260206000f25b600060078202905091905056" * * web3.eth.getCode( * "0x407d73d8a49eeb85d32cf465507dd71d507100c1", * undefined, * { number: FMT_NUMBER.HEX , bytes: FMT_BYTES.UINT8ARRAY } * ).then(console.log); * > Uint8Array(50) [ * 96, 1, 96, 0, 128, 53, 129, 26, 129, 129, 129, * 20, 96, 18, 87, 131, 1, 0, 91, 96, 27, 96, * 1, 53, 96, 37, 86, 91, 128, 96, 0, 82, 96, * 32, 96, 0, 242, 91, 96, 0, 96, 7, 130, 2, * 144, 80, 145, 144, 80, 86 * ] * ``` */ getCode<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(address: Address, blockNumber?: BlockNumberOrTag, returnFormat?: ReturnFormat): Promise<import("web3-types").ByteTypes[ReturnFormat["bytes"]]>; /** * Retrieves a {@link Block} matching the provided block number, block hash or block tag. * * @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block. * @param hydrated If specified `true`, the returned block will contain all transactions as objects. If `false` it will only contain transaction hashes. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted (does not format transaction objects or hashes). * @returns A {@link Block} object matching the provided block number or block hash. * * ```ts * web3.eth.getBlock(0).then(console.log); * > { * hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d', * parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', * miner: '0x0000000000000000000000000000000000000000', * stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4', * transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', * receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', * logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', * difficulty: 1n, * number: 0n, * gasLimit: 30000000n, * gasUsed: 0n, * timestamp: 1658281638n, * extraData: '0x', * mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * nonce: 0n, * totalDifficulty: 1n, * baseFeePerGas: 1000000000n, * size: 514n, * transactions: [], * uncles: [] * } * * web3.eth.getBlock( * "0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d", * false, * { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX } * ).then(console.log); * > { * hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d', * parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', * miner: '0x0000000000000000000000000000000000000000', * stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4', * transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', * receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', * logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', * difficulty: 1, * number: 0, * gasLimit: 30000000, * gasUsed: 0, * timestamp: 1658281638, * extraData: '0x', * mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * nonce: 0, * totalDifficulty: 1, * baseFeePerGas: 1000000000, * size: 514, * transactions: [], * uncles: [] * } * ``` */ getBlock<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(block?: HexString32Bytes | BlockNumberOrTag, hydrated?: boolean, returnFormat?: ReturnFormat): Promise<{ transactions: string[] | { readonly blockHash?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; readonly blockNumber?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; readonly from: Address; readonly hash: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly transactionIndex?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; to?: (Address | null) | undefined; value?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; accessList?: { readonly address?: Address | undefined; readonly storageKeys?: HexString32Bytes[] | undefined; }[] | undefined; common?: { customChain: { name?: string | undefined; networkId: import("web3-types").NumberTypes[ReturnFormat["number"]]; chainId: import("web3-types").NumberTypes[ReturnFormat["number"]]; }; baseChain?: import("web3-types").ValidChains | undefined; hardfork?: import("web3-types").Hardfork | undefined; } | undefined; gas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; gasPrice?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; type?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; maxFeePerGas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; maxPriorityFeePerGas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; data?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; input?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; nonce?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; chain?: import("web3-types").ValidChains | undefined; hardfork?: import("web3-types").Hardfork | undefined; chainId?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; networkId?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; gasLimit?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; yParity?: import("web3-types").Uint | undefined; v?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; r?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; s?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; }[]; parentHash: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; sha3Uncles: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; miner: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; stateRoot: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; transactionsRoot: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; receiptsRoot: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; logsBloom?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; difficulty?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; number: import("web3-types").NumberTypes[ReturnFormat["number"]]; gasLimit: import("web3-types").NumberTypes[ReturnFormat["number"]]; gasUsed: import("web3-types").NumberTypes[ReturnFormat["number"]]; timestamp: import("web3-types").NumberTypes[ReturnFormat["number"]]; extraData: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; mixHash: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; nonce: import("web3-types").NumberTypes[ReturnFormat["number"]]; totalDifficulty: import("web3-types").NumberTypes[ReturnFormat["number"]]; baseFeePerGas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; size: import("web3-types").NumberTypes[ReturnFormat["number"]]; uncles: string[]; hash?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; }>; /** * @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The number of transactions in the provided block. * * ```ts * web3.eth.getBlockTransactionCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log); * > 1n * * web3.eth.getBlockTransactionCount( * "0x407d73d8a49eeb85d32cf465507dd71d507100c1", * { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX } * ).then(console.log); * > 1 * ``` */ getBlockTransactionCount<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(block?: HexString32Bytes | BlockNumberOrTag, returnFormat?: ReturnFormat): Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>; /** * @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The number of [uncles](https://ethereum.org/en/glossary/#ommer) in the provided block. * * ```ts * web3.eth.getBlockUncleCount("0x407d73d8a49eeb85d32cf465507dd71d507100c1").then(console.log); * > 1n * * web3.eth.getBlockUncleCount( * "0x407d73d8a49eeb85d32cf465507dd71d507100c1", * { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX } * ).then(console.log); * > 1 * ``` */ getBlockUncleCount<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(block?: HexString32Bytes | BlockNumberOrTag, returnFormat?: ReturnFormat): Promise<import("web3-types").NumberTypes[ReturnFormat["number"]]>; /** * * @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block. * @param uncleIndex The index position of the uncle. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns A blocks [uncle](https://ethereum.org/en/glossary/#ommer) by a given uncle index position. * * ```ts * web3.eth.getUncle(0, 1).then(console.log); * > { * hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d', * parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', * miner: '0x0000000000000000000000000000000000000000', * stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4', * transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', * receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', * logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', * difficulty: 1n, * number: 0n, * gasLimit: 30000000n, * gasUsed: 0n, * timestamp: 1658281638n, * extraData: '0x', * mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * nonce: 0n, * totalDifficulty: 1n, * baseFeePerGas: 1000000000n, * size: 514n, * transactions: [], * uncles: [] * } * * web3.eth.getUncle( * "0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d", * 1, * { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX } * ).then(console.log); * > { * hash: '0x7dbfdc6a7a67a670cb9b0c3f81ca60c007762f1e4e598cb027a470678ff26d0d', * parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * sha3Uncles: '0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347', * miner: '0x0000000000000000000000000000000000000000', * stateRoot: '0x5ed9882897d363c4632a6e67fba6203df61bd994813dcf048da59be442a9c6c4', * transactionsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', * receiptsRoot: '0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421', * logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000', * difficulty: 1, * number: 0, * gasLimit: 30000000, * gasUsed: 0, * timestamp: 1658281638, * extraData: '0x', * mixHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * nonce: 0, * totalDifficulty: 1, * baseFeePerGas: 1000000000, * size: 514, * transactions: [], * uncles: [] * } * ``` */ getUncle<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(block: (HexString32Bytes | BlockNumberOrTag) | undefined, uncleIndex: Numbers, returnFormat?: ReturnFormat): Promise<{ readonly parentHash: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly sha3Uncles: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly miner: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly stateRoot: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly transactionsRoot: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly receiptsRoot: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly logsBloom?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; readonly difficulty?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; readonly number: import("web3-types").NumberTypes[ReturnFormat["number"]]; readonly gasLimit: import("web3-types").NumberTypes[ReturnFormat["number"]]; readonly gasUsed: import("web3-types").NumberTypes[ReturnFormat["number"]]; readonly timestamp: import("web3-types").NumberTypes[ReturnFormat["number"]]; readonly extraData: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly mixHash: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly nonce: import("web3-types").NumberTypes[ReturnFormat["number"]]; readonly totalDifficulty: import("web3-types").NumberTypes[ReturnFormat["number"]]; readonly baseFeePerGas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; readonly size: import("web3-types").NumberTypes[ReturnFormat["number"]]; readonly transactions: string[] | { readonly blockHash?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; readonly blockNumber?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; readonly from: Address; readonly hash: import("web3-types").ByteTypes[ReturnFormat["bytes"]]; readonly transactionIndex?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; to?: (Address | null) | undefined; value?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; accessList?: { readonly address?: Address | undefined; readonly storageKeys?: HexString32Bytes[] | undefined; }[] | undefined; common?: { customChain: { name?: string | undefined; networkId: import("web3-types").NumberTypes[ReturnFormat["number"]]; chainId: import("web3-types").NumberTypes[ReturnFormat["number"]]; }; baseChain?: import("web3-types").ValidChains | undefined; hardfork?: import("web3-types").Hardfork | undefined; } | undefined; gas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; gasPrice?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; type?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; maxFeePerGas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; maxPriorityFeePerGas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; data?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; input?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; nonce?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; chain?: import("web3-types").ValidChains | undefined; hardfork?: import("web3-types").Hardfork | undefined; chainId?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; networkId?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; gasLimit?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; yParity?: import("web3-types").Uint | undefined; v?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; r?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; s?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; }[]; readonly uncles: string[]; readonly hash?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; }>; /** * @param transactionHash The hash of the desired transaction. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The desired transaction object. * * ```ts * web3.eth.getTransaction('0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc').then(console.log); * { * hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc', * type: 0n, * nonce: 0n, * blockHash: '0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00', * blockNumber: 1n, * transactionIndex: 0n, * from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', * to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c', * value: 1n, * gas: 90000n, * gasPrice: 2000000000n, * input: '0x', * v: 2709n, * r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c', * s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d' * } * * web3.eth.getTransaction( * web3.utils.hexToBytes("0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400"), * { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX } * ).then(console.log); * { * hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc', * type: 0, * nonce: 0, * blockHash: '0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00', * blockNumber: 1, * transactionIndex: 0, * from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', * to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c', * value: 1, * gas: 90000, * gasPrice: 2000000000, * input: '0x', * v: 2709, * r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c', * s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d' * } * ``` */ getTransaction<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(transactionHash: Bytes, returnFormat?: ReturnFormat): Promise<{ readonly yParity: import("web3-types").Uint; readonly r: import("web3-types").Uint; readonly s: import("web3-types").Uint; readonly v?: never | undefined; readonly maxFeePerGas: import("web3-types").Uint; readonly maxPriorityFeePerGas: import("web3-types").Uint; readonly accessList: { readonly address?: Address | undefined; readonly storageKeys?: HexString32Bytes[] | undefined; }[]; readonly gasPrice: import("web3-types").Uint; readonly to?: (Address | null) | undefined; readonly type: import("web3-types").HexStringSingleByte; readonly nonce: import("web3-types").Uint; readonly gas: import("web3-types").Uint; readonly value: import("web3-types").Uint; readonly input: import("web3-types").HexStringBytes; readonly data?: import("web3-types").HexStringBytes | undefined; readonly chainId?: import("web3-types").Uint | undefined; readonly hash: HexString32Bytes; readonly blockHash?: HexString32Bytes | undefined; readonly blockNumber?: import("web3-types").Uint | undefined; readonly from: Address; readonly transactionIndex?: import("web3-types").Uint | undefined; } | { readonly yParity: import("web3-types").Uint; readonly r: import("web3-types").Uint; readonly s: import("web3-types").Uint; readonly v?: never | undefined; readonly gasPrice: import("web3-types").Uint; readonly accessList: { readonly address?: Address | undefined; readonly storageKeys?: HexString32Bytes[] | undefined; }[]; readonly maxFeePerGas?: never | undefined; readonly maxPriorityFeePerGas?: never | undefined; readonly to?: (Address | null) | undefined; readonly type: import("web3-types").HexStringSingleByte; readonly nonce: import("web3-types").Uint; readonly gas: import("web3-types").Uint; readonly value: import("web3-types").Uint; readonly input: import("web3-types").HexStringBytes; readonly data?: import("web3-types").HexStringBytes | undefined; readonly chainId?: import("web3-types").Uint | undefined; readonly hash: HexString32Bytes; readonly blockHash?: HexString32Bytes | undefined; readonly blockNumber?: import("web3-types").Uint | undefined; readonly from: Address; readonly transactionIndex?: import("web3-types").Uint | undefined; } | { readonly v: import("web3-types").Uint; readonly r: import("web3-types").Uint; readonly s: import("web3-types").Uint; readonly gasPrice: import("web3-types").Uint; readonly accessList?: never | undefined; readonly maxFeePerGas?: never | undefined; readonly maxPriorityFeePerGas?: never | undefined; readonly to?: (Address | null) | undefined; readonly type: import("web3-types").HexStringSingleByte; readonly nonce: import("web3-types").Uint; readonly gas: import("web3-types").Uint; readonly value: import("web3-types").Uint; readonly input: import("web3-types").HexStringBytes; readonly data?: import("web3-types").HexStringBytes | undefined; readonly chainId?: import("web3-types").Uint | undefined; readonly hash: HexString32Bytes; readonly blockHash?: HexString32Bytes | undefined; readonly blockNumber?: import("web3-types").Uint | undefined; readonly from: Address; readonly transactionIndex?: import("web3-types").Uint | undefined; }>; /** * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns A list of pending transactions. * * ```ts * web3.eth.getPendingTransactions().then(console.log); * > [ * { * hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc', * type: 0n, * nonce: 0n, * blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * blockNumber: null, * transactionIndex: 0n, * from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', * to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c', * value: 1n, * gas: 90000n, * gasPrice: 2000000000n, * input: '0x', * v: 2709n, * r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c', * s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d' * }, * { * hash: '0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f', * type: 0n, * nonce: 1n, * blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * blockNumber: null, * transactionIndex: 0n, * from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', * to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c', * value: 1n, * gas: 90000n, * gasPrice: 2000000000n, * input: '0x', * v: 2710n, * r: '0x55ac19fade21db035a1b7ea0a8d49e265e05dbb926e75f273f836ad67ce5c96a', * s: '0x6550036a7c3fd426d5c3d35d96a7075cd673957620b7889846a980d2d017ec08' * } * ] * * * web3.eth.getPendingTransactions({ number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX }).then(console.log); * > [ * { * hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc', * type: 0, * nonce: 0, * blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * blockNumber: null, * transactionIndex: 0, * from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', * to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c', * value: 1, * gas: 90000, * gasPrice: 2000000000, * input: '0x', * v: 2709, * r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c', * s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d' * }, * { * hash: '0xdf7756865c2056ce34c4eabe4eff42ad251a9f920a1c620c00b4ea0988731d3f', * type: 0, * nonce: 1, * blockHash: '0x0000000000000000000000000000000000000000000000000000000000000000', * blockNumber: null, * transactionIndex: 0, * from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', * to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c', * value: 1, * gas: 90000, * gasPrice: 2000000000, * input: '0x', * v: 2710, * r: '0x55ac19fade21db035a1b7ea0a8d49e265e05dbb926e75f273f836ad67ce5c96a', * s: '0x6550036a7c3fd426d5c3d35d96a7075cd673957620b7889846a980d2d017ec08' * } * ] * ``` */ getPendingTransactions<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(returnFormat?: ReturnFormat): Promise<{ from?: Address | undefined; to?: (Address | null) | undefined; value?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; accessList?: { readonly address?: Address | undefined; readonly storageKeys?: HexString32Bytes[] | undefined; }[] | undefined; common?: { customChain: { name?: string | undefined; networkId: import("web3-types").NumberTypes[ReturnFormat["number"]]; chainId: import("web3-types").NumberTypes[ReturnFormat["number"]]; }; baseChain?: import("web3-types").ValidChains | undefined; hardfork?: import("web3-types").Hardfork | undefined; } | undefined; gas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; gasPrice?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; type?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; maxFeePerGas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; maxPriorityFeePerGas?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; data?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; input?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; nonce?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; chain?: import("web3-types").ValidChains | undefined; hardfork?: import("web3-types").Hardfork | undefined; chainId?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; networkId?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; gasLimit?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; yParity?: import("web3-types").Uint | undefined; v?: import("web3-types").NumberTypes[ReturnFormat["number"]] | undefined; r?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; s?: import("web3-types").ByteTypes[ReturnFormat["bytes"]] | undefined; }[]>; /** * @param block The {@link BlockNumberOrTag} (defaults to {@link Web3Eth.defaultBlock}) or block hash of the desired block. * @param transactionIndex The index position of the transaction. * @param returnFormat ({@link DataFormat} defaults to {@link DEFAULT_RETURN_FORMAT}) Specifies how the return data should be formatted. * @returns The desired transaction object. * * ```ts * web3.eth.getTransactionFromBlock('0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00', 0).then(console.log); * { * hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc', * type: 0n, * nonce: 0n, * blockHash: '0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00', * blockNumber: 1n, * transactionIndex: 0n, * from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', * to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c', * value: 1n, * gas: 90000n, * gasPrice: 2000000000n, * input: '0x', * v: 2709n, * r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c', * s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d' * } * * web3.eth.getTransactionFromBlock( * hexToBytes("0x30755ed65396facf86c53e6217c52b4daebe72aa4941d89635409de4c9c7f9466d4e9aaec7977f05e923889b33c0d0dd27d7226b6e6f56ce737465c5cfd04be400"), * 0, * { number: FMT_NUMBER.NUMBER , bytes: FMT_BYTES.HEX } * ).then(console.log); * { * hash: '0x73aea70e969941f23f9d24103e91aa1f55c7964eb13daf1c9360c308a72686dc', * type: 0, * nonce: 0, * blockHash: '0x43202bd16b6bd54bea1b310736bd78bdbe93a64ad940f7586739d9eb25ad8d00', * blockNumber: 1, * transactionIndex: 0, * from: '0x6e599da0bff7a6598ac1224e4985430bf16458a4', * to: '0x6f1df96865d09d21e8f3f9a7fba3b17a11c7c53c', * value: 1, * gas: 90000, * gasPrice: 2000000000, * input: '0x', * v: 2709, * r: '0x8b336c290f6d7b2af3ccb2c02203a8356cc7d5b150ab19cce549d55636a3a78c', * s: '0x5a83c6f816befc5cd4b0c997a347224a8aa002e5799c4b082a3ec726d0e9531d' * } * ``` */ getTransactionFromBlock<ReturnFormat extends DataFormat = typeof DEFAULT_RETURN_FORMAT>(block: (HexString32Bytes | BlockNumberOrTag) | undefined, transactionIndex: Numbers, returnFormat?: ReturnFormat): Promise<{ readonly yParity: import("web3-types").Uint; readonly r: import("web3-types").Uint; readonly s: import("web3-types").Uint; readonly v?: never | undefined; readonly maxFeePerGas: import("web3-types").Uint; readonly maxPriorityFeePerGas: import("web3-types").Uint; readonly accessList: { readonly address?: Address | undefined; readonly storageKeys?: HexString32Bytes[] | undefined; }[]; readonly gasPrice: import("web3-types").Uint; readonly to?: (Address | null) | undefined; readonly type: import("web3-types").HexStringSingleByte; readonly nonce: import("web3-types").Uint; readonly gas: import("web3-types").Uint; readonly value: import("web3-types").Uint; readonly input: import("web3-types").HexStringBytes; readonly data?: import("web3-types").HexStringBytes | undefined; readonly chainId?: import("web3-types").Uint | undefined; readonly hash: HexString32Bytes; readonly blockHash?: HexString32Bytes | undefined; readonly blockNumber?: import("web3-types").Uint | undefined; readonly from: Address; readonly transactionIndex?: import("web3-types").Uint | undefined; } | { readonly yParity: import("web3-types").Uint; readonly r: import("web3-types").Uint; readonly s: import("web3-types").Uint; readonly v?: never | undefined; readonly gasPrice: import("web3-types").Uint; readonly accessList: { readonly address?: Address | undefined; readonly storageKeys?: HexString32Bytes[] | undefined; }[]; readonly maxFeePerGas?: never | undefined; readonly maxPriorityFeePerGas?: never | undefined; readonly to?: (Address | null) | undefined; readonly type: import("web3-types").HexStringSingleByte; readonly nonce: import("web3-types").Uint; readonly gas: import("web3-types").Uint; readonly value: import("web3-types").Uint; readonly input: import("web3-types").HexStringBytes; readonly data?: import("web3-types").HexStringBytes | undefined; readonly chainId?: import("web3-types").Uint | undefined; readonly hash: HexString32Bytes; readonly blockHash?: HexString32Bytes | undefined; readonly blockNumber?: import("web3-types").Uint | undefined; readonly from: Address; readonly transacti