2023-04-25 15:07:06 +00:00
|
|
|
{
|
2023-05-02 22:24:53 +00:00
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {
|
|
|
|
"id": "vm8vn9t8DvC_"
|
|
|
|
},
|
|
|
|
"source": [
|
|
|
|
"# Blockchain"
|
|
|
|
]
|
2023-04-25 15:07:06 +00:00
|
|
|
},
|
2023-05-02 22:24:53 +00:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {
|
|
|
|
"id": "5WjXERXzFEhg"
|
|
|
|
},
|
|
|
|
"source": [
|
|
|
|
"## Overview"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
2023-05-27 01:55:21 +00:00
|
|
|
"attachments": {},
|
2023-05-02 22:24:53 +00:00
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {
|
|
|
|
"id": "juAmbgoWD17u"
|
|
|
|
},
|
|
|
|
"source": [
|
|
|
|
"The intention of this notebook is to provide a means of testing functionality in the Langchain Document Loader for Blockchain.\n",
|
|
|
|
"\n",
|
|
|
|
"Initially this Loader supports:\n",
|
|
|
|
"\n",
|
|
|
|
"* Loading NFTs as Documents from NFT Smart Contracts (ERC721 and ERC1155)\n",
|
2023-05-27 01:55:21 +00:00
|
|
|
"* Ethereum Mainnnet, Ethereum Testnet, Polygon Mainnet, Polygon Testnet (default is eth-mainnet)\n",
|
2023-05-02 22:24:53 +00:00
|
|
|
"* Alchemy's getNFTsForCollection API\n",
|
|
|
|
"\n",
|
|
|
|
"It can be extended if the community finds value in this loader. Specifically:\n",
|
|
|
|
"\n",
|
|
|
|
"* Additional APIs can be added (e.g. Tranction-related APIs)\n",
|
|
|
|
"\n",
|
|
|
|
"This Document Loader Requires:\n",
|
|
|
|
"\n",
|
|
|
|
"* A free [Alchemy API Key](https://www.alchemy.com/)\n",
|
|
|
|
"\n",
|
|
|
|
"The output takes the following format:\n",
|
|
|
|
"\n",
|
|
|
|
"- pageContent= Individual NFT\n",
|
|
|
|
"- metadata={'source': '0x1a92f7381b9f03921564a437210bb9396471050c', 'blockchain': 'eth-mainnet', 'tokenId': '0x15'})"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"## Load NFTs into Document Loader"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2023-06-16 18:52:56 +00:00
|
|
|
"# get ALCHEMY_API_KEY from https://www.alchemy.com/\n",
|
2023-05-02 22:24:53 +00:00
|
|
|
"\n",
|
|
|
|
"alchemyApiKey = \"...\""
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"### Option 1: Ethereum Mainnet (default BlockchainType)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {
|
|
|
|
"id": "J3LWHARC-Kn0"
|
|
|
|
},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2023-06-16 18:52:56 +00:00
|
|
|
"from langchain.document_loaders.blockchain import (\n",
|
|
|
|
" BlockchainDocumentLoader,\n",
|
|
|
|
" BlockchainType,\n",
|
|
|
|
")\n",
|
2023-05-02 22:24:53 +00:00
|
|
|
"\n",
|
2023-06-16 18:52:56 +00:00
|
|
|
"contractAddress = \"0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d\" # Bored Ape Yacht Club contract address\n",
|
2023-05-02 22:24:53 +00:00
|
|
|
"\n",
|
2023-06-16 18:52:56 +00:00
|
|
|
"blockchainType = BlockchainType.ETH_MAINNET # default value, optional parameter\n",
|
|
|
|
"\n",
|
|
|
|
"blockchainLoader = BlockchainDocumentLoader(\n",
|
|
|
|
" contract_address=contractAddress, api_key=alchemyApiKey\n",
|
|
|
|
")\n",
|
2023-05-02 22:24:53 +00:00
|
|
|
"\n",
|
|
|
|
"nfts = blockchainLoader.load()\n",
|
|
|
|
"\n",
|
|
|
|
"nfts[:2]"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"### Option 2: Polygon Mainnet"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": null,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2023-06-16 18:52:56 +00:00
|
|
|
"contractAddress = (\n",
|
|
|
|
" \"0x448676ffCd0aDf2D85C1f0565e8dde6924A9A7D9\" # Polygon Mainnet contract address\n",
|
|
|
|
")\n",
|
2023-05-02 22:24:53 +00:00
|
|
|
"\n",
|
2023-06-16 18:52:56 +00:00
|
|
|
"blockchainType = BlockchainType.POLYGON_MAINNET\n",
|
2023-05-02 22:24:53 +00:00
|
|
|
"\n",
|
2023-06-16 18:52:56 +00:00
|
|
|
"blockchainLoader = BlockchainDocumentLoader(\n",
|
|
|
|
" contract_address=contractAddress,\n",
|
|
|
|
" blockchainType=blockchainType,\n",
|
|
|
|
" api_key=alchemyApiKey,\n",
|
|
|
|
")\n",
|
2023-05-02 22:24:53 +00:00
|
|
|
"\n",
|
|
|
|
"nfts = blockchainLoader.load()\n",
|
|
|
|
"\n",
|
|
|
|
"nfts[:2]"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"colab": {
|
|
|
|
"collapsed_sections": [
|
|
|
|
"5WjXERXzFEhg"
|
|
|
|
],
|
|
|
|
"provenance": []
|
|
|
|
},
|
|
|
|
"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.10.6"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 4
|
2023-04-25 15:07:06 +00:00
|
|
|
}
|