Functions
bag.watch function library
Table functions
- call_decode Decodes ABI-encoded function return data into structured columns using the provided ABI definition.
- compile Compiles Solidity or Vyper smart contract source code returning contract name, ABI, and bytecode.
- create2_mine Performs a CREATE2 brute-force search across salt ranges, optionally applying byte masks to target vanity patterns or protocol bitfields.
- evm_disassemble Disassembles EVM bytecode into core instruction metadata using evmone's advanced analysis. Returns 22 essential columns: pc, label, mnemonic, opcode, push_value (BYTES32), instruction properties, stack analysis, block structure, and gas costs from evmone. For comprehensive analysis including CFG, function detection, memory tracking, and dominance analysis, use evm_disassemble_full().
- get_block Retrieves block metadata via eth_getBlockBy* endpoints using the canonical schema.
- get_logs Streams contract logs via eth_getLogs, decoding topics with human-readable signatures or ABI. Named parameters for topic filtering (available on all overloads): - topic1 := BYTES32 or BYTES32[] - Filter first indexed parameter (exact match or OR) - topic2 := BYTES32 or BYTES32[] - Filter second indexed parameter - topic3 := BYTES32 or BYTES32[] - Filter third indexed parameter For Transfer events: topic1=from, topic2=to. Use NULL::ADDRESS to match all contracts.
- get_transaction Retrieves canonical transaction metadata via eth_getTransactionByHash with strict hash validation.
Scalar functions
- block_at Convert a timestamp/date to a block number. Essential for querying blockchain events by date - use with get_logs to fetch transfers, swaps, or any events on a specific day or time range.
- block_range Get the block range for a specific date or time period. Perfect for querying all events (transfers, swaps, mints) that happened on a particular day or within a date range on Ethereum, Base, or other EVM chains.
- call Invokes eth_call using the provided transport, target address, and calldata, returning the raw bytes.
- create2_predict Derives the deterministic CREATE2 deployment address from a deployer, 32-byte salt, and init code hash.
- divmul Computes (x * d) / y using 512-bit intermediate to avoid overflow. Inverse of muldiv. Useful for price calculations.
- encode_function_data Encodes contract function arguments using ABI definitions, returning selector-prefixed calldata.
- error_selector
- error_selector_json
- event_signature
- event_signature_json
- evm_addmod EVM ADDMOD opcode: (a + b) % n without overflow. Returns 0 if n == 0 (EVM behavior). Uses 512-bit intermediate.
- evm_bit_count Population count: Returns the number of set bits (1s) in a UINT256 value. Useful for bitmap analysis and flag counting.
- evm_byte EVM BYTE opcode: Extract the nth byte from a 256-bit value. Byte 0 is MSB, byte 31 is LSB. Returns 0 if n >= 32.
- evm_ceil_div Ceiling division: (x + y - 1) / y. Rounds up to ensure no remainder.
- evm_clamp Constrains x to the range [lo, hi]. Equivalent to max(lo, min(hi, x)).
- evm_clz Count leading zeros: Returns the number of leading zero bits in a UINT256 value. Returns 256 for zero. Useful for finding the most significant bit position.
- evm_ctz Count trailing zeros: Returns the number of trailing zero bits in a UINT256 value. Returns 256 for zero. Useful for finding the least significant bit position.
- evm_iszero EVM ISZERO opcode: Returns 1 if x == 0, otherwise returns 0.
- evm_max Returns the maximum of two UINT256 values.
- evm_min Returns the minimum of two UINT256 values.
- evm_modexp EVM MODEXP precompile: Computes base^exp mod mod using modular exponentiation. Returns 0 if mod is 0 or 1. Uses square-and-multiply algorithm. Critical for cryptographic operations like RSA verification.
- evm_mulmod EVM MULMOD opcode: (a * b) % n without overflow. Returns 0 if n == 0 (EVM behavior). Uses 512-bit intermediate. Essential for cryptographic operations.
- evm_prepare_deployment Creates deployment payloads by combining bytecode with constructor arguments.
- evm_prepare_tx Builds an unsigned eth_sendTransaction JSON payload with minimal inputs.
- evm_sar EVM SAR opcode: Arithmetic right shift x by shift bits. Sign-extends (fills with 1s for negative values). For signed INT256.
- evm_shl EVM SHL opcode: Left shift x by shift bits. Returns 0 if shift >= 256.
- evm_shr EVM SHR opcode: Logical right shift x by shift bits. Fills with zeros.
- evm_sign Returns the sign of an INT256 value: -1 for negative, 0 for zero, 1 for positive. Useful for direction detection in price changes and deltas.
- evm_signextend EVM SIGNEXTEND opcode: Sign-extend x from byte k. Byte k is 0-indexed from LSB. Extends sign bit through higher bytes. Returns x unchanged if k >= 31.
- evm_sqrt Integer square root (floor) using Newton-Raphson iteration. Returns floor(sqrt(x)). Essential for AMM liquidity calculations.
- format_ether Human-readable helper for wei balances. Equivalent to format_units(amount, 18).
- format_units Scales raw EVM integer balances by 10^decimals and returns a VARCHAR string representation.
- function_selector
- function_selector_json
- get_balance Returns the Wei-denominated account balance via eth_getBalance through the configured transport.
- get_code Retrieves deployed EVM bytecode via eth_getCode, returning NULL for EOAs or pre-deploy addresses.
- get_storage_at Retrieves raw storage slot values via eth_getStorageAt for EVM forensics, bytecode analysis, and state inspection. Returns 32-byte BYTES32 values suitable for low-level contract state research.
- http_transport Creates a TRANSPORT JSON blob backed by the HTTP client, carrying base timeouts and headers.
- keccak256 Computes the Keccak-256 hash used across the EVM toolchain, returning a BYTES32 digest.
- latest_block Get the current block number (chain head/tip). Use to find the most recent block on Ethereum, Base, or other EVM chains.
- muldiv Computes (x * y) / z using 512-bit intermediate to avoid overflow. Essential for DeFi calculations like token swaps and price computations.
- parse_abi_event
- parse_ether Shorthand for parse_units(value, 18). Converts ETH/WETH amounts to wei.
- parse_gwei Shorthand for parse_units(value, 9). Converts gwei to wei.
- parse_units Converts human-readable token amounts to UINT256 raw values by multiplying by 10^decimals.
- read_contract Invokes eth_call with ABI-aware argument encoding. Returns a single value if the ABI function has one output, or a STRUCT with named fields if multiple outputs.
- rpc_call Issues a JSON-RPC request using the provided transport configuration and returns the raw result.
- sort_key Converts INT256/UINT256 to a sortable BLOB for use in ORDER BY. Necessary because DuckDB's default BLOB ordering doesn't handle signed integers correctly.
- to_timestamp Converts a UINT256 Unix timestamp (seconds since epoch) to a TIMESTAMP.
- transport Builds a TRANSPORT JSON payload suitable for RPC helpers, normalizing the URL and attaching metadata.
- try_add Add two UINT256 values, returning NULL if overflow occurs. Follows DuckDB's try_* convention for safe arithmetic.
- try_mul Multiply two UINT256 values, returning NULL if overflow occurs. Follows DuckDB's try_* convention for safe arithmetic.
- try_sub Subtract two UINT256 values, returning NULL if underflow occurs. Follows DuckDB's try_* convention for safe arithmetic.