near-lake-framework

Available in programming languages: Rust | Javascript

NEAR Lake Framework is a small library companion to NEAR Lake. It allows you to build your own indexer that subscribes to the stream of blocks from the NEAR Lake data source and create your own logic to process the NEAR Protocol data.

crates.io Documentation MIT or Apache 2.0 licensed


Official NEAR Lake Framework launch announcement has been published on the NEAR Gov Forum Greetings from the Data Platform Team! We are happy and proud to announce an MVP release of a brand new word in indexer building approach - NEAR Lake Framework.


Example

```rust use futures::StreamExt; use nearlakeframework::LakeConfigBuilder;

[tokio::main]

async fn main() -> Result<(), tokio::io::Error> { // create a NEAR Lake Framework config let config = LakeConfigBuilder::default() .testnet() .startblockheight(82422587) .build() .expect("Failed to build LakeConfig");

// instantiate the NEAR Lake Framework Stream let stream = nearlakeframework::streamer(config);

// read the stream events and pass them to a handler function with // concurrency 1 let mut handlers = tokiostream::wrappers::ReceiverStream::new(stream) .map(|streamermessage| handlestreamermessage(streamermessage)) .bufferunordered(1usize);

while let Some(handlemessage) = handlers.next().await {}

Ok(()) }

// The handler function to take the entire StreamerMessage // and print the block height and number of shards async fn handlestreamermessage( streamermessage: nearlakeframework::nearindexerprimitives::StreamerMessage, ) { eprintln!( "{} / shards {}", streamermessage.block.header.height, streamer_message.shards.len() ); } ```

For more information refer to the docs

Tutorials

More examples

How to use

Dependencies

Add the following dependencies to your Cargo.toml

```toml ... [dependencies] futures = "0.3.5" itertools = "0.10.3" tokio = { version = "1.1", features = ["sync", "time", "macros", "rt-multi-thread"] } tokio-stream = { version = "0.1" }

NEAR Lake Framework

near-lake-framework = "0.3.0" ```

Cost estimates

TL;DR approximately $18.15 per month (for AWS S3 access, paid directly to AWS) for the reading of fresh blocks

Explanation:

Assuming NEAR Protocol produces accurately 1 block per second (which is really not, the average block production time is 1.3s). A full day consists of 86400 seconds, that's the max number of blocks that can be produced.

According the Amazon S3 prices list requests are charged for $0.005 per 1000 requests and get is charged for $0.0004 per 1000 requests.

Calculations (assuming we are following the tip of the network all the time):

86400 blocks per day * 5 requests for each block / 1000 requests * $0.0004 per 1k requests = $0.173 * 30 days = $5.19 Note: 5 requests for each block means we have 4 shards (1 file for common block data and 4 separate files for each shard)

And a number of list requests we need to perform for 30 days:

``` 86400 blocks per day / 1000 requests * $0.005 per 1k list requests = $0.432 * 30 days = $12.96

$5.19 + $12.96 = $18.15 ```

The price depends on the number of shards

Future plans

We use Milestones with clearly defined acceptance criteria: