Getting Started
Using Algokit
The recommended way to get started with TEALScript is to use the Algokit template:
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
.
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:
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 Rule | Reason |
---|---|
object-shorthand | Object shorthand is not yet supported by TEALScript |
no-undef | The global TEALScript functions are not actually defined anywhere |
class-methods-use-this | Not all methods will actually use this |
max-classes-per-file | Multiple contracts can be defined in a single file |
no-bitwise | Bitwise 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: