Ejemplos de preguntas con respuestas optimistas

En esta página, se proporcionan ejemplos de consultas de Blockchain Analytics para Optimism.

Consulta la documentación de BigQuery para obtener instrucciones sobre cómo usar BigQuery.

Cómo ver el bloque indexado más antiguo y el más reciente

En la consola de Google Cloud , ve a la página BigQuery.

Ir a BigQuery

La siguiente consulta se carga en el campo Editor:

SELECT
  MIN(block_number) AS `First block`,
  MAX(block_number) AS `Newest block`,
  COUNT(1) AS `Total number of blocks`
FROM
  bigquery-public-data.goog_blockchain_optimism_mainnet_us.blocks;

Ejemplo de resultado:

Primer bloque Bloque más reciente Cantidad total de bloques
0 109516624 109516625

Consulta los activos de L1 que se transfirieron a Optimism a través del puente estándar de Optimism

Esta consulta muestra cómo encontrar los registros de eventos de depósito finalizados para los activos de L1 que se transfirieron a Optimism a través del puente estándar de Optimism oficial. El puente estándar de Optimism admite la transferencia de Ether nativo y ciertos tokens ERC-20 de Ethereum a Optimism.

En la consola de Google Cloud , ve a la página BigQuery.

Ir a BigQuery

La siguiente consulta se carga en el campo Editor:

-- UDF for easier string manipulation.
CREATE TEMP FUNCTION ParseSubStr(hexStr STRING, startIndex INT64, endIndex INT64)
RETURNS STRING
LANGUAGE js
AS r"""
  if (hexStr.length < 1) {
    return hexStr;
  }
  return hexStr.substring(startIndex, endIndex);
""";

-- UDF to translate hex numbers into decimal representation.
CREATE TEMP FUNCTION HexToDec(hexStr STRING)
RETURNS BIGNUMERIC
LANGUAGE js
AS r"""
   return parseInt(hexStr, 16)
""";

-- UDF to strip leading zeroes from 66 character addresses.
-- Optimism addresses as returned from the OP node are 66 characters long.
-- Format: "0x" prefix + 64 character (32-byte) address.
-- Strip the leading zeroes so that it's easier to look up addresses in block explorer.
CREATE TEMP FUNCTION StripLeadingZeroes(hex STRING, numZeroes INT64)
RETURNS STRING
LANGUAGE js
AS r"""
  function _stripLeadingZeroes(addr, numZeroes) {
    if (addr.length != 66) {
      return addr;
    }
    return '0x'.concat(addr.substring(numZeroes));
  }
  return _stripLeadingZeroes(hex, numZeroes);
""";

-- Find finalized deposits into Optimism (L2) where assets were transferred
-- from the L1 (Ethereum) to the L2 (Optimism) via the Optimism Standard Bridge
-- at block X.
SELECT
  block_number,
  transaction_hash,
  CONCAT("https://optimistic.etherscan.io/tx/", transaction_hash) AS txn_optimistic_etherscan,
  StripLeadingZeroes(topics[OFFSET(1)], 26) AS L1Token,
  StripLeadingZeroes(topics[OFFSET(2)], 26) AS L2Token,
  StripLeadingZeroes(topics[OFFSET(3)], 26) AS from_address,
  StripLeadingZeroes(ParseSubStr(l.data, 0, 66), 26) AS to_address,
  HexToDec(ParseSubStr(l.data, 66, 130)) AS amount_deposited,
FROM
  `bigquery-public-data.goog_blockchain_optimism_mainnet_us.logs` as l
WHERE
  ARRAY_LENGTH(l.topics) > 0 -- Check for non-empty topics first to short-circuit boolean evaluation.
AND
  -- DepositFinalized:
  -- https://github.com/ethereum-optimism/optimism/blob/e24d77204ede3635d57253f5b6306be261e109b5/packages/contracts-ts/abis.json#L10319
  l.topics[OFFSET(0)] = "0xb0444523268717a02698be47d0803aa7468c00acbed2f8bd93a0459cde61dd89"
AND
  block_number = 109223310;

Ejemplo de resultado:

Bloquear número Hash de la transacción Txn Optimistic Etherscan Token de L1 Token de L2 Dirección del remitente Dirección para Importe depositado
109223310 0xec5885cdfe06809206d3898206e855b7fdac7c95792974f33462b90c7a91f126 https://optimistic.etherscan.io/tx/0xec5885cdfe06809206d3898206e855b7fdac7c95792974f33462b90c7a91f126 0x0000000000000000000000000000000000000000 0xdeaddeaddeaddeaddeaddeaddeaddeaddead0000 0x777a89166b1265ec9d2cab2df5db59d1f50621d1 0x777a89166b1265ec9d2cab2df5db59d1f50621d1 1000000000000000
109223310 0xa04d89f7a8cbbafd81fc315d3f76ca8d8dda4e0177225ff62d266b34b2530454 https://optimistic.etherscan.io/tx/0xa04d89f7a8cbbafd81fc315d3f76ca8d8dda4e0177225ff62d266b34b2530454 0xd533a949740bb3306d119cc777fa900ba034cd52 0x0994206dfe8de6ec6920ff4d779b0d950605fb53 0x9e7f8d6e87ec1c783d01fcc90ebf6ec766b0036c 0xcea806562b757aeffa9fe9d0a03c909b4a204254 1022823927640195072000