o1js

ℹ️ o1js is an evolution of SnarkyJS which saw 49 updated versions over two years of development with 43,141 downloads.
This name change to o1js reflects the evolution of our vision for the premiere toolkit used by developers to build zero knowledge-enabled applications, while paying homage to our technology's recursive proof generation capabilities.
Your favorite functionality stays the same and transitioning to o1js is a quick and easy process:
-
To update zkApp-cli, run the following command:
npm i -g zkapp-cli@latest
-
To remove the now-deprecated SnarkyJS package and install o1js, run the following command:
npm remove snarkyjs && npm install o1js
-
For existing zkApps, make sure to update your imports from
snarkyjs
too1js
-
No need to redeploy, you are good to go!
o1js
o1js helps developers build apps powered by zero knowledge (zk) cryptography.
The easiest way to write zk programs is using o1js.
o1js is a TypeScript library for zk-SNARKs and zkApps. You can use o1js to write zk smart contracts based on zero-knowledge proofs for the Mina Protocol.
o1js is automatically included when you create a project using the zkApp CLI.
Learn More
-
To learn more about developing zkApps, see the zkApp Developers docs.
-
For guided steps building and using zkApps, see the zkApp Developers Tutorials.
-
To meet other developers building zkApps with o1js, participate in the #zkapps-developers channel on Mina Protocol Discord.
-
For a list of changes between versions, see the CHANGELOG.
-
To stay up to date with o1js, see the O(1) Labs Blog.
Contributing
o1js is an open source project. We appreciate all community contributions to o1js!
See the Contributing guidelines for ways you can contribute.
Development Workflow
For guidance on building o1js from source and understanding the development workflow, see o1js README-dev.
Community Packages
High-quality community packages from open source developers are available for your project.
- o1js-elgamal A partially homomorphic encryption library for o1js based on Elgamal encryption: GitHub and npm
- o1js-pack A library for o1js that allows a zkApp developer to pack extra data into a single Field. GitHub and npm
- zk-regex-o1js A CLI tool for compiling ZK Regex circuits in o1js. Github and npm
- eddsa-o1js A library for provable EdDSA and Twisted Edwards Curve operations. Github and npm
To include your package, see Creating high-quality community packages.
Namespaces
Namespace | Description |
---|---|
Crypto | - |
Encryption | - |
Experimental | This module exposes APIs that are unstable, in the sense that the API surface is expected to change. (Not unstable in the sense that they are less functional or tested than other parts.) |
Lightnet | - |
Mina | - |
Classes
Class | Description |
---|---|
AccountUpdate | An AccountUpdate is a set of instructions for the Mina network. It includes Preconditions and a list of state updates, which need to be authorized by either a Signature or Proof. |
AccountUpdateForest | Class which represents a forest (list of trees) of account updates, in a compressed way which allows iterating and selectively witnessing the account updates. |
AccountUpdateTree | Class which represents a tree of account updates, in a compressed way which allows iterating and selectively witnessing the account updates. |
AlmostForeignField | - |
BaseMerkleWitness | The BaseMerkleWitness class defines a circuit-compatible base class for Merkle Witness. |
Bool | A boolean value. You can use it like this: |
CanonicalForeignField | - |
Character | - |
Circuit | - |
CircuitString | - |
DynamicProof | The DynamicProof class enables circuits to verify proofs using in-ciruit verfication keys. This is opposed to the baked-in verification keys of the Proof class. |
EcdsaSignature | - |
Field | A Field is an element of a prime order finite field. Every other provable type is built using the Field type. |
ForeignCurve | - |
ForeignCurveNotNeeded | @see: ForeignCurve |
ForeignField | - |
Group | An element of a Group. |
Hashed | Hashed<T> represents a type T by its hash. |
Int64 | A 64 bit signed integer with values ranging from -18,446,744,073,709,551,615 to 18,446,744,073,709,551,615. |
Keypair | - |
Ledger | Represents the Mina ledger. |
MerkleList | Dynamic-length list which is represented as a single hash |
MerkleListIterator | MerkleListIterator helps iterating through a Merkle list. This works similar to calling list.pop() or list.push() repeatedly, but maintaining the entire list instead of removing elements. |
MerkleMap | - |
MerkleMapWitness | - |
MerkleTree | A Merkle Tree is a binary tree in which every leaf is the cryptography hash of a piece of data, and every node is the hash of the concatenation of its two child nodes. |
Nullifier | Nullifiers are used as a public commitment to a specific anonymous account, to forbid actions like double spending, or allow a consistent identity between anonymous actions. |
Packed | Packed<T> is a "packed" representation of any type T . |
PrivateKey | A signing key. You can generate one via PrivateKey.random. |
Proof | - |
ProofBase | - |
PublicKey | A public key, which is also an address on the Mina network. You can derive a PublicKey directly from a PrivateKey. |
Scalar | Represents a Scalar. |
ScalarField | ForeignField representing the scalar field of Pallas and the base field of Vesta |
SelfProof | A class representing the type of Proof produced by the ZkProgram in which it is used. |
Sign | - |
Signature | A Schnorr Signature over the Pasta Curves. |
SmartContract | The main zkapp class. To write a zkapp, extend this class as such: |
TokenAccountUpdateIterator | Data structure to represent a forest of account updates that is being iterated over, in the context of a token manager contract. |
TokenContract | Base token contract which - implements the Approvable API, with the approveBase() method left to be defined by subclasses - implements the Transferable API as a wrapper around the Approvable API |
TokenSymbol | - |
UInt32 | A 32 bit unsigned integer with values ranging from 0 to 4,294,967,295. |
UInt64 | A 64 bit unsigned integer with values ranging from 0 to 18,446,744,073,709,551,615. |
UInt8 | A 8 bit unsigned integer with values ranging from 0 to 255. |
Unconstrained | Container which holds an unconstrained value. This can be used to pass values between the out-of-circuit blocks in provable code. |
UnreducedForeignField | - |
VerificationKey | - |
Interfaces
Interface | Description |
---|---|
Permissions | Permissions specify how specific aspects of the zkapp account are allowed to be modified. All fields are denominated by a Permission. |
Type Aliases
Type alias | Description |
---|---|
Account | - |
Bool | - |
BoolVar | - |
Bytes | - |
Cache | Interface for storing and retrieving values, for caching. read() and write() can just throw errors on failure. |
CacheHeader | A header that is passed to the caching layer, to support rich caching strategies. |
ConstantField | - |
DeployArgs | - |
Empty | - |
FeatureFlags | - |
Field | - |
FlexibleBytes | - |
FlexiblePoint | - |
FlexibleProvable | - |
FlexibleProvablePure | - |
Group | - |
InferProvable | - |
JsonProof | Serializable representation of a Pickles proof, useful for caching compiled proofs. |
MemoizationContext | - |
MerkleListBase | Common base type for MerkleList and MerkleListIterator |
MerkleListIteratorBase | - |
Option | - |
Provable | Provable<T> is the general interface for provable types in o1js. |
Provable | Provable<T> is the general interface for provable types in o1js. |
ProvableExtended | - |
ProvableHashable | - |
ProvableHashable | - |
ProvablePure | ProvablePure<T> is a special kind of Provable interface, where the "auxiliary" (non-provable) data is empty. This means the type consists only of field elements, in that sense it is "pure". Any instance of ProvablePure<T> is also an instance of Provable<T> where the "auxiliary" data is empty. |
ProvablePureExtended | - |
ProvableType | - |
ProvableTypePure | - |
ProvableWithEmpty | - |
Reducer | - |
ScalarConst | - |
State | Gettable and settable state that can be checked for equality. |
Struct | - |
ToProvable | - |
TransactionPromise | A Promise<Transaction> with some additional methods for making chained method calls into the pending value upon its resolution. |
TransactionStatus | INCLUDED: A transaction that is on the longest chain |
TupleN | tuple type that has the length as generic parameter |
Undefined | - |
VarField | - |
Void | - |
WithHash | - |
WithProvable | - |
Witness | - |
ZkappPublicInput | The public input for zkApps consists of certain hashes of the proving account update (and its child updates) which is constructed during method execution. |
ZkProgram | - |
Variables
Variable | Description |
---|---|
Account | - |
Bool | A boolean value. You can create it like this: |
Cache | - |
Crypto | - |
Empty | - |
emptyHash | - |
FeatureFlags | Feature flags indicate what custom gates are used in a proof of circuit. Side loading, for example, requires a set of feature flags in advance (at compile time) in order to verify and side load proofs. If the side loaded proofs and verification keys do not match the specified feature flag configurations, the verification will fail. Flags specified as undefined are considered as maybe by Pickles. This means, proofs can be sided loaded that can, but don't have to, use a specific custom gate. Note: Maybe feature flags incur a proving overhead. |
Field | A Field is an element of a prime order finite field. Every other provable type is built using the Field type. |
Gadgets | - |
Group | An element of a Group. |
Hash | A collection of hash functions which can be used in provable code. |
Keccak | - |
Permissions | - |
Poseidon | - |
Provable | - |
ProvableType | - |
TokenId | - |
TransactionVersion | - |
TupleN | - |
Undefined | - |
Void | - |
ZkappPublicInput | - |
Functions
Function | Description |
---|---|
addCachedAccount | Adds an account to the local cache, indexed by a GraphQL endpoint. |
assert | Assert that a statement is true. If the statement is false, throws an error with the given message. Can be used in provable code. |
Bytes | A provable type representing an array of bytes. |
checkBitLength | - |
checkZkappTransaction | - |
circuitMain | - |
conditionalSwap | - |
ConstantField | - |
createEcdsa | Create a class EcdsaSignature for verifying ECDSA signatures on the given curve. |
createForeignCurve | Create a class representing an elliptic curve group, which is different from the native Group. |
createForeignField | Create a class representing a prime order finite field, which is different from the native Field. |
declareMethods | declareMethods can be used in place of the @method decorator to declare SmartContract methods along with their list of arguments. It should be placed after the class declaration. Here is an example of declaring a method update , which takes a single argument of type Field : class MyContract extends SmartContract { // ... update(x: Field) { // ... } } declareMethods(MyContract, { update: [Field] }); // [Field] is the list of arguments! Note that a method of the same name must still be defined on the class, just without the decorator. |
declareState | declareState can be used in place of the @state decorator to declare on-chain state on a SmartContract. It should be placed after the class declaration. Here is an example of declaring a state property x of type Field . class MyContract extends SmartContract { x = State<Field>(); // ... } declareState(MyContract, { x: Field }); |
fetchAccount | Gets account information on the specified publicKey by performing a GraphQL query to the specified endpoint. This will call the 'GetAccountInfo' query which fetches zkapp related account information. |
fetchEvents | Asynchronously fetches event data for an account from the Mina Archive Node GraphQL API. |
fetchLastBlock | Fetches the last block on the Mina network. |
fetchTransactionStatus | Fetches the status of a transaction. |
genericHash | - |
getBlindingValue | - |
initializeBindings | A function that has to finish before any bindings exports can be used. |
memoizationContext | - |
memoizeWitness | Like Provable.witness, but memoizes the witness during transaction construction for reuse by the prover. This is needed to witness non-deterministic values. |
MerkleListBase | - |
merkleListHash | - |
MerkleWitness | Returns a circuit-compatible Witness for a specific Tree height. |
method | A decorator to use in a zkApp to mark a method as provable. You can use inside your zkApp class as: |
Option | Define an optional version of a provable type. |
provable | - |
provableFromClass | - |
provablePure | - |
public_ | - |
readVarMessage | - |
Reducer | - |
sendZkapp | Sends a zkApp command (transaction) to the specified GraphQL endpoint. |
setArchiveGraphqlEndpoint | Sets up a GraphQL endpoint to be used for fetching information from an Archive Node. |
setGraphqlEndpoint | - |
setGraphqlEndpoints | - |
setNumberOfWorkers | Set the number of workers to use for parallelizing the proof generation. By default the number of workers is set to the number of physical CPU cores on your machine, but there may be some instances where you want to set the number of workers manually. Some machines may have a large number of cores, but not enough memory to support that many workers. In that case, you can set the number of workers to a lower number to avoid running out of memory. On the other hand, some machines with heterogeneous cores may benefit from setting the number of workers to a lower number to avoid contention between core types if load-link/store-conditional multithreading is used. Feel free to experiment and see what works best for your use case. Maybe you can squeeze slightly more performance out by tweaking this value :) |
state | A decorator to use within a zkapp to indicate what will be stored on-chain. For example, if you want to store a field element some_state in a zkapp, you can use the following in the declaration of your zkapp: |
State | - |
Struct | Struct lets you declare composite types for use in o1js circuits. |
toConstantField | - |
toFp | - |
toPoint | - |
VarField | - |
verify | Initializes Pickles bindings, serializes the input proof and verification key for use in OCaml, then calls into the Pickles verify function and returns the result. |
WithHash | - |
withHashes | - |
withMessage | - |
ZkProgram | Wraps config + provable code into a program capable of producing Proofs. |