{ "cells": [ { "cell_type": "markdown", "id": "c3d4e5f6-0003-0000-0000-000000000001", "metadata": {}, "source": [ "# Querying\n", "\n", "All five query functions demonstrated against live Sepolia data.\n", "\n", "> These examples run against Sepolia testnet (`network=\"sepolia\"`).\n", "> To run against Base mainnet: replace `configure(network=\"sepolia\")` with `configure(network=\"base\")`.\n", "> All function calls, record structures, and output shapes are identical across networks." ] }, { "cell_type": "code", "execution_count": 1, "id": "c3d4e5f6-0003-0000-0000-000000000002", "metadata": {}, "outputs": [], "source": [ "# Cell 1 — setup\n", "from anchorregistry import configure, get_by_arid, get_by_registrant, get_by_tree, get_by_type, get_all, BASE_SEPOLIA_RPC, V1A_BASE_SEPOLIA\n", "from anchorregistry import ARTIFACT_TYPE_MAP, BASE_SEPOLIA_RPC, V1A_BASE_SEPOLIA\n", "from anchorregistry.enums import ArtifactType\n", "\n", "configure(\n", " network=\"base-sepolia\",\n", " contract_address=V1A_BASE_SEPOLIA,\n", " rpc_url=BASE_SEPOLIA_RPC, # swap for Infura / Alchemy URL for faster scans\n", ")\n" ] }, { "cell_type": "code", "execution_count": 2, "id": "c3d4e5f6-0003-0000-0000-000000000003", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Type: RESEARCH\n", "Title: test sepolia anchor\n", "Data: {'doi': '', 'institution': '', 'co_authors': '', 'url': 'https://anchorregistry.com/'}\n" ] } ], "source": [ "# Cell 2 — get_by_arid\n", "# Fetch a single anchor by its AR-ID\n", "record = get_by_arid(\"AR-2026-dPXazj6\")\n", "print(f\"Type: {record['artifact_type_name']}\")\n", "print(f\"Title: {record['title']}\")\n", "print(f\"Data: {record['data']}\")" ] }, { "cell_type": "code", "execution_count": 3, "id": "c3d4e5f6-0003-0000-0000-000000000004", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total anchors by registrant: 5\n" ] } ], "source": [ "# Cell 3 — get_by_registrant\n", "# Fetch all anchors registered by a specific wallet address\n", "records = get_by_registrant(\"0xc7a7afde1177fbf0bb265ea5a616d1b8d7ed8c44\")\n", "print(f\"Total anchors by registrant: {len(records)}\")" ] }, { "cell_type": "code", "execution_count": 4, "id": "c3d4e5f6-0003-0000-0000-000000000005", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total anchors in tree: 1\n" ] } ], "source": [ "# Cell 4 — get_by_tree\n", "# Fetch all anchors belonging to a named artifact tree\n", "records = get_by_tree(\"0xf07140ce4deaf3b5dac859091a079f82e9656f173593feda7895d940b8fa5d13\")\n", "print(f\"Total anchors in tree: {len(records)}\")" ] }, { "cell_type": "code", "execution_count": 5, "id": "c3d4e5f6-0003-0000-0000-000000000006", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "RESEARCH anchors on Sepolia: 1\n" ] } ], "source": [ "# Cell 5 — get_by_type\n", "# Fetch all anchors of a given artifact type\n", "research_anchors = get_by_type(ArtifactType.RESEARCH)\n", "print(f\"RESEARCH anchors on Sepolia: {len(research_anchors)}\")" ] }, { "cell_type": "code", "execution_count": 6, "id": "c3d4e5f6-0003-0000-0000-000000000007", "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Total anchors on Sepolia: 5\n" ] } ], "source": [ "# Cell 6 — get_all\n", "# Reconstruct the full registry — all anchors from deploy block to latest\n", "all_records = get_all()\n", "print(f\"Total anchors on Sepolia: {len(all_records)}\")" ] }, { "cell_type": "code", "execution_count": 7, "id": "mf8afgrsxjs", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "{0: 'CODE',\n", " 1: 'RESEARCH',\n", " 2: 'DATA',\n", " 3: 'MODEL',\n", " 4: 'AGENT',\n", " 5: 'MEDIA',\n", " 6: 'TEXT',\n", " 7: 'POST',\n", " 8: 'ONCHAIN',\n", " 9: 'REPORT',\n", " 10: 'NOTE',\n", " 11: 'WEBSITE',\n", " 12: 'EVENT',\n", " 13: 'RECEIPT',\n", " 14: 'LEGAL',\n", " 15: 'ENTITY',\n", " 16: 'PROOF',\n", " 17: 'SEAL',\n", " 18: 'RETRACTION',\n", " 19: 'REVIEW',\n", " 20: 'VOID',\n", " 21: 'AFFIRMED',\n", " 22: 'ACCOUNT',\n", " 23: 'OTHER'}" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Cell 7 — ARTIFACT_TYPE_MAP\n", "# Maps integer type indices to human-readable names\n", "# Useful for decoding artifact_type_index in raw records\n", "{k: v for k, v in ARTIFACT_TYPE_MAP.items()}" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.11.15" } }, "nbformat": 4, "nbformat_minor": 5 }