langchain_community.document_loaders.blockchain.BlockchainDocumentLoader¶

class langchain_community.document_loaders.blockchain.BlockchainDocumentLoader(contract_address: str, blockchainType: BlockchainType = BlockchainType.ETH_MAINNET, api_key: str = 'docs-demo', startToken: str = '', get_all_tokens: bool = False, max_execution_time: Optional[int] = None)[source]¶

Load elements from a blockchain smart contract.

The supported blockchains are: Ethereum mainnet, Ethereum Goerli testnet, Polygon mainnet, and Polygon Mumbai testnet.

If no BlockchainType is specified, the default is Ethereum mainnet.

The Loader uses the Alchemy API to interact with the blockchain. ALCHEMY_API_KEY environment variable must be set to use this loader.

The API returns 100 NFTs per request and can be paginated using the startToken parameter.

If get_all_tokens is set to True, the loader will get all tokens on the contract. Note that for contracts with a large number of tokens, this may take a long time (e.g. 10k tokens is 100 requests). Default value is false for this reason.

The max_execution_time (sec) can be set to limit the execution time of the loader.

Future versions of this loader can:
  • Support additional Alchemy APIs (e.g. getTransactions, etc.)

  • Support additional blockain APIs (e.g. Infura, Opensea, etc.)

Parameters
  • contract_address – The address of the smart contract.

  • blockchainType – The blockchain type.

  • api_key – The Alchemy API key.

  • startToken – The start token for pagination.

  • get_all_tokens – Whether to get all tokens on the contract.

  • max_execution_time – The maximum execution time (sec).

Methods

__init__(contract_address[, blockchainType, ...])

param contract_address

The address of the smart contract.

lazy_load()

A lazy loader for Documents.

load()

Load data into Document objects.

load_and_split([text_splitter])

Load Documents and split into chunks.

__init__(contract_address: str, blockchainType: BlockchainType = BlockchainType.ETH_MAINNET, api_key: str = 'docs-demo', startToken: str = '', get_all_tokens: bool = False, max_execution_time: Optional[int] = None)[source]¶
Parameters
  • contract_address – The address of the smart contract.

  • blockchainType – The blockchain type.

  • api_key – The Alchemy API key.

  • startToken – The start token for pagination.

  • get_all_tokens – Whether to get all tokens on the contract.

  • max_execution_time – The maximum execution time (sec).

lazy_load() Iterator[Document]¶

A lazy loader for Documents.

load() List[Document][source]¶

Load data into Document objects.

load_and_split(text_splitter: Optional[TextSplitter] = None) List[Document]¶

Load Documents and split into chunks. Chunks are returned as Documents.

Parameters

text_splitter – TextSplitter instance to use for splitting documents. Defaults to RecursiveCharacterTextSplitter.

Returns

List of Documents.

Examples using BlockchainDocumentLoader¶