Skip to content

Getting Started

Using Algokit

The recommended way to get started with TEALScript is to use the Algokit template:

algokit init -t tealscript

This will set up a project repository with TEALScript, ESLint, algokit generate, and some tests.

More information about how to use the template is provided in the template’s README.

Manual Installation

If you do not wish to use the above Algokit template, you can manually add TEALScript to any project with npm.

Installing TEALScript

TEALScript can be installed from npm via npm install @algorandfoundation/tealscript.

Writing First Contract

To write your first smart contract, import the Contract class and create a new class that extends Contract.

import { Contract } from '@algorandfoundation/tealscript';
class FirstContract extends Contract {

This is where all of the method definitions will go. You can then write a method that is typed and written like a regular TypeScript method:

import { Contract } from '@algorandfoundation/tealscript';
class FirstContract extends Contract {
add(a: uint64, b: uint64): uint64 {
return a + b
}
}

Compiling

To compile a TEALScript smart contract, run npx tealscript <file> [artifact directory]

  • <file> is the .ts file containing your TEALScript source code
  • [artifact directory] is an optional directory to output the artifacts generated by TEALScript. If a directory isn’t given, the current working directory will be used.

To learn more about method definitions and decorators for specific smart contract actions (such as creating, updating, or deleting the contract) see methods.

ESLint

Note: This is assuming you are extending the airbnb-base. Other standards might have additional rules that need to be disabled or modified.

If you are using ESLint, the following rules must be disabled:

ESLint RuleReason
object-shorthandObject shorthand is not yet supported by TEALScript
no-undefThe global TEALScript functions are not actually defined anywhere
class-methods-use-thisNot all methods will actually use this
max-classes-per-fileMultiple contracts can be defined in a single file
no-bitwiseBitwise operations are supported by TEALScript

.eslintrc.js

Rather than disabling these directly in the file, you can also create some rule overrides in your .eslintrc.js. For example, if you end all of your TEALScript contracts with .algo.ts you can add this to your config:

overrides: [
{
files: ['*.algo.ts'],
rules: {
'object-shorthand': 'off',
'class-methods-use-this': 'off',
'no-undef': 'off',
'max-classes-per-file': 'off',
'no-bitwise': 'off',
},
}
],