Skip to main content

EVM Globals

Skittles provides typed stubs for all standard EVM global objects and built in functions. Import them from "skittles" and use them directly in your contracts.

Transaction Context

import { msg, block, tx } from "skittles";

msg

PropertySolidityTypeDescription
msg.sendermsg.senderaddressAddress of the caller
msg.valuemsg.valueuint256ETH sent with the call (makes function payable)
msg.datamsg.databytesRaw calldata
class Token {
owner: address = msg.sender;

deposit(): void {
// Accessing msg.value makes this function payable
this.balances[msg.sender] += msg.value;
}
}

block

PropertySolidityTypeDescription
block.timestampblock.timestampuint256Current block timestamp
block.numberblock.numberuint256Current block number
block.chainidblock.chainiduint256Chain ID
block.coinbaseblock.coinbaseaddressBlock miner/validator address
class Staking {
private depositTimestamps: Record<address, number> = {};

deposit(): void {
this.depositTimestamps[msg.sender] = block.timestamp;
}
}

tx

PropertySolidityTypeDescription
tx.origintx.originaddressOriginal sender of the transaction
tx.gaspricetx.gaspriceuint256Gas price of the transaction

self

Use the keyword self to reference the contract's own address:

let contractAddress: address = self;
// Generates: address(this)

Built In Functions

Import built in functions from "skittles":

import { keccak256, sha256, ecrecover, abi, gasleft } from "skittles";

Hashing

FunctionSolidityDescription
keccak256(...)keccak256(abi.encodePacked(...))Keccak256 hash
sha256(...)sha256(abi.encodePacked(...))SHA256 hash
hash(...)keccak256(abi.encodePacked(...))Alias for keccak256
let digest: string = keccak256(msg.sender, amount);
// Generates: bytes32 digest = keccak256(abi.encodePacked(msg.sender, amount));

ABI Encoding

FunctionSolidityDescription
abi.encode(...)abi.encode(...)ABI encode
abi.encodePacked(...)abi.encodePacked(...)Packed ABI encode
abi.decode(...)abi.decode(...)ABI decode

Cryptography

FunctionSolidityDescription
ecrecover(hash, v, r, s)ecrecover(hash, v, r, s)Recover signer from signature

Math

FunctionSolidityDescription
addmod(x, y, k)addmod(x, y, k)(x + y) % k with overflow protection
mulmod(x, y, k)mulmod(x, y, k)(x * y) % k with overflow protection

Utilities

FunctionSolidityDescription
assert(condition)assert(condition)Assert a condition (panics on failure)
gasleft()gasleft()Remaining gas

String and Bytes Concatenation

FunctionSolidityDescription
string.concat(...)string.concat(...)Concatenate strings
bytes.concat(...)bytes.concat(...)Concatenate bytes

Template literals are automatically compiled to string.concat():

let greeting: string = `Hello ${name}!`;
// Generates: string memory greeting = string.concat("Hello ", name, "!");

Special Values

TypeScriptSolidityDescription
Number.MAX_VALUEtype(uint256).maxMaximum uint256 value
null0Zero value
undefined0Zero value