May 17, 2019

Sandcastle, our Latest R&D Pre-Alpha Release, Brings SQL to Ethereum Smart Contracts

Sandcastle R&D

This article was written by PegaSys Co-Founder, developer, and researcher, Shahan Khatchadourian, Ph.D.

Millions of SQL developers are now Ethereum smart contract developers.

As someone with a passion for bridging database and blockchain technologies, I’ve spent a lot of time thinking about blockchains as different forms of databases. It’s still the case that a blockchain is not a database, yet. However, Sandcastle, an Ethereum SQL smart contract language, helps bridge that divide.

A Sandcastle pre-alpha web service that translates SQL into Solidity, and which works on all existing clients (i.e., no changes are needed), is now available as a Remix plugin.

Try the Sandcastle pre-alpha now! Feedback is welcome.

Sandcastle improves Ethereum’s data management capabilities by provisioning an on-chain relational database that supports tables, (sub-)queries, aggregation, updates, triggers, and indexes. Smart contracts based on relational semantics can be automatically optimized for transaction cost, performance, scalability and security across blockchains and databases.

Sandcastle operates by translating each table into a smart contract that contains rows of data structured according to the table’s schema. Queries, updates, triggers, and transactions are smart contract methods that execute against these tables. Our tool hides the complexity of joining multiple tables, computing aggregations, using indexes whenever possible, and using Solidity data structures effectively. The architecture diagram below shows that Sandcastle fits into existing development processes because the generated code can be integrated with pre-existing code and compiled using the standard solc-based toolchain.

Why did we build Sandcastle?

Enterprises need to manage and understand complex data in order to make informed business decisions. But committing to that effort will first require strategies to mitigate the associated costs and risks. One way to reduce risk is to improve blockchain’s data management capabilities. One way to reduce costs is to rely on the expertise of the millions of existing SQL developers by turning them into Ethereum smart contract developers.

Enterprises will benefit from the (re-)use of SQL as a way to preserve application logic across private and public Ethereum blockchains and databases, while optimizing for each. For example, Sandcastle’s optimizer will be able to take SQL code and generate smart contracts that minimize transaction costs in public chains, and can also generate smart contracts that perform identical application logic while maximizing performance in private chains. Developers won’t have to spend any time hand-coding brittle optimizations that limit agility and innovation. One of the most promising features is the ability to integrate existing enterprise data to model and simulate transactions and processes. We will share more about these exciting features soon.

Sandcastle is one of several steps we’re taking to help advance blockchain data management. If you’re an enterprise that is familiar with databases, focused on building Ethereum applications (i.e., not necessarily low-level), and willing to experiment with Sandcastle, do get in touch. This is an opportunity to give your input to our work blending database and blockchain paradigms.

We thank Eric Kellstrand for their contributions, and Kate Hardy, Horacio Mijail Anton Quiles and Gina Rubino for their reviews.

Want to join the team? PegaSys is hiring! Check out our list of open roles.

To keep up to date on PegaSys’ progress, check out our GitHub, follow us on Twitter and sign up for our mailing list below.