Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

beaker-ts

Package Overview
Dependencies
Maintainers
1
Versions
73
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

beaker-ts

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

  • 0.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
53
decreased by-51.82%
Maintainers
1
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 29 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc