Giter Club home page Giter Club logo

tealscript's Introduction

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.

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.

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 {
  private getSum(a: number, b: number): number {
    return a + b;
  }

  private getDifference(a: number, b: number): number {
    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: number, b: number, operation: string): number {
    let result: number;

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

    return result;
  }
}

tealscript's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.