区块链
概览
该笔记本的目的是提供一种测试Langchain文档加载器(用于区块链)功能的方法。
起初,此加载器支持:
- 加载来自NFT智能合约的NFT作为文档(ERC721和ERC1155)
- 以太坊主网,以太坊测试网,多边形主网,多边形测试网(默认是 eth-mainnet)
- Alchemy的getNFTsForCollection API
如果社区认为这个加载器有价值,那么它可以扩展。具体来说:
- 可以添加其他API(例如交易相关的API)
此文档加载器需要:
- 一个免费的 Alchemy API密钥
The output takes the following format:
- pageContent= 单个NFT
- metadata={'source': '0x1a92f7381b9f03921564a437210bb9396471050c', 'blockchain': 'eth-mainnet', 'tokenId': '0x15'}
加载NFT到文档加载器
# get ALCHEMY_API_KEY from https://www.alchemy.com/
alchemyApiKey = "..."
Option 1: Ethereum 主网(默认区块链类型)
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 |区块链类型
Option 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]