Jstz Documentation

website·Indexed 39 days ago

https://jstz.tezos.com

A runtime layer on top of the Tezos blockchain that allows developers to write and deploy smart functions using TypeScript. Jstz provides a serverless-like environment with a CLI, a local sandbox for testing, and a client SDK for web applications. It includes implementations of Web standard APIs such as Fetch (Request, Response, Headers), URL, URLPattern, and TextDecoder, as well as a key-value database for persistent data storage.

Tokens
17.4K
Snippets
107
Records
146
Agent score
53%

What's inside Jstz

  1. Overview of jstz URLPattern implementation

    The jstz implementation of URLPattern is based on the WHATWG URL Pattern specification and utilizes rust-urlpattern. Note that this implementation is not fully spec-compliant.
  2. Overview of jstz URLSearchParams

    The URLSearchParams API in jstz provides utility methods for working with the query string of a URL according to the URL specification. It is used for building and manipulating search parameters.
    // Parse query string from URL
    let url = new URL("https://example.com?foo=1&bar=2");
    let params = new URLSearchParams(url.search);
    
    // Add a new parameter
    params.append("baz", 3);
    
    // Remove parameter
    params.delete("bar");
  3. Overview of Jstz CLI commands

    The Jstz CLI is used to interact with the Jstz environment, manage accounts, start the sandbox, and deploy/interact with smart functions.

    Key global commands include:

    • jstz help: Displays help information.
    • jstz --version (-V): Displays the current version.
    • jstz whoami: Prints the current active account.
    • jstz login <ALIAS>: Sets the active account used to send requests.
    • jstz logout: Deselects the current active account.

    Many commands require the -n or --network flag to specify the environment (e.g., -n dev for the local sandbox).

  4. Overview of Jstz Smart Functions

    Jstz allows developers to deploy JavaScript/TypeScript applications as 'smart functions'. These function similarly to serverless applications but operate on distributed Jstz Smart Rollup nodes, providing the following Web3 advantages:

    • Persistence & Immutability: Functions are transparent and cannot be changed or shut down once deployed.
    • Censorship Resistance: Because they are deployed on distributed nodes, calls to these functions cannot be blocked.
    • Cost Model: There are no long-term hosting costs; costs are only incurred when the smart function is called.
  5. Understand Jstz Runtime and Smart Rollup Architecture

    The Jstz runtime operates as a layer on top of the Tezos blockchain network. It is hosted by a cluster of Tezos Smart Rollup nodes that are responsible for accepting smart function deployments, maintaining storage, and executing smart function logic. To ensure security, these nodes publish 'commitments' (reports of the Jstz state, including storage and user accounts) to the Tezos blockchain. If commitments between nodes mismatch, the Smart Rollup framework is used to determine the correct state by stepping through transactions.
  6. Understand Jstz smart function atomicity and rollbacks

    Jstz processes calls to smart functions as an atomic unit. If any smart function in a chain of calls throws an uncaught error, the entire transaction is reverted. This rollback includes:

    • Restoring the storage of every smart function in the chain to its state before the initial request.
    • Restoring the XTZ balance of each smart function to its state before the initial request.
    • Cancelling any further requests generated by the smart functions in that chain.
  7. Explore Jstz smart function examples

    The Jstz source code repository contains a collection of example smart functions and applications that demonstrate various capabilities of the platform, including data storage, currency transfers, and library integrations.
    # Browse all examples on GitHub
    https://github.com/jstz-dev/jstz/tree/main/examples
  8. Use the jstz Encoding API

    The jstz library provides an implementation of the Web standard encoding API for handling text in various character encodings. Note that the jstz implementation is not fully spec compliant. Available interfaces include TextEncoder, TextDecoder, atob, and btoa.
  9. Understand jstz runtime API availability and stability

    jstz is a JavaScript server runtime running on Tezos's smart optimistic rollups. Because of this environment, certain standard Web APIs (such as the DOM) are not available. Note that jstz APIs are currently unstable and may not be fully compliant with official specifications.
  10. Understand Jstz smart function architecture

    Jstz smart functions are JavaScript/TypeScript applications that behave like serverless functions running on the Tezos blockchain via Smart Rollup technology.

    Key characteristics:

    • Persistence: They are immutable once deployed and persistent.
    • State Management: They use a built-in key-value store (Kv) for persistent data. Only the function itself can write to its storage, though data is publicly visible via the client API.
    • Entrypoint: Every smart function must have a handler function as the sole entrypoint. This handler receives a Request object (containing the caller's address in the Referer header) and must return a Response object or a promise of one.
    • Deployment: Once deployed, they are assigned a unique KT1 address and are accessible via a URL: jstz://<ADDRESS>/.
  11. Understand Jstz smart function architecture

    Smart functions in Jstz are serverless applications that run only when called and have no long-term presence on a server. They are stateless; any global variables are reset upon each execution, and concurrent instances cannot share state. To persist data, smart functions must use the Jstz key-value store. They are permissionless (anyone can call them), immutable after deployment, and transparent (code and storage are public).
  12. Understand Jstz account types

    Jstz utilizes two distinct types of accounts:

    • User accounts: Identified by addresses starting with tz1. These are used to store tez (XTZ).
    • Smart function accounts: Identified by addresses starting with KT1. These store tez and the immutable code of the smart function.