CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-web3-eth

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

67

0.98x
Overview
Eval results
Files

blockchain-state.mddocs/

Blockchain State Access

The blockchain state access functionality provides comprehensive read access to Ethereum blockchain data including blocks, transactions, accounts, and network state information.

Block Operations

getBlock

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 hashes
  • returnFormat: Output format configuration for numbers and bytes

Usage 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...");

getBlockNumber

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}`);

getBlockTransactionCount

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...");

getBlockUncleCount

Returns the number of uncles in a block.

getBlockUncleCount(blockHashOrBlockNumber?: BlockNumberOrTag, returnFormat?: DataFormat): Promise<Numbers>;

getUncle

Returns an uncle block by block hash/number and uncle index.

getUncle(blockHashOrBlockNumber?: BlockNumberOrTag, uncleIndex?: Numbers, returnFormat?: DataFormat): Promise<Block>;

Transaction Operations

getTransaction

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}`);

getTransactionFromBlock

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);

getTransactionReceipt

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");
}

getPendingTransactions

Returns all pending transactions.

getPendingTransactions(returnFormat?: DataFormat): Promise<Transaction[]>;

Network State Information

getProtocolVersion

Returns the Ethereum protocol version.

getProtocolVersion(): Promise<string>;

getChainId

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.

isSyncing

Checks if the node is currently syncing with the network.

isSyncing(): Promise<SyncingStatusAPI | boolean>;

Returns:

  • false if not syncing
  • SyncingStatusAPI object with sync progress if syncing

Usage Example:

const syncStatus = await eth.isSyncing();
if (syncStatus !== false) {
  console.log(`Syncing: ${syncStatus.currentBlock}/${syncStatus.highestBlock}`);
}

getCoinbase

Returns the coinbase address (mining reward recipient).

getCoinbase(): Promise<Address>;

isMining

Checks if the node is currently mining.

isMining(): Promise<boolean>;

getNodeInfo

Returns information about the connected node.

getNodeInfo(): Promise<string>;

Core Types

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-eth

docs

account-operations.md

blockchain-state.md

cryptographic-operations.md

event-monitoring.md

gas-fee-management.md

index.md

network-information.md

smart-contract-interaction.md

transaction-management.md

transaction-utilities.md

tile.json