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 Mina 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
To include your package, see Creating high-quality community packages.
Member | Description |
---|---|
Crypto | - |
Encryption | - |
Experimental | This module exposes APIs that are unstable, in the sense that the API surface is expected to change. |
Lightnet | - |
Mina | - |
AccountUpdate | An AccountUpdate is a set of instructions for the Mina network. |
AccountUpdateForest | Class which represents a forest (list of trees) of account updates, |
AccountUpdateTree | Class which represents a tree of 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 | - |
EcdsaSignature | - |
Field | A Field is an element of a prime order finite field. |
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. |
MerkleMap | - |
MerkleMapWitness | - |
MerkleTree | A Merkle Tree is a binary tree in which every leaf is the cryptography hash of a piece of data, |
Nullifier | Nullifiers are used as a public commitment to a specific anonymous account, |
Packed | Packed<T> is a "packed" representation of any type T . |
PrivateKey | A signing key. You can generate one via PrivateKey.random. |
Proof | - |
PublicKey | A public key, which is also an address on the Mina network. |
Scalar | Represents a Scalar. |
SelfProof | - |
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, |
TokenContract | Base token contract which |
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 |
VerificationKey | - |
Permissions | Permissions specify how specific aspects of the zkapp account are allowed |
Account | - |
Bool | - |
BoolVar | - |
Bytes | - |
Cache | Interface for storing and retrieving values, for caching. |
CacheHeader | A header that is passed to the caching layer, to support rich caching strategies. |
ConstantField | - |
DeployArgs | - |
Empty | - |
Field | - |
FlexibleProvable | - |
FlexibleProvablePure | - |
Group | - |
InferProvable | - |
JsonProof | - |
MerkleListBase | Common base type for MerkleList and MerkleListIterator |
MerkleListIteratorBase | - |
Provable | Provable<T> is the general interface for provable types in o1js. |
ProvableExtended | - |
ProvableHashable | - |
ProvablePure | ProvablePure<T> is a special kind of Provable interface, where the "auxiliary" (non-provable) data is empty. |
Reducer | - |
ScalarConst | - |
State | Gettable and settable state that can be checked for equality. |
Struct | - |
TransactionPromise | A Promise<Transaction> with some additional methods for making chained method calls |
TransactionStatus | INCLUDED: A transaction that is on the longest chain |
Undefined | - |
VarField | - |
Void | - |
WithHash | - |
Witness | - |
ZkProgram | - |
ZkappPublicInput | The public input for zkApps consists of certain hashes of the proving |
Account | - |
Bool | A boolean value. You can create it like this: |
Cache | - |
Crypto | - |
Empty | - |
Field | A Field is an element of a prime order finite field. |
Gadgets | - |
Group | An element of a Group. |
Hash | A collection of hash functions which can be used in provable code. |
Keccak | - |
Permissions | - |
Poseidon | - |
TokenId | - |
TransactionVersion | - |
Undefined | - |
Void | - |
ZkappPublicInput | - |
emptyHash | - |
Bytes | A provable type representing an array of bytes. |
ConstantField | - |
MerkleListBase | - |
MerkleWitness | Returns a circuit-compatible Witness for a specific Tree height. |
Reducer | - |
State | - |
Struct | Struct lets you declare composite types for use in o1js circuits. |
VarField | - |
WithHash | - |
ZkProgram | - |
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. |
checkBitLength | - |
checkZkappTransaction | - |
circuitMain | - |
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 |
declareState | declareState can be used in place of the @state decorator to declare on-chain state on a SmartContract. |
fetchAccount | Gets account information on the specified publicKey by performing a GraphQL query |
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 | - |
initializeBindings | A function that has to finish before any bindings exports can be used. |
maybeSwap | - |
merkleListHash | - |
method | A decorator to use in a zkApp to mark a method as provable. |
provable | - |
provablePure | - |
public_ | - |
readVarMessage | - |
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. |
toConstantField | - |
toFp | - |
verify | - |
withHashes | - |
withMessage | - |