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

@hashgraphonline/recursion-sdk

v0.0.3

Published

HCS Recursion SDK

Downloads

125

Readme

HCS Recursion SDK

The Recursion SDK is a powerful and flexible tool designed to simplify the integration of Hedera Consensus Service into web applications. It provides an easy way to load and manage HCS-related scripts, styles, and images, with built-in support for configuration, retry mechanisms, and loading indicators.

Features

  • Easy configuration via HTML data attributes
  • Automatic loading of HCS-related scripts, styles, and WASM modules
  • Support for custom CDNs and networks
  • Built-in retry mechanism for failed resource loads
  • Customizable loading indicator
  • Queue-based loading system with support for load order
  • Promise-based initialization

Examples Exploring Recursion

Included in this repository are a number of examples demonstrating the capabilities of recursion.

  1. Hashinals Blaster: A simple, arcade style shooting game leveraging ThreeJS, AnimeJS, NESS-CSS, and Hashinals Wallet Connect.
  1. HashiNova: A complex, casual growth game where your entity grows by consuming Hashinals floating in the universe. It leverages ThreeJS, AnimeJS, NESS-CSS, Hashinals Wallet Connect, CannonJS, and follows the ECS (Entity Component System) framework for development.
  • Download HashiNova
  • Play https://kiloscribe.com/inscription/0.0.6798739
  1. Basic Recursion: A simple example of Recursion demonstrating the capability of utilizing WASM inside of Inscribed Files.
  • Download HashiNova
  • Explore https://kiloscribe.com/inscription/0.0.6796093?network=mainnet

Exploring Further:

  • Visit https://kiloscribe.com/gaming
    • Try the featured games and copy the code snippets to create your own experiences & games using HCS-3.
  • Implement Hashinals Wallet Connect: https://github.com/hashgraph-online/hashinal-wc
    • Add wallet capabilities to your HTML Hashinals with just a few lines of code.

Usage

Testing locally:

  • Copy the contents of the file in the dist directory into your HTML file.
  • Ensure the script included before any logic that depends on the loading of assets.
<script src="path/to/hcs-sdk.js"></script>

Usage with TierBot CDN:

  • Remove the SDK from your code.
  • The TierBot CDN will automatically inject the latest version of the Recursion SDK into your file. Saving you extra HBAR on inscription fees, and ensuring you have access to all the latest features at the time of inscription.

Configuration

You can configure the SDK using data attributes on a script tag. Here's an example with all available options:

<script
  data-hcs-config
  data-hcs-cdn-url="https://your-custom-cdn.com/"
  data-hcs-network="testnet"
  data-hcs-debug="true"
  data-hcs-retry-attempts="5"
  data-hcs-retry-backoff="500"
  data-hcs-show-loading-indicator="true"
  data-hcs-loading-callback-name="setLoadingIndicator"
></script>

Configuration Options

  • data-hcs-cdn-url: The base URL for the CDN hosting your HCS resources (default: "https://kiloscribe.com/api/inscription-cdn/")
  • data-hcs-network: The Hedera network to use (default: "mainnet")
  • data-hcs-debug: Enable debug logging (default: false)
  • data-hcs-retry-attempts: Number of retry attempts for failed resource loads (default: 3)
  • data-hcs-retry-backoff: Initial backoff time in milliseconds for retries (default: 300)
  • data-hcs-show-loading-indicator: Show loading status in console (default: false)
  • data-hcs-loading-callback-name: Name of a global function to call with loading status updates

Usage

Loading HCS Resources

To load HCS resources (scripts, styles, or images), use the data-src attribute with the hcs:// protocol:

<script data-src="hcs://1/0.0.6614307" data-script-id="threejs"></script>
<script data-src="hcs://1/0.0.6627067" data-script-id="animejs"></script>
<script
  data-src="hcs://1/0.0.6633438"
  data-script-id="nes-css"
  type="css"
></script>
<script
  data-src="hcs://1/0.0.6628687"
  data-script-id="rust-wasm"
  type="wasm"
></script>
<img data-src="hcs://1/0.0.6529019" alt="Example Image" />

Note, the examples above are real HCS-1 inscribed topics.

Initialization and Ready State

The SDK automatically initializes itself. To run code after all HCS resources are loaded, define a global HCSReady function:

window.HCSReady = function () {
  console.log('All HCS resources loaded, initializing application');
  // Your initialization code here
};

Custom Loading Indicator

To use a custom loading indicator, define a global function and specify its name in the configuration:

<script>
  function setLoadingIndicator(id, status) {
    console.log(`Resource ${id}: ${status}`);
    // Update your custom loading UI here
  }
</script>
<script
  data-hcs-config
  data-hcs-loading-callback-name="setLoadingIndicator"
></script>

Advanced Usage

Load Order

You can specify the load order for resources using the data-load-order attribute:

<script
  data-src="hcs://1/0.0.6614307"
  data-script-id="threejs"
  data-load-order="1"
></script>
<script
  data-src="hcs://1/0.0.6627067"
  data-script-id="animejs"
  data-load-order="2"
></script>

Required Scripts

Mark a script as required by adding the data-required attribute. If a required script fails to load, the SDK will stop processing the queue:

<script
  data-src="hcs://1/0.0.6614307"
  data-script-id="threejs"
  data-required
></script>

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

If you encounter any problems or have any questions, please open an issue in this repository.