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
from beaker import Application
class HelloBeaker(Application):
@external
def hello(self, name: abi.String, *, output: abi.String):
return output.set(Concat(Bytes("Hello, "), name.get()))
with open("hello.json", "w") as f:
f.write(json.dumps(HelloBeaker.application_spec()))
This spec 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 generate
command
$ npx beaker help generate
Usage: beaker 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!
import * as bkr from "beaker-ts";
import {HelloBeaker} from "./hellobeaker_client";
(async function () {
const acct = (await bkr.sandbox.getAccounts()).pop();
if (acct === undefined) return;
const appClient = new HelloBeaker({
client: bkr.sandbox.getAlgodClient(),
signer: acct.signer,
sender: acct.addr,
});
const [appId, appAddr, txId] = await appClient.create();
console.log(`Created app ${appId} with address ${appAddr} in tx ${txId}`);
const result = await appClient.hello({name: "Beaker"});
console.log(result.value);
})();
See the examples directory for usage examples.
Please report issues