0.1.2 • Published 1 year ago

beaker-ts v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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

0.1.0-beta.2

1 year ago

0.1.0-beta.1

1 year ago

0.1.0-beta.0

1 year ago

0.0.82

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.96-beta.0

1 year ago

0.0.96-beta.1

1 year ago

0.0.95

1 year ago

0.0.90

1 year ago

0.0.91

1 year ago

0.0.92

1 year ago

0.0.93

1 year ago

0.0.94

1 year ago

0.0.80

1 year ago

0.0.81

1 year ago

0.0.70

1 year ago

0.0.60

1 year ago

0.0.61

1 year ago

0.0.40

2 years ago

0.0.42

2 years ago

0.0.43

2 years ago

0.0.44

2 years ago

0.0.45

2 years ago

0.0.46

2 years ago

0.0.47

2 years ago

0.0.37

2 years ago

0.0.38

2 years ago

0.0.39

2 years ago

0.0.35

2 years ago

0.0.36

2 years ago

0.0.51

2 years ago

0.0.52

2 years ago

0.0.53

2 years ago

0.0.54

2 years ago

0.0.55

2 years ago

0.0.50

2 years ago

0.0.48

2 years ago

0.0.49

2 years ago

0.0.21

2 years ago

0.0.22

2 years ago

0.0.23

2 years ago

0.0.24

2 years ago

0.0.25

2 years ago

0.0.30

2 years ago

0.0.31

2 years ago

0.0.32

2 years ago

0.0.33

2 years ago

0.0.34

2 years ago

0.0.26

2 years ago

0.0.27

2 years ago

0.0.28

2 years ago

0.0.29

2 years ago

0.0.20

2 years ago

0.0.19

2 years ago

0.0.18

2 years ago

0.0.17

2 years ago

0.0.16

2 years ago

0.0.15

2 years ago

0.0.14

2 years ago

0.0.13

2 years ago

0.0.12

2 years ago

0.0.11

2 years ago

0.0.10

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago