CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-web3

Ethereum JavaScript API for interacting with the Ethereum blockchain with comprehensive TypeScript support, modular architecture, and plugin extensibility.

Pending
Overview
Eval results
Files

ethereum-interaction.mddocs/

Ethereum Interaction

The Web3Eth module provides comprehensive functionality for interacting with the Ethereum blockchain, including account queries, transaction handling, block operations, and gas estimation. It serves as the primary interface for all Ethereum-specific operations.

Capabilities

Account Queries

Retrieve account information and balances from the blockchain.

/**
 * Get the balance of an account at a given block
 * @param address - The account address
 * @param blockNumber - Block number or tag (default: 'latest')
 * @param returnFormat - Return format for the response
 * @returns Account balance in wei
 */
getBalance(
  address: Address, 
  blockNumber?: BlockNumberOrTag, 
  returnFormat?: DataFormat
): Promise<bigint>;

/**
 * Get the transaction count (nonce) for an account
 * @param address - The account address  
 * @param blockNumber - Block number or tag (default: 'latest')
 * @param returnFormat - Return format for the response
 * @returns Transaction count
 */
getTransactionCount(
  address: Address,
  blockNumber?: BlockNumberOrTag,
  returnFormat?: DataFormat  
): Promise<bigint>;

/**
 * Get code at a given address
 * @param address - The contract address
 * @param blockNumber - Block number or tag (default: 'latest')
 * @param returnFormat - Return format for the response  
 * @returns Contract code
 */
getCode(
  address: Address,
  blockNumber?: BlockNumberOrTag,
  returnFormat?: DataFormat
): Promise<string>;

Usage Examples:

// Get account balance
const balance = await web3.eth.getBalance('0x742C1382...');
const balanceInEther = web3.utils.fromWei(balance, 'ether');

// Get transaction count (nonce)
const nonce = await web3.eth.getTransactionCount('0x742C1382...');

// Get contract code
const code = await web3.eth.getCode('0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984');

Transaction Operations

Send transactions, estimate gas, and retrieve transaction information.

/**
 * Send a transaction to the network
 * @param transaction - Transaction object
 * @param returnFormat - Return format for the response
 * @returns PromiEvent with transaction receipt
 */
sendTransaction(
  transaction: Transaction,
  returnFormat?: DataFormat
): PromiEvent<TransactionReceipt>;

/**
 * Send a signed raw transaction
 * @param signedTransaction - Signed transaction data
 * @param returnFormat - Return format for the response
 * @returns PromiEvent with transaction receipt
 */
sendSignedTransaction(
  signedTransaction: Bytes,
  returnFormat?: DataFormat
): PromiEvent<TransactionReceipt>;

/**
 * Estimate gas required for a transaction
 * @param transaction - Transaction object
 * @param blockNumber - Block number or tag (default: 'latest')
 * @param returnFormat - Return format for the response
 * @returns Estimated gas amount
 */
estimateGas(
  transaction: Transaction,
  blockNumber?: BlockNumberOrTag,
  returnFormat?: DataFormat
): Promise<bigint>;

/**
 * Get transaction by hash
 * @param transactionHash - Transaction hash
 * @param returnFormat - Return format for the response
 * @returns Transaction object or null
 */
getTransaction(
  transactionHash: Bytes,
  returnFormat?: DataFormat
): Promise<TransactionInfo | null>;

/**
 * Get transaction receipt
 * @param transactionHash - Transaction hash
 * @param returnFormat - Return format for the response
 * @returns Transaction receipt or null
 */
getTransactionReceipt(
  transactionHash: Bytes,
  returnFormat?: DataFormat
): Promise<TransactionReceipt | null>;

Usage Examples:

// Send a transaction
const receipt = await web3.eth.sendTransaction({
  from: '0x742C1382...',
  to: '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
  value: web3.utils.toWei('0.1', 'ether'),
  gas: 21000
});

// Estimate gas
const gasEstimate = await web3.eth.estimateGas({
  to: '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
  data: '0xa9059cbb...'
});

// Get transaction info
const tx = await web3.eth.getTransaction('0x123...');
const receipt = await web3.eth.getTransactionReceipt('0x123...');

Block Operations

Retrieve block information and monitor new blocks.

/**
 * Get block information
 * @param blockHashOrBlockNumber - Block hash or number
 * @param hydrated - Whether to include full transaction objects (default: false)
 * @param returnFormat - Return format for the response
 * @returns Block information
 */
getBlock(
  blockHashOrBlockNumber: Bytes | BlockNumberOrTag,
  hydrated?: boolean,
  returnFormat?: DataFormat
): Promise<Block>;

/**
 * Get the latest block number
 * @param returnFormat - Return format for the response
 * @returns Latest block number
 */
getBlockNumber(returnFormat?: DataFormat): Promise<bigint>;

/**
 * Get block transaction count
 * @param blockHashOrBlockNumber - Block hash or number
 * @param returnFormat - Return format for the response
 * @returns Number of transactions in block
 */
getBlockTransactionCount(
  blockHashOrBlockNumber: Bytes | BlockNumberOrTag,
  returnFormat?: DataFormat
): Promise<bigint>;

