区块链
概述
此笔记本的目的是提供一种测试 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]
API 参考:BlockchainDocumentLoader | BlockchainType
选项 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]