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

beaker-ts

v0.1.2

Published

> :warning: **Experimental. Zero tests. Please report issues**

Downloads

595

Readme

Beaker Typescript Client Generator

:warning: Experimental. Zero tests. Please report issues

Generate an ApplicationSpec

Use beaker-pyteal to create an Application and write the ApplicationSpec to json

import json
import pyteal as pt
from beaker import Application

# Create a new Application
hello_app = Application("HelloBeaker")

# Add method handler
@hello_app.external
def hello(name: pt.abi.String, *, output: pt.abi.String) -> pt.Expr:
    # Set output to the result of `Hello, `+name
    return output.set(pt.Concat(pt.Bytes("Hello, "), name.get()))

if __name__ == "__main__":
  # Writes contract.json, HelloBeaker.json, approval.teal, and clear.teal 
  # to the `artifacts` directory
  hello_app.build().export("artifacts")

The ApplicationSpec contains the ARC4 ABI spec with some extra bits to help the client

Generate a TypeScript Client

In a node project directory install beaker-ts

npm install beaker-ts

Generate the client using the beaker-ts generate command

$ npx beaker help generate

Usage: beaker-ts generate [options] <path-to-spec> <path-to-write>

Generates an application client given an application spec

Options:
  -l, --local  whether or not to use local import
  -h, --help   display help for command

Example:

npx beaker generate examples/hello/hello.json examples/hello/

This should create a new file called hellobeaker_client.ts

The client can now be imported and used to create or call the app methods by name and with expected types.

// Helpers to get accounts and algod client for sandbox
import * as bkr from "beaker-ts";

// Our autogenerated client
import {HelloBeaker} from "./hellobeaker_client";

(async function () {

  // Grab an account
  const acct = (await bkr.sandbox.getAccounts()).pop();
  if (acct === undefined) return;

  // Create a new client that will talk to our app
  // Including a signer lets it worry about signing
  // the app call transactions 
  const appClient = new HelloBeaker({
    client: bkr.clients.sandboxAlgod(),
    signer: acct.signer,
    sender: acct.addr,
  });

  // Deploy our app on chain (Only works if the ApplicationSpec was used to generate the client)
  const {appId, appAddress, txId} = await appClient.createApplication();
  console.log(`Created app ${appId} with address ${appAddress} in tx ${txId}`);

  // Call the method by name, with named and typed arguments
  const result = await appClient.hello({name: "Beaker"});
  // Get a typed result back from our app call
  console.log(result.value); // Hello, Beaker

})();

See the examples directory for usage examples.

Please report issues