Skip to main content
Open In ColabOpen on GitHub

区块链

概述

本笔记本的目的是提供一种测试Langchain区块链文档加载器功能的方法。

最初,此加载器支持:

  • 从NFT智能合约(ERC721和ERC1155)加载NFT作为文档
  • 以太坊主网, 以太坊测试网, Polygon主网, Polygon测试网 (默认为 eth-mainnet)
  • Alchemy的getNFTsForCollection API

如果社区认为这个加载器有价值,它可以被扩展。具体来说:

  • 可以添加额外的API(例如,与交易相关的API)

此文档加载器需要:

输出采用以下格式:

  • pageContent= 单个NFT
  • metadata={'source': '0x1a92f7381b9f03921564a437210bb9396471050c', 'blockchain': 'eth-mainnet', 'tokenId': '0x15'}

将NFTs加载到文档加载器中

# get ALCHEMY_API_KEY from https://www.alchemy.com/

alchemyApiKey = "..."

选项1:以太坊主网(默认区块链类型)

from langchain_community.document_loaders.blockchain import (
BlockchainDocumentLoader,
BlockchainType,
)

contractAddress = "0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d" # Bored Ape Yacht Club contract address

blockchainType = BlockchainType.ETH_MAINNET # default value, optional parameter

blockchainLoader = BlockchainDocumentLoader(
contract_address=contractAddress, api_key=alchemyApiKey
)

nfts = blockchainLoader.load()

nfts[:2]

选项2:Polygon 主网

contractAddress = (
"0x448676ffCd0aDf2D85C1f0565e8dde6924A9A7D9" # Polygon Mainnet contract address
)

blockchainType = BlockchainType.POLYGON_MAINNET

blockchainLoader = BlockchainDocumentLoader(
contract_address=contractAddress,
blockchainType=blockchainType,
api_key=alchemyApiKey,
)

nfts = blockchainLoader.load()

nfts[:2]

这个页面有帮助吗?