Skittles
Write smart contracts in TypeScript.
Skittles lets you write blockchain smart contracts using TypeScript — the language you already know. No new syntax to learn. Just write classes, use the types and features you're familiar with, and Skittles handles all the blockchain complexity for you.
What is a Smart Contract?
If you're new to blockchain development, here's what you need to know:
A smart contract is a program that runs on a blockchain (like Ethereum). Once deployed, it can hold funds, enforce rules, and execute automatically without any middleman.
Think of it like a vending machine:
- You put money in (send cryptocurrency)
- The contract follows its programmed rules
- You get something out (tokens, NFTs, or any other outcome)
- No middleman needed — it all happens automatically and transparently on the blockchain
Smart contracts are used to build decentralized applications (dApps) like token systems, NFT marketplaces, DeFi protocols, and much more.
import { address, msg, SkittlesEvent, Indexed } from "skittles";
export class Token {
Transfer: SkittlesEvent<{
from: Indexed<address>;
to: Indexed<address>;
value: number;
}>;
name: string = "My Token";
symbol: string = "TKN";
totalSupply: number = 0;
balances: Record<address, number> = {};
constructor(initialSupply: number) {
this.totalSupply = initialSupply;
this.balances[msg.sender] = initialSupply;
}
transfer(to: address, amount: number): boolean {
if (this.balances[msg.sender] < amount) {
throw new Error("Insufficient balance");
}
this.balances[msg.sender] -= amount;
this.balances[to] += amount;
this.Transfer.emit({ from: msg.sender, to, value: amount });
return true;
}
}
This contract creates a simple token with balances and transfers. The balances Record keeps track of how many tokens each address owns. The transfer method lets users send tokens to each other, checking that they have enough balance first. The Transfer event logs every transfer that happens, which is important for tracking activity on the blockchain.
Why Skittles?
You write TypeScript — the language you already know. No need to learn Solidity syntax, memory keywords, or blockchain-specific quirks.
You get full IDE support — autocomplete, type checking, go-to-definition, and refactoring all work out of the box. Your editor understands your contracts just like any other TypeScript code.
Skittles handles the blockchain complexity — automatic type conversions, visibility rules, state mutability, gas optimizations, and all the low-level details are managed for you.
Your contracts are tested with familiar tools — use Hardhat and Mocha/Chai for testing, the same tools TypeScript developers use for other projects. No special testing frameworks to learn.
Features
- Familiar types: Use
numberfor amounts and counters,stringfor text,booleanfor flags,addressfor wallet addresses,bytesfor raw data,Record<K,V>orMap<K,V>for key-value storage, arrays, type aliases for custom structures, interfaces, and enums - Class properties become persistent state variables — use
public,private,readonly, andstatic readonlyjust like in TypeScript - Methods work like you expect — automatic optimizations detect if your function only reads data or modifies state,
virtual/overridefor inheritance, getters/setters, plus specialreceive()andfallback()for handling payments - Events let you log activity on the blockchain — use
SkittlesEvent<T>withIndexed<T>to mark searchable parameters - Custom errors for better error messages — use
SkittlesError<T>or extend theErrorclass - Inheritance with
extendsandsuper— build modular, reusable contracts - Control flow — all the standard JavaScript patterns work:
if/else,for,while,do/while,for...of,for...in(enums),switch/case, ternary operators,try/catchfor external calls - Destructuring — array, tuple, and object destructuring for local variables and function return values
- Operators — arithmetic (
+,-,*,/,%,**), comparison, logical, bitwise, and compound assignment operators all work as expected - Blockchain globals — access
msg.sender(who called your function),msg.value(how much they sent),block.timestamp,block.number,tx.origin, and more - Built-in functions —
keccak256(),sha256(),ecrecover(),abi.encode(),abi.encodePacked()for cryptographic operations and data encoding, plusMath.min(),Math.max(),Math.sqrt(),Math.pow()for common math operations - Standard library — built-in ERC20, ERC20Permit, ERC20Votes, ERC721, Ownable, AccessControl, Pausable, and ReentrancyGuard contracts ready to extend, no extra packages needed
- Debugging —
console.log()support maps to Hardhat's console, and is automatically stripped from production builds - Multi-file projects — share types, constants, and functions across contract files
- Fast incremental builds — SHA256-based caching only recompiles what changed
Build Output
When you compile your TypeScript contracts, Skittles generates:
artifacts/
solidity/ # Generated contract source code
Run npx skittles to compile your contracts, then use Hardhat to test and deploy them. Everything works with standard Ethereum tools like ethers.js, viem, and Foundry.
Under the Hood
How does Skittles work? (Click to expand)
Under the hood, Skittles compiles your TypeScript to Solidity source code. This is great because:
- Auditable — Security professionals can review the generated Solidity code
- Verifiable — You can verify your contracts on Etherscan and other block explorers
- Compatible — Works with every EVM tool and deployment platform
- Transparent — The generated Solidity is human-readable and available in
build/solidity/
The compilation happens in three stages:
- Parse your TypeScript with the official TypeScript compiler
- Generate optimized Solidity code with proper types and visibility
- Output clean, readable Solidity source files
Want to learn more about how the compilation works? Check out the Under the Hood guide.
Next Steps
- Try the Playground — Try Skittles in your browser, no installation needed
- Installation — Get Skittles set up in your project
- Quick Start — Write and compile your first smart contract
- Type System — Learn what TypeScript features you can use
- Examples — See real contracts like tokens and NFTs