@rigidity/clvm v4.0.0
CLVM
A browser friendly implementation of clvm in TypeScript, based off of the Chia Network implementation written in Python.
Introduction
Chialisp is an on-chain smart coin programming language developed by the Chia Network. It is compiled and then executed by the Chialisp Virtual Machine, or CLVM for short.
This particular implementation is written with TypeScript, and is not bindings to native code. This allows it to be used in the browser as well. However, if you prefer native bindings, you should check out this library instead.
Usage
You can learn more about how this language works here. This is a implementation and should work as expected, but in any case that it differs, please open an issue.
By design, the functions and methods exposed by this library are synchronous and everything is exported for ease of use.
Since it is written in TypeScript, there are built-in typings for IntelliSense. The following documentation is non-exhaustive, but should be enough for most uses.
Documentation
Value
Either Cons or Uint8Array.
Cons
A tuple of Program and Program.
Program
This represents a program or value in Chialisp or compiled clvm. It is the main class of the library, allowing you to manipulate programs and convert between various forms.
static true
- A program representing the value
1.
static false
- A program representing the value
().
atom
- The
Uint8Arrayvalue of the program.
cons
- The
Conspair of the program.
first
- The first
Programvalue ofcons.
rest
- The rest
Programvalue ofcons.
isAtom
- A
booleanfor if it's an atom.
isCons
- A
booleanfor if it's a cons pair.
isNull
- A
booleanfor if it's null.
static cons(first, rest)
firstis aProgram.restis aProgram.- Returns a
Programthat is a cons pair between them.
static fromBytes(bytes)
bytesis aUint8Array.- Returns a
Program.
static fromHex(hex)
hexis a hexstring.- Returns a
Program.
static fromBool(value)
valueis aboolean.- Returns a
Program.
static fromInt(value)
valueis anumber.- Returns a
Program.
static fromBigint(value)
valueis abigint.- Returns a
Program.
static fromText(text)
textis astring.- Returns a
Program.
static fromSource(source)
sourceis astring.- Returns a
Program.
static fromList(programs)
programsis anArray<Program>.- Returns a
Program.
static deserialize(bytes)
bytesis aUint8Array.- Returns a
Program.
constructor(value)
valueis aValue.
positionSuffix
- A
stringcontaining the line and column suffix, if there is one.
at(position)
positionis aPosition.- Returns
this.
curry(args)
argsis anArray<Program>.- Returns a
Programcontaining the current one with each argument applied to it in reverse, precommitting them in the final solution.
uncurry()
- Returns a
[Program, Array<Program>]containing the mod and curried in arguments.
hash()
- Returns a
Uint8Arrayof the tree hash of the program. Hashed with1for atoms, and2for cons pairs.
hashHex()
- Returns a hex
stringrepresentation of the tree hash.
define(program)
- Returns a
Programcontaining the current one wrapped in a mod if there isn't already, and with a definition inserted.
defineAll(programs)
programsis anArray<Program>.- Returns a
Programcontaining the current one and each definition.
compile(options?)
optionsis a partialCompileOptions, defaulting tostrict = false,operators = base, andincludeFilePaths = {}.- Returns a
ProgramOutputthat is the result of compiling the program. Should be identical to therunCLI tool.
run(environment, options?)
environmentis aProgram.optionsis a partialRunOptions, defaulting tostrict = falseandoperators = base.- Returns a
ProgramOutputthat is the result of running the program. Should be identical to thebrunCLI tool.
toBytes()
- Returns a
Uint8Arrayrepresentation.
toHex()
- Returns a hex
stringrepresentation.
toBool()
- Returns a
booleanrepresentation.
toInt()
- Returns a
numberrepresentation.
toBigInt()
- Returns a
bigintrepresentation.
toText()
- Returns a
stringrepresentation.
toSource(showKeywords?)
showKeywordsis aboolean, by defaulttrue.- Returns a
stringsource code representation, like it would be if it were an output fromrunorbrun.
toList(strict?)
strictis aboolean, by defaultfalse.- Returns an
Array<Program>representation. If it's strict, it must be a proper list.
serialize()
- Returns a
Uint8Arrayserialized form of the program.
serializeHex()
- Returns a hex
stringrepresentation of the serialized form of the program.
equals(value)
valueis aProgram.- Returns a
booleanfor if the values are exactly equal.
toString()
- Returns a
stringsource code representation, like it would be if it were an output fromrunorbrun.
