Introducing Polylang
What is Polylang?
Polylang
is a statically (and strongly typed) smart contract programming language, with syntax and features influenced by languages such as JavaScript
and TypeScript
, used by Polybase (opens in a new tab) for writing smart contracts1
whereby proofs can be generated that state transitions follow the contract's rules, and which compiles down to Zero-Knowledge (opens in a new tab) programs that are verified using zk-STARKs.
Zero-Knowledge provides two main benefits:
- Provable computation - proves that the code ran as designed, and therefore the output can be trusted.
- Privacy - the user can prove that they possess certain information without revealing the information itself.
Refer to the page on Zero-Knowledge for more details.
Overview
Using Polylang
, you can define contract fields, and add methods (functions associated with the contract) that operate on the data (fields).
An example of a typical smart contract in Polylang
is:
contract Person {
id: string;
name: string;
age: number;
// create a new record for this smart contract
constructor (id: string, name: string, age: number) {
this.id = id;
this.name = name;
this.age = age;
}
// update the name for this record
setName(newName: string) {
this.name = newName;
}
// update the age for this record
setAge(newAge: number) {
this.age = age;
}
}
The code above defines a smart contract called Person
which defines a set of fields associated with Person
. In this case, we have three fields:
- the
id
field which uniquely identifies a "record" of this contract - a
name
field for storing the name of the person - an
age
field for storing the age of the person
Like other smart contract languages, Polylang
allows the updating of a contract's state by calling functions/methods on the contract.
In the contract above, we have defined a couple of functions that can update the name
and age
fields of the contract.
Using Polylang
Polylang
is open-source and implemented in Rust. It can be used as a CLI or as a library (crate). Head to the next section to get started with Polylang
.
Examples
For full-fledged and runnable examples, please refer to the examples (opens in a new tab) in the Polylang
repository.
Footnotes
-
See the section on contracts (opens in a new tab) in the
Polybase
documentation for more details. ↩