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

@smartweave/modules

v0.0.0-alpha

Published

## Overview The goal of the project is to provide standardized modules which can be used by anyone. ## Installation ``` yarn add @smartweave/modules ``` ## Usage ### Setting up the contract In your project, create an `index.ts`. The modules allows you to

Downloads

2

Readme

SmartWeave modules

Overview

The goal of the project is to provide standardized modules which can be used by anyone.

Installation

yarn add @smartweave/modules

Usage

Setting up the contract

In your project, create an index.ts. The modules allows you to write SmartWeave Contracts in Typescript. Use can use this skeleton to get started:

import {ActionInterface, StateInterface} from "@smartweave/modules/faces";

declare const SmartWeave: any;

export async function handle(state: StateInterface, action: ActionInterface) {
  switch (action.input.function) {
   
    default:
      throw new ContractError(`${input.function} not implemented`);
  }
}

Using a module

To use a module, simply import it and register it in handle:

import {ActionInterface, StateInterface} from "@smartweave/modules/faces";
import {Transfer} from "@smartweave/modules/token/transfer";

export async function handle(state: StateInterface, action: ActionInterface) {
  switch (action.input.function) {
    case "transfer":
      return { state: Transfer(state, action) };
    default:
      throw new ContractError(`${input.function} not implemented`);
  }
}

Building the contract

Building the contract requires an extra script. Create a build.js script:

const { build } = require("esbuild");
const fs = require("fs");

(async () => {
  await build({
    entryPoints: ["./src/index.ts"],
    outfile: "./dist/index.js",
    format: "esm",
    bundle: true,
  });

  let src = fs.readFileSync("./dist/index.js").toString();
  src = src.replace("async function handle", "export async function handle");
  src = src.replace("export {\n  handle\n};\n", "");
  fs.writeFileSync("./dist/index.js", src);
})();

To run the script execute:

node build.js

Deploying the contract

Deploying the contract requires an extra script. Copy your arweave-keyfile, create a deploy.js script and your initial state.json:

const Arweave = require("arweave");
const { createContract } = require("smartweave");
const fs = require("fs");

const client = new Arweave({
  host: "arweave.net",
  port: 443,
  protocol: "https",
});

const wallet = JSON.parse(fs.readFileSync("./arweave.json"));
const src = fs.readFileSync("./dist/index.js");
const state = fs.readFileSync("./scripts/state.json");

(async () => {
  const id = await createContract(client, wallet, src, state);
  console.log(id);
})();

To run the script execute:

node deploy.js