Skip to main content

Intercept Function Calls

In this tutorial, we will build a simple indexer using the NEAR Lake Framework. The indexer will listen for FunctionCalls on a specific contract and log the details of each call.

The full source code for the indexer is available in the GitHub repository.

info

Using NEAR Lake Framework, we can subscribe to the stream of blocks from the NEAR Lake data source. The source of data are JSON files stored in an AWS S3 bucket by NEAR Lake Indexer. The NEAR Lake Framework takes care of downloading and parsing the data for users, but the reader is paying the costs. More details about technical limitations and estimating costs can be found here.


Initialization

AWS Credentials

To access the data provided by NEAR Lake you need to provide valid AWS credentials in order to be charged by the AWS for the S3 usage.

AWS credentials

Please note that using your own AWS Credentials is the only way to access the data provided by NEAR Lake ecosystem.

AWS default profile configuration with aws configure looks similar to the following:

~/.aws/credentials
[default]
aws_access_key_id=<YOUR_AWS_ACCESS_KEY_ID>
aws_secret_access_key=<YOUR_AWS_ACCESS_KEY>

AWS docs: Configuration and credential file settings

Lake Configuration

To initialize the NEAR Lake Framework, we need to provide the following basic settings:

  • The S3 bucket name: the bucket where the NEAR Lake data is stored. The value is near-lake-data-testnet for the testnet and near-lake-data-mainnet for the mainnet.
  • The S3 region: The AWS region where the S3 bucket is located. The default value is eu-central-1.
  • Start block height: The block height from which the indexer will start processing blocks.

The Rust package provides a way to use the default configuration for testnet/mainnet and requires only to choose network and set the start block height which in the example we pass as command line argument.

Running the Indexer

To run the indexer, we need to create a function that will handle every message from the stream. In this function, we can access the block data and process it as needed.

Parsing the Block Data

From the block data, we can access the transactions, their receipts and actions. In this example, we will look for FunctionCall actions on a specific contract and log the details of each call.

The example of logged data:

Block height: 214692896

Transaction hash HQsRK16ABEQWtKpHKWMbPgUreXCD95ZpKw47YkHxGsEc related to 6QpDUkd5n2xJ6mTjkdzXDbvMFo5mEzANS1t4Hfr76SAY executed with status "SuccessValue"
aha_6.testnet
{"contract_id":"3vaopJ7aRoivvzZLngPQRBEd8VJr2zPLTxQfnRCoFgNX"}

Looking for Support?

If you have any questions, connect with us on Telegram or Discord .

Happy coding! 🚀

Versioning for this article

At the time of this writing, this example works with the following versions:

  • near-lake-framework (Rust): 0.7.13
  • @near-lake/framework (JS): 0.1.5
  • near-lake-framework (Python): 0.1.3
  • rustc: 1.86.0
  • node: 22.18.0
  • python: 3.13.5