npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@okcontract/multichain

v0.1.1

Published

Low-level library for functional reactive blockchain RPC calls

Downloads

9

Readme

multichain: Reactive Blockchain RPC Calls

CI

size

multichain is a low-level library that facilitates reactive blockchain RPC calls, leveraging the cells library - a simplified reactive functional library inspired by spreadsheet functionalities.

Problem Statement

Decentralized applications (dApps) often face challenges when connecting to blockchain RPCs due to asynchronous operations that result in significant delays. Common issues include:

  1. Difficulty in implementing multicall aggregation to optimize RPC calls.
  2. Lack of default mechanisms for retrying or dispatching calls to multiple RPC nodes.
  3. Inefficient caching of immutable data, leading to unnecessary re-queries.
  4. The complexity of integrating reactive, functional programming with existing imperative libraries.

Solution

multichain addresses these challenges by providing a multi-chain cache for RPC queries and their responses, built around reactive functional programming principles. Each response is treated as a cell, allowing predefined computational flows that execute automatically when the data becomes available.

Quick Start

Here's how you can set up and use multichain:

Setup

// Import necessary modules
import { Sheet } from "@okcontract/cells";
import {
  MultiChainRPC,
  LocalRPCSubscriber,
  Address,
  EVMAddress,
} from "@okcontract/multichain";

// Create a cells proxy
const proxy = new Sheet().newProxy();

// Initialize a multichain instance
const multi = new MultiChainRPC(proxy);
// Initialize a local instance -- doing reference counting
const local = new LocalRPCSubscriber(proxy, multi);

// Create cells for ABI, contract, method, and args
const abi = proxy.new(parseAbi(["..."]));
const contract = proxy.new<EVMAddress>({
  addr: new Address("0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"),
  chain: "sepolia",
});
const method = proxy.new("fake");
const args = proxy.new([]);

Fetch and react to RPC data

Use local.call to retrieve a reactive cell:

const data = local.call(contract, abi, method, args);
const next = data.map(v => ...)
args.set(["new..."]); // Update arguments and recompute automatically data, next, etc.

There are options to set the data validity, e.g. query every 30 sec, or define a specific number of retries.

Additional Query Support

multichain extends its functionality beyond function calls to:

  • getTransactionReceipt: Retrieves the receipt of a transaction, providing critical details like status, gas used, and logs.
  • estimateGas: Estimates the gas needed for a transaction before it's executed on the blockchain.
  • getBalance: Fetches the balance of an account at a given block number.
  • blockNumber: Returns the number of the most recent block in the chain.

Our support for RPC methods will keep expanding: Keep an eye on our release notes and community channels for the latest updates and added query support.

Extended Support: EVM and Starknet

In addition to Ethereum and EVM-compatible networks, multichain natively supports Starknet calls, enabling seamless queries across different blockchain networks.

There is no difference in the call, just make sure that both contract and abi match a Starknet contract:

// Contract is a Starknet Address
const contract = proxy.new({
    chain: "starknet",
    addr: new Address(
      "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
      StarkNet
    )
  });
// Starknet ABI
const abi = proxy.new(...)
...
const value = local.call(contract, abi, method, args);

Design & Philosophy

multichain is crafted to offer fine-grained control for developers and dApp implementors, with plans to release a higher-level consumer interface to simplify rapid dApp development.

We aim for ease of use and correction, so chasing down any bug is our top priority.

Contributing

Contributions are welcome! For minor fixes, please feel free to submit a pull request. For significant changes, kindly discuss with us via Discord or Twitter before proceeding.

License & Support

multichain is developed by OKcontract and is released under the Apache license. The project is supported by a strategic partnership with Starknet.