跳到主要内容
本 notebook 旨在提供一种测试 LangChain 区块链文档加载器功能的方法。 此加载器最初支持:
  • 从 NFT 智能合约(ERC721 和 ERC1155)加载 NFT 作为文档
  • 以太坊主网、以太坊测试网、Polygon 主网、Polygon 测试网(默认为 eth-mainnet)
  • Alchemy 的 getNFTsForCollection API
如果社区认为此加载器有价值,可以对其进行扩展。具体来说:
  • 可以添加额外的 API(例如,与交易相关的 API)
此文档加载器需要 输出采用以下格式
  • pageContent= 单个 NFT
  • metadata={‘source’: ‘0x1a92f7381b9f03921564a437210bb9396471050c’, ‘blockchain’: ‘eth-mainnet’, ‘tokenId’: ‘0x15’}

将 NFT 加载到文档加载器中

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

alchemyApiKey = "..."

选项 1:以太坊主网(默认 BlockchainType)

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]

以编程方式连接这些文档到 Claude、VSCode 等,通过 MCP 获取实时答案。
© . This site is unofficial and not affiliated with LangChain, Inc.