Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Contract Structure and Patterns

ES5 Class Pattern

Zetrix smart contracts use ES5 JavaScript (no ES6+ features). Here's how to create classes:

const MyContract = function() {
    const self = this;

    // Private variables (local scope)
    const _privateVar = 'private';

    // Public variables
    self.publicVar = 'public';

    // Protected namespace
    self.p = {};

    // Private method
    const _privateMethod = function() {
        return _privateVar;
    };

    // Public method
    self.publicMethod = function() {
        return self.publicVar;
    };

    // Protected method
    self.p.protectedMethod = function() {
        return _privateMethod();
    };

    // Constructor/Initialize
    self.init = function(param1, param2) {
        // Initialization logic
        self.publicVar = param1;
    };
};

// Entry point
function init(input) {
    const contract = new MyContract();
    contract.init(input);
}

function main(input) {
    // Handle contract calls
}

function query(input) {
    // Handle read-only queries
}

Restrictions:

  • ❌ No arrow functions

  • ❌ No let/const (use var only)

  • ❌ No template literals

  • ❌ No class keyword

  • ❌ No ES6+ syntax


Inheritance Pattern


Storage Pattern


Last updated