This is an all-in-one query dashboard of the 🔍Bytexplorer Web3 SQL Weekly Series
📚The series was super helpful for me in getting used to onchain queries and Dune. I often revert back here to find which table to use and how to structure the query. Hope you find it useful as well!
They are forks of @ilemi's queries from the blog series, and i updated the bonus questions and the deprecated queries. I added notes on what I have learned on the side.
Feedback welcomed😃 @twinFin22
Web3 SQL Weekly #7: Cohort Retention for Opensea and Other NFT Marketplaces
- table:
nft.trades
CTEs
- Get all seller/buyer addy and assign to a cohort : SELECT min(month) as cohort, user GROUP BY 2
- Get total size of cohort : SELECT count(*) as total_size , cohort GROUP BY 2
- For each month after the cohort month, find how many are still using : row_number() over (partition by cohort order by month asc) as months GROUP BY cohort, month
- Create {months : Retention%} dict per cohort and pivot the table using the key-pair
Web3 SQL Weekly #4: Getting New and Old Users (Wallets) for a Protocol
- table: ethereum.traces
row_number() OVER (PARTITION BY user ORDER BY week ASC) as times_used. CASE WHEN times_used = 1 THEN new_user ELSE old_user- 👆🏼default contract: Opensea Seaport
Web3 SQL Weekly #9: Sleuthing a Sudoswap Trade(link to blog)
- tables used:
sudoswap_v2_ethereum.base_trades - older query uses
sudoswap_v2_ethereum.LSSVMPair_call_swapNFTsForTokenand require some digging into the sol structure 👉🏻 Use the table finder given a tx to explore!
Web3 SQL Weekly #8: Analyzing Account Abstraction (ERC-4337)
- table:
erc4337_polygon.EntryPoint_v0_6_call_innerHandleOp - JOIN
polygon.traces ON cardinality(t.trace_address) > 3 - "it takes at least depth of 4 for user ops to be sent"
- EntryPoint: Receives user ops and performs initial validation checks, and forwards user ops to the user's smart account contract.
Web3 SQL Weekly #6: Finding Metaverse Landlords by creating and using labels
- table:
nft.trades - find the nft_contract_addy for each metaverse project in their docs/Dune dashboard. check if it is ERC721
- for Voxel, they are ERC20 and the quantity indicates token_id (use etherscan to double check this)
- Metaverse pjts included: Decentraland, Apeland, Sandbox, Voxel
Web3 SQL Weekly #5: How to Identify All Bitcoin NFT Mints (Ordinal Inscriptions)
- table:
bitcoin.transactions - locate the Ordinals Inscription OPcode in the hex column and then read the following data
- ㄴ
WHERE cast(hex as varchar) LIKE '%0063036f72640101%'
Web3 SQL Weekly #2: Finding contracts that have integrated with a contract
- table: ethereum.traces , ethereum.signatures
ON sig.id = bytearray_substring(tr.input, 1, 5) WHERE cardinality!= 0 AND json(abi, stateMutability) NOT IN view, pure- 👆🏼 default contract: Lido stETH
Web3 SQL Weekly #3: Finding all NFTs (ERC721) held by an address
- table:
nft.transfers row_number() OVER (PARTITION BY contract_addy, token_id ORDER BY block_num DESC, evt_idx DESC) CASE WHEN tx.from != target_addy THEN 'gifted' WHEN from = 0x00 null addy THEN 'minted' ELSE 'bought'- 👆🏼 default addy: deeze
Web3 SQL Weekly #1: How to calculate ETH balances for any address
- table:
ethereum.traces WHERE value > 0 AND call_type NOT IN delegatecall, staticcall, callcode- 👆🏼 default addy: Robinhood