Web3 module to interact with the Ethereum blockchain and smart contracts.
67
The blockchain state access functionality provides comprehensive read access to Ethereum blockchain data including blocks, transactions, accounts, and network state information.
Retrieves a block by hash or number with optional transaction details.
getBlock(blockHashOrBlockNumber?: BlockNumberOrTag, hydrated?: boolean, returnFormat?: DataFormat): Promise<Block>;Parameters:
blockHashOrBlockNumber: Block hash (hex string) or block number/tag ("latest", "earliest", "pending", etc.)hydrated: If true, returns full transaction objects; if false, returns only transaction hashesreturnFormat: Output format configuration for numbers and bytesUsage Example:
// Get latest block with transaction hashes only
const latestBlock = await eth.getBlock("latest");
// Get specific block with full transaction details
const blockWithTxs = await eth.getBlock(15000000, true);
// Get block by hash
const block = await eth.getBlock("0x1234567890abcdef...");Returns the number of the most recent block.
getBlockNumber(returnFormat?: DataFormat): Promise<Numbers>;Usage Example:
const blockNumber = await eth.getBlockNumber();
console.log(`Current block: ${blockNumber}`);Returns the number of transactions in a block.
getBlockTransactionCount(blockHashOrBlockNumber?: BlockNumberOrTag, returnFormat?: DataFormat): Promise<Numbers>;Usage Example:
const txCount = await eth.getBlockTransactionCount("latest");
const txCountByHash = await eth.getBlockTransactionCount("0x1234567890abcdef...");Returns the number of uncles in a block.
getBlockUncleCount(blockHashOrBlockNumber?: BlockNumberOrTag, returnFormat?: DataFormat): Promise<Numbers>;Returns an uncle block by block hash/number and uncle index.
getUncle(blockHashOrBlockNumber?: BlockNumberOrTag, uncleIndex?: Numbers, returnFormat?: DataFormat): Promise<Block>;Retrieves a transaction by its hash.
getTransaction(transactionHash?: HexString32Bytes, returnFormat?: DataFormat): Promise<Transaction>;Usage Example:
const tx = await eth.getTransaction("0xabcdef1234567890...");
console.log(`From: ${tx.from}, To: ${tx.to}, Value: ${tx.value}`);Retrieves a transaction from a block by index.
getTransactionFromBlock(blockHashOrBlockNumber?: BlockNumberOrTag, indexNumber?: Numbers, returnFormat?: DataFormat): Promise<Transaction>;Usage Example:
// Get first transaction from latest block
const firstTx = await eth.getTransactionFromBlock("latest", 0);Retrieves the receipt for a transaction by its hash.
getTransactionReceipt(transactionHash?: HexString32Bytes, returnFormat?: DataFormat): Promise<TransactionReceipt>;Usage Example:
const receipt = await eth.getTransactionReceipt("0xabcdef1234567890...");
if (receipt.status === '0x1') {
console.log("Transaction successful");
} else {
console.log("Transaction failed");
}Returns all pending transactions.
getPendingTransactions(returnFormat?: DataFormat): Promise<Transaction[]>;Returns the Ethereum protocol version.
getProtocolVersion(): Promise<string>;Returns the chain ID of the current network.
getChainId(): Promise<Numbers>;Usage Example:
const chainId = await eth.getChainId();
// 1 for mainnet, 5 for goerli, etc.Checks if the node is currently syncing with the network.
isSyncing(): Promise<SyncingStatusAPI | boolean>;Returns:
false if not syncingSyncingStatusAPI object with sync progress if syncingUsage Example:
const syncStatus = await eth.isSyncing();
if (syncStatus !== false) {
console.log(`Syncing: ${syncStatus.currentBlock}/${syncStatus.highestBlock}`);
}Returns the coinbase address (mining reward recipient).
getCoinbase(): Promise<Address>;Checks if the node is currently mining.
isMining(): Promise<boolean>;Returns information about the connected node.
getNodeInfo(): Promise<string>;interface Block {
hash?: HexString32Bytes;
parentHash: HexString32Bytes;
sha3Uncles: HexString32Bytes;
miner: Address;
stateRoot: HexString32Bytes;
transactionsRoot: HexString32Bytes;
receiptsRoot: HexString32Bytes;
logsBloom: HexString;
difficulty: Numbers;
number: Numbers;
gasLimit: Numbers;
gasUsed: Numbers;
timestamp: Numbers;
extraData: Bytes;
mixHash: HexString32Bytes;
nonce: HexString8Bytes;
totalDifficulty: Numbers;
size: Numbers;
transactions: HexString32Bytes[] | Transaction[];
uncles: HexString32Bytes[];
}
interface Transaction {
hash?: HexString32Bytes;
nonce: Numbers;
blockHash?: HexString32Bytes;
blockNumber?: Numbers;
transactionIndex?: Numbers;
from: Address;
to?: Address;
value: Numbers;
gasPrice?: Numbers;
maxPriorityFeePerGas?: Numbers;
maxFeePerGas?: Numbers;
gas: Numbers;
input: Bytes;
type?: Numbers;
accessList?: AccessList;
chainId?: Numbers;
v?: Numbers;
r?: HexString32Bytes;
s?: HexString32Bytes;
}
interface TransactionReceipt {
transactionHash: HexString32Bytes;
transactionIndex: Numbers;
blockHash: HexString32Bytes;
blockNumber: Numbers;
from: Address;
to?: Address;
cumulativeGasUsed: Numbers;
gasUsed: Numbers;
contractAddress?: Address;
logs: Log[];
logsBloom: HexString;
status: HexString;
effectiveGasPrice: Numbers;
type: Numbers;
}
interface SyncingStatusAPI {
startingBlock: Numbers;
currentBlock: Numbers;
highestBlock: Numbers;
knownStates?: Numbers;
pulledStates?: Numbers;
}
type BlockNumberOrTag = Numbers | "latest" | "earliest" | "pending" | "safe" | "finalized";
type DataFormat = { number: NumberFormat; bytes: BytesFormat };Install with Tessl CLI
npx tessl i tessl/npm-web3-ethdocs
evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10