Skip to main content

o1js   npm version PRs Welcome

ℹ️ 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 to o1js

  • 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

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.

MemberDescription
Crypto-
Encryption-
ExperimentalThis module exposes APIs that are unstable, in the sense that the API surface is expected to change.
Lightnet-
Mina-
AccountUpdateAn AccountUpdate is a set of instructions for the Mina network.
AccountUpdateForestClass which represents a forest (list of trees) of account updates,
AccountUpdateTreeClass which represents a tree of account updates,
AlmostForeignField-
BaseMerkleWitnessThe BaseMerkleWitness class defines a circuit-compatible base class for Merkle Witness'.
BoolA boolean value. You can use it like this:
CanonicalForeignField-
Character-
Circuit-
CircuitString-
DynamicProofThe DynamicProof class enables circuits to verify proofs using in-ciruit verfication keys.
EcdsaSignature-
FieldA Field is an element of a prime order finite field.
ForeignCurve-
ForeignField-
GroupAn element of a Group.
HashedHashed<T> represents a type T by its hash.
Int64A 64 bit signed integer with values ranging from -18,446,744,073,709,551,615 to 18,446,744,073,709,551,615.
Keypair-
LedgerRepresents the Mina ledger.
MerkleListDynamic-length list which is represented as a single hash
MerkleListIteratorMerkleListIterator helps iterating through a Merkle list.
MerkleMap-
MerkleMapWitness-
MerkleTreeA Merkle Tree is a binary tree in which every leaf is the cryptography hash of a piece of data,
NullifierNullifiers are used as a public commitment to a specific anonymous account,
PackedPacked<T> is a "packed" representation of any type T.
PrivateKeyA signing key. You can generate one via PrivateKey.random.
Proof-
PublicKeyA public key, which is also an address on the Mina network.
ScalarRepresents a Scalar.
SelfProof-
Sign-
SignatureA Schnorr Signature over the Pasta Curves.
SmartContractThe main zkapp class. To write a zkapp, extend this class as such:
TokenAccountUpdateIteratorData structure to represent a forest of account updates that is being iterated over,
TokenContractBase token contract which
TokenSymbol-
UInt32A 32 bit unsigned integer with values ranging from 0 to 4,294,967,295.
UInt64A 64 bit unsigned integer with values ranging from 0 to 18,446,744,073,709,551,615.
UInt8A 8 bit unsigned integer with values ranging from 0 to 255.
UnconstrainedContainer which holds an unconstrained value. This can be used to pass values
VerificationKey-
PermissionsPermissions specify how specific aspects of the zkapp account are allowed
Account-
Bool-
BoolVar-
Bytes-
CacheInterface for storing and retrieving values, for caching.
CacheHeaderA header that is passed to the caching layer, to support rich caching strategies.
ConstantField-
DeployArgs-
Empty-
Field-
FlexibleProvable-
FlexibleProvablePure-
Group-
InferProvable-
JsonProof-
MerkleListBaseCommon base type for MerkleList and MerkleListIterator
MerkleListIteratorBase-
ProvableProvable<T> is the general interface for provable types in o1js.
ProvableExtended-
ProvableHashable-
ProvablePureProvablePure<T> is a special kind of Provable interface, where the "auxiliary" (non-provable) data is empty.
Reducer-
ScalarConst-
StateGettable and settable state that can be checked for equality.
Struct-
TransactionPromiseA Promise<Transaction> with some additional methods for making chained method calls
TransactionStatusINCLUDED: A transaction that is on the longest chain
Undefined-
VarField-
Void-
WithHash-
Witness-
ZkProgram-
ZkappPublicInputThe public input for zkApps consists of certain hashes of the proving
Account-
BoolA boolean value. You can create it like this:
Cache-
Crypto-
Empty-
FieldA Field is an element of a prime order finite field.
Gadgets-
GroupAn element of a Group.
HashA collection of hash functions which can be used in provable code.
Keccak-
Permissions-
Poseidon-
TokenId-
TransactionVersion-
Undefined-
Void-
ZkappPublicInput-
emptyHash-
BytesA provable type representing an array of bytes.
ConstantField-
MerkleListBase-
MerkleWitnessReturns a circuit-compatible Witness for a specific Tree height.
Reducer-
State-
StructStruct lets you declare composite types for use in o1js circuits.
VarField-
WithHash-
ZkProgram-
addCachedAccountAdds an account to the local cache, indexed by a GraphQL endpoint.
assertAssert that a statement is true. If the statement is false, throws an error with the given message.
checkBitLength-
checkZkappTransaction-
circuitMain-
createEcdsaCreate a class EcdsaSignature for verifying ECDSA signatures on the given curve.
createForeignCurveCreate a class representing an elliptic curve group, which is different from the native Group.
createForeignFieldCreate a class representing a prime order finite field, which is different from the native Field.
declareMethodsdeclareMethods can be used in place of the @method decorator
declareStatedeclareState can be used in place of the @state decorator to declare on-chain state on a SmartContract.
fetchAccountGets account information on the specified publicKey by performing a GraphQL query
fetchEventsAsynchronously fetches event data for an account from the Mina Archive Node GraphQL API.
fetchLastBlockFetches the last block on the Mina network.
fetchTransactionStatusFetches the status of a transaction.
genericHash-
initializeBindingsA function that has to finish before any bindings exports can be used.
maybeSwap-
merkleListHash-
methodA decorator to use in a zkApp to mark a method as provable.
provable-
provablePure-
public_-
readVarMessage-
sendZkappSends a zkApp command (transaction) to the specified GraphQL endpoint.
setArchiveGraphqlEndpointSets up a GraphQL endpoint to be used for fetching information from an Archive Node.
setGraphqlEndpoint-
setGraphqlEndpoints-
setNumberOfWorkersSet 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 :)
stateA decorator to use within a zkapp to indicate what will be stored on-chain.
toConstantField-
toFp-
verify-
withHashes-
withMessage-