goteal

module
v0.0.0-...-f6aa287 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2021 License: ISC

README

goteal

goteal enables writing Smart Contracts for Algorand in the Go programming language.

goteal achieves this by compiling Go programs into AVM/TEAL programs.

Why goteal

goteal exists to simplify the process of authoring and testing Algorand Smart Contracts for people that are familiar with the Go programming language.

Those familiar with Go know that the language and surrounding ecosystem offers many helpful tools. goteal exists to bridge the Go ecosystem with the Algorand Smart Contract ecosystem.

How goteal works

goteal takes a Go program that follows a few constraints (see below) and transpiles/compiles it to TEAL (Transaction Execution Approval Language) - the language that nodes in the Algorand network execute to validate and approve transactions.

Constraints

A TEAL program must exit with an integer value that indicates whether or not the transaction should proceed (zero for should-not-proceed, >0 for should-proceed). goteal expects a package that is being compiled to TEAL to expose the following interface:


func Contract(globals types.Globals, gtxn types.GroupTransaction, txn types.Transaction) (int,
error)

Where if any non-nil error is returned the program will halt (and reject the transaction).

Interface

When an Algorand Smart Contract is executing there are several important sources of context:

  • globals - contains network-wide information including values of current global configuration parameters.
  • txn - The current Transaction.
  • gtxn - The current Transaction Group (a Transaction in Algorand may be part of a group).

Compiling a contract with goteal

You compile a go program to TEAL program with the following pattern:

goteal build github.com/yourname/yourproject/contract1

This will leverage your current Go environment to find source code in the contract1 package, will find the Contract() entrypoint (as defined above) and output to stdout the TEAL program equivalent.

You can output direct bytecode by supplying the -o bytecode argument.

Important subcommands

goteal vet

goteal intends to encourage common patterns and warn contract authors about common missteps or errors in contract development. The goteal vet subcommand will run your contract through several static analysis checks to help guide you in your contract authorship.

Example usage: goteal vet github.com/yourname/yourproject/contract1

goteal vet will output in a standard format any issues that are detected in your contract design.

goteal test

goteal leverages the rich testing ecosystem from the Go programming language and makes it easy to write tests that verify the behavior of your contract.

By placing your test code into *_test.go files in your package directory you can easily test your contract via goteal test:

Example usage: goteal test github.com/yourname/yourproject/contract1

Example Contracts

The examples subdirectory contains a number of example contracts.

Directories

Path Synopsis
Package avm defines the set of functions exposed by the AVM (Algorand Virtual Machine).
Package avm defines the set of functions exposed by the AVM (Algorand Virtual Machine).
cmd
examples
Package types defines the set of relevant types for Algorand Smart Contracts.
Package types defines the set of relevant types for Algorand Smart Contracts.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL