npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eth--bigquery

v1.1.0

Published

This module repackages [ethers.js](https://github.com/ethers-io/ethers.js/) for use in BigQuery, to decode Ethereum event logs and transaction inputs.

Downloads

4

Readme

ethers.js-bigquery

This module repackages ethers.js for use in BigQuery, to decode Ethereum event logs and transaction inputs.

Example usage:

CREATE TEMP FUNCTION
  DECODE_ERC721_TRANSFER(data STRING, topics ARRAY<STRING>)
  RETURNS STRUCT<`from` STRING, `to` STRING, tokenId STRING>
  LANGUAGE js AS """
    var CRYPTOKITTY_TRANSFER = {
      "anonymous": false,
      "inputs": [
        {
          "indexed": false,
          "name": "from",
          "type": "address"
        },
        {
          "indexed": false,
          "name": "to",
          "type": "address"
        },
        {
          "indexed": false,
          "name": "tokenId",
          "type": "uint256"
        }
      ],
      "name": "Transfer",
      "type": "event"
    };

    var interface_instance = new ethers.utils.Interface([CRYPTOKITTY_TRANSFER]);
    var parsedLog = interface_instance.parseLog({topics: topics, data: data});

    return parsedLog.values;
"""
OPTIONS
  ( library="gs://blockchain-etl-bigquery/ethers.js" );
SELECT
  DECODE_ERC721_TRANSFER(data, topics) AS transfer
FROM
  `bigquery-public-data.crypto_ethereum.logs`
WHERE
  topics[SAFE_OFFSET(0)] = "0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef" -- topic for Transfer(address,address,uint256) event
  AND address = "0x06012c8cf97bead5deae237070f9587f8e7a266d"
LIMIT 100;

The above query returns decoded CryptoKitty transfer events. You can run it by pasting into the BigQuery console SQL editor https://console.cloud.google.com/bigquery.

CREATE TEMP FUNCTION
  DECODE_CREATE_SALE_AUCTION(data STRING)
  RETURNS ARRAY<STRING>
  LANGUAGE js AS """
    var CRYPTOKITTY_CREATE_SALE_AUCTION = {
      "constant": false,
      "inputs": [
        {
          "name": "_kittyId",
          "type": "uint256"
        },
        {
          "name": "_startingPrice",
          "type": "uint256"
        },
        {
          "name": "_endingPrice",
          "type": "uint256"
        },
        {
          "name": "_duration",
          "type": "uint256"
        }
      ],
      "name": "createSaleAuction",
      "outputs": [],
      "payable": false,
      "stateMutability": "nonpayable",
      "type": "function"
    };

    var interface_instance = new ethers.utils.Interface([CRYPTOKITTY_CREATE_SALE_AUCTION]);
    
    // You might need to wrap with try-catch here as transaction input is user provided data and might not follow abi. 
    var parsedTransaction = interface_instance.parseTransaction({data: data});

    return parsedTransaction.args;
"""
OPTIONS
  ( library="gs://blockchain-etl-bigquery/ethers.js" );
SELECT
  `hash`, DECODE_CREATE_SALE_AUCTION(input) AS decoded_input
FROM
  `bigquery-public-data.crypto_ethereum.transactions`
WHERE
  STARTS_WITH(input, "0x3d7d3f5a") -- 4byte sighash for createSaleAuction(uint256,uint256,uint256,uint256) method
  AND to_address = "0x06012c8cf97bead5deae237070f9587f8e7a266d"
LIMIT 100;

The above query returns decoded createSaleAuction() transactions inputs.

To include internal transactions use bigquery-public-data.crypto_ethereum.traces instead of bigquery-public-data.crypto_ethereum.transactions.

Credits

  • https://github.com/Arachnid/ethjs-abi-bigquery