Documentation
Language Features
Field Types

Field Types

Polylang provides support for the following types.

Primitive types

Example:

contract Person {
    id: string;
    name: string;
    age: number;
    salary: u32;
    qualified: boolean;
    profileImage: bytes;
 }

PublicKey

This is a special type used to represent a public key. Currently, only secp256k1 (Ethereum) public keys are supported. However, support for Falcon (opens in a new tab) public keys is in progress.

This key is used in contracts to enforce a means of Access Control (opens in a new tab) in Polybase.

Example:

contract User {
    id: string;
    name: string;
    publicKey: PublicKey;
 
    constructor (id: string, name: string) {
        this.id = id;
        this.name = name;
        this.publicKey = ctx.publicKey;
    }
 
    function setName(newName: string) {
        if (ctx.publicKey != this.publicKey) {
            error('Unauthorized access!)
        }
    }
 }

For the ctx.publicKey part, please refer to the page on Context.

Later, in the setName function (also note the use of the optional function keyword), we can check the public key of the user invoking the function against the public key which was used at record creation time, and allow the operation only if they match.

This check provides fine-grained checks over data updates. See the section on permissions for more details on permissions.

Contract Types

A contract type is simply a reference to a Polybase contract. Consider the following example:

contract Employee {
    id: string;
    name: string;
    empId: number;
    company: Company;
 
    constructor (id: string, name: string, empId: number, company: Company) {
        this.id = id;
        this.name = name;
        this.empid = empId;
        this.company = company;
    }
}

The company field if of type Company, which is a contract declared as follows:

contract Company {
    id: string;
    name: string;
    code: string;
 
    constructor (id: string, name: string, code: string) {
        this.id = id;
        this.name = name;
        this.code = code;
    }
}

Array Types

An array in Polylang represents an ordered sequence of values of the same type (homogenous arrays). However, there are some restrictions on which types are allowed in array declarations. Only the following Polylang types are permitted:

Example:

contract Bank {
    id: string;
    accId: string;
    accounts: Account[];
 
    ...
  }
 
contract Account {
    id: string;
    name: string;
    balance: number;
 
    ...
 }

Map Types

A map in Polylang represents, as expected, a mapping from the key type to the value type. However, the key can only be either a string or a number while the value can be any valid Polylang type.

Example:

contract Bank {
    id: string;
    accId: string;
    accounts: map<string, Account>;
 
    ...
  }
 
contract Account {
    id: string;
    name: string;
    balance: number;
 
    ...
}
 

Object Types

As in the case of nested fields, an object type represents a composite contract of key-value pairs.

Example:

contract Product {
    id: string;
    name: string;
    price: number;
    tags: string[];
    details: {
        description: string;
        manufacturer: string;
    }
 
    constructor (id: string, name: string, price: number, description: string, manufacturer: string) {
        this.id = id;
        this.name = name;
        this.price = price;
        this.details = {
            description: description,
            manufacturer: manufacturer
        }
    }
}

In the example above, the details field is of object type, and in the constructor, we populate this field by populating its nested fields with the values from the constructor arguments.


Polylang Docs