Weaving Clarity: Safe Smart Contracts for SmartWeave

TL;DR: At the beginning of September, Arweave and Blockstack announced a joint bounty for enabling use of the safe, decidable Clarity smart contract language on Arweave’s smart contract protocol, SmartWeave. Community member Arto Bendiken, known for creating Gitstamp, won the bounty. This is a guest blog post by Arto describing the need for Clarity and introducing Sworn, his compiler for Clarity on SmartWeave.

The Demo

The Bounty

The Promise

It’s for these reasons that Arweave decided to adopt Clarity, which was originally developed by Blockstack and Algorand. SmartWeave offers unparallelled flexibility by moving computation from network validators to the contract users themselves. This eliminates gas fees and removes the computation bottleneck that currently plagues Ethereum in particular.

SmartWeave also allows developers to deploy JavaScript contracts that require significant amounts of computation. It’s not a problem, computation-wise, for a contract to get stuck in an infinite loop on SmartWeave, because that would tend to affect mainly the party that wrote that contract. However, from a composability and correctness perspective, a safer language is desirable. (JavaScript contains even more footguns than Solidity.)

The Language

Despite that, smart contracts in Clarity are easy to write, and the language doesn’t feel restrictive. Indeed, people familiar with functional programming will feel right at home, and programmers familiar with Clojure will love the Lisp-derived simplicity of the syntax. (For others, that may take a few moments to get used to. Don’t worry, the road to enlightenment is littered with irritating, superfluous parentheses.)

Here’s counter.clar, a simple example contract that implements a persistent counter:

(define-data-var counter int 0)
(define-read-only (get-counter) (ok (var-get counter)))
(define-public (increment) (begin (var-set counter (+ (var-get counter) 1)) (ok (var-get counter))))
(define-public (decrement) (begin (var-set counter (- (var-get counter) 1)) (ok (var-get counter))))

The Future

As for Sworn, this is just the beginning. On the Sworn roadmap, we have more Arweave-specific Clarity functions for easily building profit-sharing tokens and communities. And we have big plans for Sworn 2.0: to facilitate Arweave adoption by developers already familiar with Ethereum, I am exploring how we might ingest existing Solidity contracts as well, preserving sunk investment.

If you’re as excited about these developments as I am, hop on over to #smartweave on Discord and join the conversation!

By Arto Bendiken

A novel data storage blockchain protocol enabling a permanent serverless web and creating truly permanent data storage for the first time.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store