Compiling and executing Teal opcodes

How do I compile and execute a teal code in python without using goal?

You can use pyteal to create the TEAL or handwrite it. To use with the SDKs look at:
https://developer.algorand.org/docs/features/asc1/sdks/

Pyteal - https://developer.algorand.org/articles/pyteal-writing-algorand-smart-contracts-in-python/

Additionally a new endpoint will be available very shortly. This endpoint will allow compiling TEAL directly. from the SDKs.

1 Like

I can’t wait to use it. It’s tough trying to compile teal without goal. I’m done writing the pyteal codes but compiling to use within a transaction is my headache right now.

1 Like

Actually, the REST API is available … and as @jsaonw says the SDKs will support this very shortly. https://github.com/algorand/go-algorand/tree/master/daemon/algod/api

1 Like

ok great. but I need a help right now.

DISCLAIMER: This is an advanced response and includes limited documentation or lacks an example describing usage. A tutorial will be released in the coming weeks describing how to use this feature in detail.

@ddev I think you got this :+1: Currently the master branch of go-algorand contains the REST API /v2/teal/compile which does exactly what you want. You POST your TEAL source code and it returns the program bytes and the contract address. We don’t yet have documentation posted, nor a tutorial to guide you through it use, so try this:

  1. First, you must enable the Developer API on your local algod node. Locate the “config.json” file within the data directory for your local node.
  2. Add the following json:
    "EnableDeveloperAPI": true
  3. Restart your algod node so it reads this new configuration value
  4. Use the following REST API excerpt to learn how to POST your data and the expected response:

POST /v2/teal/compile

Compile TEAL source code to binary, produce its hash

POST /v2/teal/compile

Description
Given TEAL source code in plain text, return base64 encoded program bytes and base32 SHA512_256 hash of program bytes (Address style).

Parameters

Type Name Description Schema
Body source
required
TEAL source code to be compiled string (binary)

Responses

HTTP Code Description Schema
200 Teal compile Result Response 200
400 Bad Request - Teal Compile Error ErrorResponse
401 Invalid API Token ErrorResponse
500 Internal Error ErrorResponse
default Unknown Error No Content


Response 200

Name Description Schema
hash
required
base32 SHA512_256 of program bytes (Address style) string
result
required
base64 encoded program bytes string

Consumes

  • text/plain

Produces

  • application/json

oh great. That gives what I expect. Now I understand how the opcodes is converted. I’m gonna try compiling it from the editor cos I can’t access a node right now. Thanks again RyanRfox.

You can also use https://algodesk.io/teal/ to quickly compile TEAL smart contracts.

Since you don’t run your own node @ddev , i am fairly certain you can use this api with a Purestake node. Ping them and see if “EnableDeveloperAPI”: true is set. Good suggestion from @fabrice too.

1 Like

Cool. I’ll do just that now. Thank you.