Basic examples

From RunWiki
Revision as of 11:27, 6 April 2025 by Zhell (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

These are some basic examples to get your imagination flowing.

Dragon

When one company makes a digital pet dragon, another can make a house to live in. Jigs interact with each other.

class Dragon extends Jig {
    init(name) {
        this.name = name
    }
}


class DragonHouse extends Jig {
    init(dragon) {
        this.dragon = dragon
    }

    clean() {
        this.dirty = false
    }
}

Axe

The base class is the parent of all weapons in the game. Each weapon subclass independently sets the damage it delivers. Then you check whether a particular weapon is the correct type to allow in the game.

class Weapon extends Jig {
    init(damage) {
        this.damage = damage
    }
}


class Axe extends Weapon {
    init() {
        super.init(9001)
    }
}


new Axe() instanceof Weapon // true

Loyalty Card

Any card you’d have in your iOS or Android wallet: boarding passes, prepaid cards.

class LoyaltyCard extends Jig {
    init() {
        this.stamps = 0
    }

    stamp() {
        this.stamps += 1
    }
}

Product

Track a physical good from manufacturing through delivery to the customer. Store both the unique serial number and the shared model number. When you transfer ownership, the official record is on-chain.

class Product extends Jig {
    init(model, serial, date) {
        this.model = model
        this.serial = serial
        this.creation = date
    }

    transfer(to) {
        this.owner = to
    }
}

Vote

For any recorded decision, you can build a graphical user interface with a dropdown selection. Then, after a milestone, tally up the votes and set in motion the transition of power.

class Vote extends Jig {
    vote(candidate) {
        this.candidate = candidate
    }
}


class Election extends Jig {
    // ...

    tally() {
        const counts = { 'Alice': 0, 'Bob': 0, 'Carol': 0 }
        this.voters.forEach((name, vote) => {
            counts[vote.candidate] += 1
        })
        return counts
    }
}

Dollar

Directly or indirectly link backing to a token. Send numerical amounts and provide the functionality of SLP and ERC20 tokens.

class Dollar extends Token { }

Dollar.decimals = 2
Dollar.currency = 'USD'
Dollar.backingBank = 'HSBC'
Dollar.accountNumber = '#103947000'

run.deploy(Dollar)

const coin = Dollar.mint(100000)

coin.send(address, 1000)

Permissions

Allow several people edit access to a website or raise a digital pet together with your friends. Also updates to the permissions are as easy as a cheap bitcoin transaction.

class User extends Jig { }


class UserGroup extends Jig {
    init() {
        this.users = []
    }

    addUser(user) {
        if (!this.users.includes(user)) {
            this.users.push(user)
        }
    }

    removeUser(user) {
        this.users = this.users.filter(u => user !== u)
    }
}