Arweave.news

Arweave Smart Contracts Now Support Solidity, Rust and C: Everything We Know About 3em

0 2,055

Read in Chinese

On the 3rd of January 2022, Verto Exchange, the leading decentralised exchange (DEX) on Arweave, announced the public release of 3em, a multi-language execution environment for Arweave Smart Contracts.

Verto Exchange has been working with the developers at 3em to incubate and help bring this idea to life.

3em and Arweave

3em was created by Andres Pirela and Divy Srivastava to help address some of the obstacles that current developers might face when wanting to deploy a smart contract to Arweave.

Smart contracts are, at their core, pieces of code that contain functions that live on an immutable blockchain. When the smart contract is called, this code runs and executes those functions that then return a transaction result depending on the nature of that smart contract, whether it be to send funds to another user, or create (mint) an NFT.

When it comes to Arweave, the smart contract standard that has been used up until today is called SmartWeave. SmartWeave was created by Sam Williams and the wider Arweave team. It uses a method called “Lazy Evaluation”.

Traditional smart contract systems work in a way were every node (computers running the base software of a blockchain that verify all transactions) on the blockchain will execute every transaction to verify their validity, rejecting any false or malicious transactions.

The way lazy evaluation works is different and quite simple. Instead of every node verifying all transactions, it leaves the verifying to the users of the smart contract itself. When a user interacts with the smart contract they validate all previous transactions on the smart contract, before adding their own transaction at the end of those ones. The next user that comes along will then again verify all past transactions including this previous one.

As stated on Twitter by Tate Berenbaum, the founder of Verto Exchange: 

“(The SmartWeave standard) proved that smart contracts on a permanent data layer (the permaweb) were possible.”

This was part of a thread that Tate posted on Twitter regarding 3em.

Developers making contracts on SmartWeave can in theory use any coding language that they desire. Having said this, most SmartWeave protocols that have been written up to today utilise JavaScript as their coding language.

What happens when more programmers come in and want to use other languages? And what happens when they want to interact with smart contracts on Ethereum that are written in Solidity?

Some form of universal “translator” that would allow all these contracts and protocols written in different programming languages to communicate was needed. And this is the issue that 3em is addressing.

3em is a programming execution environment. As described on 3em’s website, it allows you to “Run SmartWeave contracts in a matter of seconds, with support for multiple langauges.” So let’s take a closer look at 3em.

Polyglot, secure, fast!

The word Polyglot derives from the Greek word “Πολύγλωσσος”. It means someone that can talk multiple languages. And this is in exactly what 3em does.

It allows programmers to come in, write a smart contract in the programming language they are most comfortable with and not have to worry about the smart contract’s cross language and cross chain functionality. Programmers can come in and use Solidity, Rust, C, JavaScript and many more languages which ultimately compile to octet stream binaries, WASM, or EVM bytecode.

3em was also created with security in mind. As described above, SmartWeave uses lazy evaluation for its contracts. And with 3em these contracts can talk to other contracts on other chains. The 3em developers wanted to make sure that users could not inject malicious code in to the path of other smart contracts.

So the answer to this was to create a sandboxed environment for the execution of the smart contracts. Think of a sandboxed environment as a testing ground that doesn’t allow anything to leave before making sure it is safe.

The 3em developers also wanted to make sure that their tech was fast. It was built with optimisation in mind. 

The issue they are addressing here is bigger than might initially come to mind. Due to the way lazy evaluation works, each interaction with the smart contract on SmartWeave means that the next user that comes along will have more transactions to evaluate before appending their own transaction to the list.

As mentioned in a thread by Verto Exchange, on average a SmartWeave contract built using JavaScript as its programming language has an evaluation time of 2.6 seconds, whereas that same contract built in 3em has an evaluation time of just 0.64 seconds. This lower evaluation time means a much smoother experience for users that interact with the smart contracts.

How 3em works and integrates in the development stack

At the time of writing, 3em is able to read SmartWeave contracts including those deployed in other languages. It can do this via the JavaScript library’s readContract function which returns data in the same way as the current smartweave-js implementation but much faster.

Developers can deploy 3em-compatible contracts via the command line tool on the project’s GitHub. They’re identified by specific transaction tags, and by reading the MIME type 3em knows which language to parse as it reads. For developers, the exception comes when sending interactions to and reading from EVM bytecode contracts; instead of the usual JSON, the inputs and outputs will be encoded with Ethereum ABI.

3em is available as a CLI, JavaScript package and Rust crate making it able to integrate with front ends, back ends and servers alike.

For examples of 3em test transactions, check:

Conclusion

This is probably the biggest news that has hit the Arweave ecosystem as of lately – definitely the biggest SmartWeave devlopment since RedStone’s implementation.

The future looks bright for 3em and the entire Arweave and SmartWeave ecosystem at large. This move will most likely bring more developers in to the world of Arweave and smart contracts that live on the permaweb.

Any developers wanting to start using 3em can do so now by going to their GitHub page.


Join our
Telegram / Discord / Twitter

Leave A Reply

Your email address will not be published.