Skip to content

Code Examples

Browse 18 runnable TypeScript examples demonstrating the Algorand TypeScript testing library. Each example is self-contained and demonstrates specific functionality.

# Clone the repository
git clone https://github.com/algorandfoundation/algorand-typescript-testing.git
cd algorand-typescript-testing

# Install dependencies
npm install

# Run any example
cd examples
npx tsx hello-world/contract.algo.ts
  • Node.js >= 20
  • npm
ExampleDescription
ARC4 Simple Voting Contract

Example source from examples/arc4-simple-voting/contract.algo.ts.

Auction

This example demonstrates a basic auction contract.

  • Create and initialize auction state
  • Opt the application account into an ASA
  • Start bidding and track highest bidder/bid
  • Let bidders claim refundable amounts
  • Transfer auctioned asset and close application
Calculator Contract

Example source from examples/calculator/contract.algo.ts.

Hello World Contract

Example source from examples/hello-world/contract.algo.ts.

Hello World ABI Contract

Example source from examples/hello-world-abi/contract.algo.ts.

Htlc Logicsig Signature

Example source from examples/htlc-logicsig/signature.algo.ts.

Local Storage Contract

A contract demonstrating local storage functionality. This contract shows how to use local state storage in an Algorand smart contract, including initialization, reading, writing, and clearing of local state values. Local state is per-account storage that requires accounts to opt-in before use.

Marketplace Contract

Example source from examples/marketplace/contract.algo.ts.

Precompiled Precompiled Apps

This logic sig can be used to create a custodial account that will allow any transaction to transfer its funds/assets.

Precompiled Precompiled Factory

Example source from examples/precompiled/precompiled-factory.algo.ts.

Precompiled Precompiled Typed

Example source from examples/precompiled/precompiled-typed.algo.ts.

Proof Of Attendance Contract

Example source from examples/proof-of-attendance/contract.algo.ts.

Scratch Storage Contract

Example source from examples/scratch-storage/contract.algo.ts.

Simple Voting

This example demonstrates a minimal voting contract with paid votes.

  • Store topic and total votes in global state
  • Prevent double-voting via local state
  • Validate grouped payment + app call flow
  • Expose methods to set topic, cast vote, and read vote count
Tealscript Example

Example source from examples/tealscript/example.algo.ts.

Tealscript Teal Script Base

Example source from examples/tealscript/teal-script-base.algo.ts.

Voting Contract

Example source from examples/voting/contract.algo.ts.

ZK Whitelist

This example demonstrates whitelist admission backed by zk proof verification.

  • Store application metadata in global state
  • Verify proofs through a verifier application call
  • Normalize public inputs to the curve field modulus
  • Whitelist accounts in local state after successful proof checks
  • Query whitelist membership for opted-in accounts