npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crystalscript

v0.3.3

Published

Crystalscript to Clarity compiler

Downloads

7

Readme

tests

Crystal Script - compiler for Stacks smart contracts

Crystal Script transforms the crystalscript language into Clarity, the smart contract language for deployment on the Stacks blockchain.

For more information about Stacks and Clarity, see:

Stacks: https://www.stacks.co/

Clarity: https://docs.stacks.co/docs/clarity/

Installation

$ npm install -g crystalscript

What does crystalscript look like?

Here is a sample smart contract in crystalscript for a self-service "mbot" NFT:

// create on-chain storage for the mbot NFT
persist mbot as nonfungible-token identified by string[50];

// Mint your own mbot!
public function mint-mbot-nft(name string[50])
{
    const result = mbot.mint?(name, tx-sender);
    if (result.iserr()) {
         // sorry, that name is taken...
         return err(false);
    }
    // congratulations, you have a new mbot!
    return ok(true);
}

// TEST: mint-mbot-nft(u"Ava") => ok: val===true

How to use

Compile a smart contract to Clarity

$ crystalscript /path/to/file.crystal
saved: /path/to/file.crystal.clar

Compile a smart contract so it can be shared (imported by other crystalscript contracts)

$ crystalscript -n mbot-nft mbot.crystal
saved: mbot.crystal.clar
saved: mbot-nft.import

Compile a smart contract, deploy it with clarity-cli, then run embedded tests*

$ crystalscript -t mbot.crystal
saved: mbot.crystal.clar

run tests
creating new clarity vm db 'test_db'
deploy mbot.crystal.clar as ST26FVX16539KKXZKJN098Q08HRX3XBAP541MFS0P.test

test 1: (mint-mbot-nft u"Ava")
  success: ok and 'val===true' is true

* Note: to deploy and run embedded tests locally in a mock Stacks environment, 'clarity-cli' from stacks-blockchain must be installed and in the path (or its location specified by the CLARITY_CLI environment variable).

crystalscript does not deploy compiled code to Stacks testnet and mainnet. You could try @stacks/cli for that.

For additional compilation options, run crystalscript with no arguments.

Documentation

Crystal Script's syntax is similar to javascript.

For language details, please see the Crystal Script Language Reference docs/language-reference.md

Why a new language?

The author believes Clarity is difficult to use and that the Stacks ecosystem could benefit from a language that is easier to understand and maintain.

For example, the Crystal Script expression "(~n >> u124) + u1" would be coded, using Clarity's "pure functional", Lisp-like syntax, as "(+ (bit-shift-right (bit-not n) u124) u1))". Although this is a simple example, you can see how it could get difficult to read in a larger context.

Support

This is an open source project and the project owners hope you find it useful. However, they may or may not have time to answer questions!

If you do have questions, please seek answers yourself before opening an issue. Otherwise, issues can be posted on GitHub. Pull requests are also welcome, but please see CONTRIBUTING.md.

License

Crystal Script is licensed under the terms of GPL v3.0 or later. See the LICENSE file for details. Any Clarity code produced by the compiler is specifically excluded from any licensing terms, including the GPL.

crystalscript uses the Jison compiler-compiler, Copyright (c) 2009-2014 Zachary Carter.