0.92.0 • Published 13 days ago

@algorandfoundation/tealscript v0.92.0

Weekly downloads
-
License
-
Repository
-
Last release
13 days ago

TEALScript

TEALScript is a subset of TypeScript that can be compiled into TEAL. The goal is to enable developers to write Algorand Smart Contracts using native TypeScript syntax. Since TEALScript uses native TypeScript syntax, IDE support works out of the box for any IDE that supports TypeScript.

Status

TEALScript is a work in progress and not production-ready. The current version is 0.x.x. This means there will be frequent changes being made, including breaking changes, without incrementing the MAJOR version number.

Documentation

The documentation for the latest release can be viewed at tealscript.algo.xyz and can be generated locally with yarn docs

Example Contract

The artifacts for this contract can be seen in examples/calculator/artifacts. Note that the TypeDoc comment is used when generating the ABI JSON

import { Contract } from '../../src/lib/index';

class Calculator extends Contract {
  /**
   * Calculates the sum of two numbers
   *
   * @param a
   * @param b
   * @returns The sum of a and b
   */
  private getSum(a: uint64, b: uint64): uint64 {
    return a + b;
  }

  /**
   * Calculates the difference between two numbers
   *
   * @param a
   * @param b
   * @returns The difference between a and b.
   */
  private getDifference(a: uint64, b: uint64): uint64 {
    return a >= b ? a - b : b - a;
  }

  /**
   * A method that takes two numbers and does either addition or subtraction
   *
   * @param a The first number
   * @param b The second number
   * @param operation The operation to perform. Can be either 'sum' or 'difference'
   *
   * @returns The result of the operation
   */
  doMath(a: uint64, b: uint64, operation: string): uint64 {
    let result: uint64;

    if (operation === 'sum') {
      result = this.getSum(a, b);
    } else if (operation === 'difference') {
      result = this.getDifference(a, b);
    } else throw Error('Invalid operation');

    return result;
  }
}

Differences from TypeScript

While TEALScript is a subset of TypeScript, it does function differently in some cases.

Types Affect Behavior

In TypeScript, using types, as expressions, or type arguments don't affect the compiled JS. In TEALScript, however, types fundamentally change the compiled TEAL.

For example, the literal expression 1 results in int 1 in TEAL, but 1 as uint8 results in byte 0x01. This also means that arithmetic is done differently on these numbers and they have different overflow protections.

Numbers Can Be Bigger

In TypeScript, numeric literals with absolute values equal to 2^53 or greater are too large to be represented accurately as integers. In TEALScript, however, numeric literals can be much larger (up to 2^512) if properly type casted as uint512.

Types May Be Required

All JavaScript is valid TypeScript, but that is not the case with TEALScript. In certain cases, types are required and the compiler will throw an error if they are missing. For example, types are always required when defining a method or when defining an array.

0.92.0

13 days ago

0.91.0

16 days ago

0.91.1

16 days ago

0.90.4

18 days ago

0.90.3

26 days ago

0.90.1

1 month ago

0.90.2

1 month ago

0.90.0

1 month ago

0.89.0

1 month ago

0.88.1

2 months ago

0.87.0

2 months ago

0.88.0

2 months ago

0.86.0

3 months ago

0.85.0

3 months ago

0.83.1

3 months ago

0.84.0

3 months ago

0.83.0

3 months ago

0.82.2

3 months ago

0.82.0

3 months ago

0.82.1

3 months ago

0.81.0

3 months ago

0.80.0

3 months ago

0.80.1

3 months ago

0.78.0

3 months ago

0.78.1

3 months ago

0.79.2

3 months ago

0.79.1

3 months ago

0.79.0

3 months ago

0.77.0

4 months ago

0.76.1

4 months ago

0.76.0

4 months ago

0.75.2

4 months ago

0.75.1

4 months ago

0.75.0

4 months ago

0.74.0

4 months ago

0.73.5

4 months ago

0.73.4

4 months ago

0.73.1

4 months ago

0.73.3

4 months ago

0.73.2

4 months ago

0.73.0

4 months ago

0.71.1

4 months ago

0.71.0

4 months ago

0.72.1

4 months ago

0.72.0

4 months ago

0.70.1

4 months ago

0.70.0

4 months ago

0.69.0

4 months ago

0.68.3

4 months ago

0.68.2

4 months ago

0.68.1

4 months ago

0.68.0

4 months ago

0.67.3

4 months ago

0.67.0

4 months ago

0.67.2

4 months ago

0.67.1

4 months ago

0.66.1

5 months ago

0.66.0

5 months ago

0.64.0

6 months ago

0.65.0

5 months ago

0.63.1

6 months ago

0.62.1

6 months ago

0.62.0

6 months ago

0.62.2

6 months ago

0.60.1

6 months ago

0.63.0

6 months ago

0.61.0

6 months ago

0.60.0

6 months ago

0.59.0

7 months ago

0.57.2

7 months ago

0.59.1

6 months ago

0.57.0

7 months ago

0.57.1

7 months ago

0.55.0

7 months ago

0.55.1

7 months ago

0.58.0

7 months ago

0.56.0

7 months ago

0.41.1

8 months ago

0.43.0

8 months ago

0.41.2

8 months ago

0.20.0

10 months ago

0.41.0

8 months ago

0.19.0

10 months ago

0.17.2

11 months ago

0.38.0

9 months ago

0.36.0

9 months ago

0.34.0

9 months ago

0.17.0

11 months ago

0.17.1

11 months ago

0.53.0

7 months ago

0.32.0

9 months ago

0.51.0

7 months ago

0.30.0

9 months ago

0.51.1

7 months ago

0.29.0

10 months ago

0.27.2

10 months ago

0.27.1

10 months ago

0.48.0

7 months ago

0.46.0

7 months ago

0.25.0

10 months ago

0.46.1

7 months ago

0.44.0

8 months ago

0.23.0

10 months ago

0.27.3

10 months ago

0.42.0

8 months ago

0.21.0

10 months ago

0.40.0

8 months ago

0.18.1

10 months ago

0.39.0

8 months ago

0.37.0

9 months ago

0.35.0

9 months ago

0.33.0

9 months ago

0.16.0

11 months ago

0.18.0

10 months ago

0.31.1

9 months ago

0.54.0

7 months ago

0.31.0

9 months ago

0.52.0

7 months ago

0.50.0

7 months ago

0.28.0

10 months ago

0.26.2

10 months ago

0.47.1

7 months ago

0.26.1

10 months ago

0.49.0

7 months ago

0.26.0

10 months ago

0.47.0

7 months ago

0.24.0

10 months ago

0.43.1

8 months ago

0.45.0

7 months ago

0.43.2

8 months ago

0.22.0

10 months ago

0.13.0

12 months ago

0.14.0

11 months ago

0.15.0

11 months ago

0.11.0

1 year ago

0.12.0

12 months ago

0.12.1

12 months ago

0.10.0

1 year ago

0.10.1

1 year ago

0.9.0

1 year ago

0.10.2

1 year ago

0.8.2

1 year ago

0.8.1

1 year ago