Usage Examples:

// Get latest block
const latestBlock = await web3.eth.getBlock('latest');

// Get specific block with transactions
const block = await web3.eth.getBlock(18000000, true);

// Get current block number
const blockNumber = await web3.eth.getBlockNumber();

Call Operations

Execute read-only contract calls and simulate transactions.

/**
 * Execute a message call transaction
 * @param transaction - Call transaction object
 * @param blockNumber - Block number or tag (default: 'latest')
 * @param returnFormat - Return format for the response
 * @returns Call result
 */
call(
  transaction: Transaction,
  blockNumber?: BlockNumberOrTag,
  returnFormat?: DataFormat
): Promise<string>;

/**
 * Get storage value at a specific position
 * @param address - Contract address
 * @param storageSlot - Storage slot position
 * @param blockNumber - Block number or tag (default: 'latest')
 * @param returnFormat - Return format for the response
 * @returns Storage value
 */
getStorageAt(
  address: Address,
  storageSlot: Numbers,
  blockNumber?: BlockNumberOrTag,
  returnFormat?: DataFormat
): Promise<string>;

Gas Price Operations

Retrieve current gas price information and fee history.

/**
 * Get current gas price
 * @param returnFormat - Return format for the response
 * @returns Current gas price in wei
 */
getGasPrice(returnFormat?: DataFormat): Promise<bigint>;

/**
 * Get fee history for recent blocks
 * @param blockCount - Number of blocks to query
 * @param newestBlock - Newest block to include
 * @param rewardPercentiles - Array of percentile values for priority fees
 * @param returnFormat - Return format for the response
 * @returns Fee history data
 */
getFeeHistory(
  blockCount: Numbers,
  newestBlock: BlockNumberOrTag,
  rewardPercentiles?: Numbers[],
  returnFormat?: DataFormat
): Promise<FeeHistory>;

Network Information

Retrieve network and chain information.

/**
 * Get the chain ID
 * @param returnFormat - Return format for the response
 * @returns Chain ID
 */
getChainId(returnFormat?: DataFormat): Promise<bigint>;

/**
 * Get network ID
 * @param returnFormat - Return format for the response
 * @returns Network ID
 */
net: {
  getId(returnFormat?: DataFormat): Promise<bigint>;
  getPeerCount(returnFormat?: DataFormat): Promise<bigint>;
  isListening(returnFormat?: DataFormat): Promise<boolean>;
};

Subscription Support

Subscribe to blockchain events and new data.

/**
 * Subscribe to blockchain events
 * @param subscription - Subscription type and parameters
 * @returns Subscription object
 */
subscribe<T extends keyof RegisteredSubscription>(
  subscription: T,
  ...args: Parameters<RegisteredSubscription[T]['new']>
): Promise<InstanceType<RegisteredSubscription[T]>>;

// Available subscriptions
interface RegisteredSubscription {
  newBlockHeaders: Web3Subscription<BlockHeaderOutput>;
  pendingTransactions: Web3Subscription<string>;
  newPendingTransactions: Web3Subscription<TransactionInfo>;
  syncing: Web3Subscription<SyncingStatusAPI>;
  logs: Web3Subscription<Log>;
}

Usage Examples:

// Subscribe to new block headers
const subscription = await web3.eth.subscribe('newBlockHeaders');
subscription.on('data', (blockHeader) => {
  console.log('New block:', blockHeader.number);
});

// Subscribe to logs
const logSubscription = await web3.eth.subscribe('logs', {
  address: '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
  topics: ['0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef']
});

Types

interface Transaction {
  to?: Address;
  from?: Address;
  value?: Numbers;
  gas?: Numbers;
  gasPrice?: Numbers;
  maxFeePerGas?: Numbers;
  maxPriorityFeePerGas?: Numbers;
  data?: Bytes;
  nonce?: Numbers;
  type?: Numbers;
  accessList?: AccessList;
}

interface TransactionReceipt {
  transactionHash: string;
  transactionIndex: bigint;
  blockNumber: bigint;
  blockHash: string;
  from: string;
  to: string;
  gasUsed: bigint;
  cumulativeGasUsed: bigint;
  logs: Log[];
  status: bigint;
  contractAddress?: string;
}

interface Block {
  number: bigint;
  hash: string;
  parentHash: string;
  timestamp: bigint;
  gasLimit: bigint;
  gasUsed: bigint;
  miner: string;
  transactions: string[] | TransactionInfo[];
}

interface Log {
  address: string;
  topics: string[];
  data: string;
  blockNumber: bigint;
  transactionHash: string;
  transactionIndex: bigint;
  blockHash: string;
  logIndex: bigint;
}

type BlockNumberOrTag = Numbers | 'earliest' | 'latest' | 'pending' | 'safe' | 'finalized';
type Address = string;
type Bytes = string | Uint8Array;
type Numbers = number | bigint | string;

Install with Tessl CLI

npx tessl i tessl/npm-web3

docs

account-management.md

core-web3.md

ens.md

ethereum-interaction.md

index.md

providers.md

smart-contracts.md

utilities.md

tile.json