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

@lit-protocol/lit-oracle-kit

v1.0.0

Published

SDK for executing Lit Actions as oracles and writing to chain

Downloads

34

Readme

Lit Oracle Kit

This is a simple kit for using the Lit Network to write web data to a chain.

How it works

The Lit Oracle Kit uses an PKP Wallet (Programmable Key Pair) to sign the data that is written to the chain using a Lit Action (JS code that runs on Lit Nodes). The PKP is irrevocably bound to the code that retrieves and writes the data to chain, so you know that if this PKP wrote the data, it was by running that Lit Action JS code.

When you call writeToChain, the kit does the following:

  1. Checks if there is already a PKP Wallet for the given IPFS CID. If not, it creates a new one and stores it in local storage.
  2. Sends the JS code to the Lit Nodes to be executed
  3. On the Lit Nodes, the JS code uses the PKP Wallet to sign the data and broadcast it to chain.

Installation

npm i lit-oracle-kit

Usage

import { LitOracleKit } from "lit-oracle-kit";

const sdk = new LitOracleKit(
  "datil-dev",
  process.env.LIT_ORACLE_KIT_PRIVATE_KEY!
);
await sdk.connect();

const result = await sdk.writeToChain({
  dataSource: `
    const url = "https://api.weather.gov/gridpoints/LWX/97,71/forecast";
    const response = await fetch(url).then((res) => res.json());
    const nearestForecast = response.properties.periods[0];
    const temp = nearestForecast.temperature;
    const probabilityOfPrecipitation = nearestForecast.probabilityOfPrecipitation.value || 0;
    return [ temp, probabilityOfPrecipitation ];
`,
  functionAbi:
    "function updateWeather(int256 temperature, uint8 precipitationProbability) external",
  toAddress: "0xE2c2A8A1f52f8B19A46C97A6468628db80d31673",
  chain: "yellowstone",
});

Examples

Fetching weather data and writing to a chain

The examples/hardhat-weather-oracle directory contains a simple example of how to use this kit to fetch weather data from the NOAA API and write it to a chain using the Lit Oracle Kit.

The script update-weather.ts fetches the weather data and writes it to the chain by calling the updateWeather function on the deployed WeatherOracle contract.

Writing your data source

You can test your data source retrieval code using the testDataSource() function. This will simply run your code on the Lit Nodes and return the result, so you can confirm that it's retrieving the correct values.

import { LitOracleKit } from "lit-oracle-kit";

const sdk = new LitOracleKit(
  "datil-dev",
  process.env.LIT_ORACLE_KIT_PRIVATE_KEY!
);
await sdk.connect();

const result = await sdk.testDataSource(`
    const url = "https://api.weather.gov/gridpoints/LWX/97,71/forecast";
    const response = await fetch(url).then((res) => res.json());
    const nearestForecast = response.properties.periods[0];
    const temp = nearestForecast.temperature;
    const probabilityOfPrecipitation = nearestForecast.probabilityOfPrecipitation.value || 0;
    return [ temp, probabilityOfPrecipitation ];
`);

// this will output your return value, so you can confirm it's correct
console.log(result.response);

Documentation

License

MIT

Support

You can find support information, including Discord and Telegram support channels, here: https://developer.litprotocol.com/support/intro