Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (2024)

Author

Julian Martinez

Publishing date

Developers

Smart Contracts

Rust v. Solidity

Why would a blockchain developer choose Rust over Solidity?

In this tutorial, we'll explore the intricacies of two major smart contract programming environments: Ethereum's Solidity and Soroban’s Rust SDK and why you should consider migrating your smart contracts to Rust.

In the blockchain and smart contract realm, Rust is a standout choice for developers, and here's why:

  • Speed & Efficiency: Rust whizzes through tasks like a sports car in style. It is super fast, even outpacing C++ when it comes to speed and efficiency so that your blockchain operations are not just quick but also saves on computing resources.
  • Type Safety: Picture Rust's type system as a meticulous inspector, who is watching each bit of your code at compile time. This means fewer errors and a safer environment for your smart contracts.
  • Memory Safety Without the Overhead: Rust boasts top-shelf memory safety, acting as an invisible shield against vulnerabilities critical in the blockchain world. And it does this leanly without needing a garbage collector, keeping your projects lean and fortified.
  • Conquering Concurrency with Ease: In blockchain, handling simultaneous transactions is like juggling fireballs. Rust excels in managing multiple operations seamlessly, preventing the common complications seen in other languages. This leads to faster, safer processing of transactions, enhancing the overall performance of your smart contracts.

Rust combines speed, safety, and execution efficiency making it an ideal language for blockchain development where such qualities are demanded. So how does Rust stack up against Solidity?

What's the difference between EVM and Soroban?

What is EVM?

The Ethereum Virtual Machine (EVM) is a core component of the Ethereum blockchain network. It is a virtual environment that allows for the execution of smart contracts and decentralized applications (dApps). While Ethereum is the primary network utilizing the EVM, other blockchain platforms have adopted or created compatible versions of the EVM. For instance:

  • Avalanche has its own virtual machine, the Avalanche Virtual Machine (AVM), but it also supports the EVM through its C-Chain, enabling compatibility with Ethereum-based applications.
  • Optimism and Polygon are Layer 2 solutions built on top of the Ethereum blockchain. They use Optimistic Rollups and Polygon's own technology, respectively, but are compatible with the EVM. This means they can run Ethereum smart contracts and dApps.

Each blockchain network can have its own consensus mechanisms, underlying architecture, and protocol implementations. Geth (Go Ethereum, an implementation of an Ethereum node in the Go programming language) is specifically an Ethereum client, and while other networks might draw inspiration or use aspects of Ethereum's technology, they often have distinct core protocols and implementations.

In EVM Land, Solidity is the go-to language for developing smart contracts. Here's a quick rundown for my fellow builders:

  • Object-Oriented Approach: Just like other OOP languages, Solidity organizes code around data and objects, not just functions and logic.
  • High-Level Language: It abstracts away from the nitty-gritty of computer hardware, making development smoother and more intuitive.
  • Statically-Typed: Solidity checks your code for errors and type mismatches at compile time, saving you from a lot of headaches later.

What makes Solidity stand out is its role in powering decentralized transactions and managing blockchain accounts. Plus, if you're comfortable with JavaScript, C++, and Python you'll find Solidity's syntax familiar.

Soroban is a smart contracts platform designed to be sensible, built-to-scale, batteries-included, and developer-friendly.

While it works great with Stellar being that it shares the blockchain's values of scale and sensibility, it neither depends nor requires Stellar at all and can be used by any transaction processor, including other blockchains, L2s, and permissioned ledgers.

Currently, Soroban is available as a part of the v20 of Stellar protocol stable release on Testnet. The package for the module consists of - smart contracts environment, a Rust SDK, A CLI, an RPC server, and additional modules tailored for smart contracts on Stellar. Users have the option to write and test contracts on their local machines or deploy them to Testnet for a more realistic simulation.

Introduced in 2022, the Soroban Rust SDK is a suite of tools specifically for writing smart contracts on the Soroban platform. Built on Rust, it enables developers to create decentralized finance applications, automated market makers, and tokenized assets, while also leveraging some of Stellar's core functionalities.

Hello World

How to Build a Hello World Smart Contract

We will create two "Hello World" contracts: first in Solidity, then using the Soroban Rust SDK.

Solidity

Solidity Version

Open the remix-ide in your browser by navigating to: remix.ethereum.org/

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (1)

Click on the “create new file” icon in the "File Explorer" tab.

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (2)

Type the file name “HelloWorld.sol” and enter the following code into the ide:

```// SPDX-License-Identifier: MIT// compiler version must be greater than or equal to 0.8.20 and less than 0.9.0pragma solidity >=0.7.0 <0.9.0;contract HelloWorld {function hello(string memory to) public pure returns(string memory){string memory greeting = string(abi.encodePacked("hello ", to));return greeting;}}```

Review

Let's take a quick intermission to break down the code

```// SPDX-License-Identifier: MIT```

This comment indicates the license under which the code is released (MIT License).

```pragma solidity >=0.7.0 <0.9.0;```

This line specifies that this code is compatible with Solidity compiler versions greater than or equal to 0.7.0 and less than 0.9.0. It sets compiler version boundaries to ensure code compatibility and expected behavior.

```contract HelloWorld {```

Here, we declare a Solidity contract named "HelloWorld."

```function hello(string memory to) public pure returns(string memory){```
  • It takes one argument, a string named "to," which represents the name of the person you want to greet.
  • The function is marked as "public," which means it can be called externally.
  • The "pure" keyword indicates that this function does not modify the contract's state.
```string memory greeting = string(abi.encodePacked("hello ", to));```

Inside the "hello" function, a new string variable "greeting" is declared.

  • It is constructed by concatenating "hello" with the provided name using the **abi.encodePacked** function.
  • The result is stored in the "greeting" variable.
```return greeting;```

Finally, the function returns the "greeting" string as the result of the function call.

Solidity

Now back to our regularly scheduled programming(🥁)

Once the code is in Remix, click the "Solidity Compiler" icon below the “File Explorer” icon.

Then, click “Compile HelloWorld.sol” or simply press `cmd+s`

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (3)

Once compiled successfully click the icon below “Solidity Compiler” that is “Deploy & Run Transactions”.

Without changing any of the values as shown above just click the “Deploy” button to deploy your smart contract. Once deployed you will find your smart contract just below in “Deployed Contracts” heading.

Click “>” before your contract you will see a button “hello” below as our contract has a hello function variable that returns a string composed of “hello” + the value you passed in for the `to` argument.

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (4)

Define an value for to and then click the “hello” button to return the greeting.

Nicely done! Now for the real Mccoy!

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (5)

Soroban

Soroban Rust SDK Version

Open the smart contract playground built for Soroban, okashi, in your browser by navigating to: okashi.dev/

Start a new project and name it HelloWorld.

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (6)

Enter the following code into the IDE:

```#![no_std]use soroban_sdk::{contract, contractimpl, symbol_short, vec, Env, Symbol, Vec};#[contract]pub struct Contract;#[contractimpl]impl Contract { /// Say Hello to someone or something. /// Returns a length-2 vector/array containing 'Hello' and then the value passed as `to`. pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> { vec![&env, symbol_short!("Hello"), to] }}```

Time for another commercial break already!?!

Don't worry this one is going to help you polish up on your Rust(🥁)

```#![no_std]```

This directive is used at the beginning of the Rust code to specify that the standard library (std) should not be included in the build. In Soroban contracts, the standard library is excluded because it's large and not suitable for deployment on blockchains.

```use soroban_sdk::{contract, contractimpl, symbol_short, vec, Env, Symbol, Vec};```
  • The **use** keyword is used to import external dependencies or modules into the current Rust code.
  • **soroban_sdk**: This is the crate/module that provides the necessary functionalities and types for Soroban contracts.
  • **{contract, contractimpl, symbol_short, vec, Env, Symbol, Vec}**: These are the specific items being imported from the **soroban_sdk** module, including attributes, macros **(contract, contractimpl, symbol_short!)**, and data types **(Env, Symbol, Vec)**.
```#[contract]pub struct Contract;```
  • **#[contract]** is an attribute applied to the Contract struct, designating it as the type to which contract functions are associated. It implies that this struct will have contract functions implemented for it.
  • **pub struct Contract;** defines a public struct named Contract. In Soroban contracts, contract functions are associated with this struct.
```#[contractimpl]impl Contract { pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> { vec![&env, symbol_short!("Hello"), to] }}```
  • **#[contractimpl]** is an attribute that is applied to the **impl** block for the **Contract** struct, indicating that this block contains the implementation of contract functions.
  • **impl Contract { ... }**: This is the implementation block for the Contract struct, where contract functions are defined.
  • **pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> { ... }**: This line defines a public function named **hello**. It takes two arguments, **env** of type **Env** and "to" of type **Symbol**(in this case, a string of up to 8 characters). It also specifies the return type as **Vec<Symbol>**
  • **{ vec![&env, symbol_short!("Hello"), to] }**: This block of code is where a length-2 vector/array containing "Hello" and then the value passed as "to" is constructed and returned.

That's all the breaks we have for today. Don't get crabby on me!(🥁)

Now that the code is in the editor, compile it by clicking the compile button or pushing "cmd+k"

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (7)

Open the contract tab and push the `hello()` button

Pass in an value for `to` and click the “call” button

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (8)

The "Console" tab should open and you should see your message!

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (9)

Comparison

Conclusion

Both Solidity and Soroban provide the functionality to declare public functions. However, their approaches to data handling and state management differ, influenced by their core languages – JavaScript for Solidity and Rust for Soroban. Solidity is ideal for those familiar with JavaScript, while Soroban's Rust foundation offers advantages in concurrency and safety.

Learn More

Additional Resources

For developers interested in transitioning from EVM to Soroban, we have comprehensive documentation that covers everything from the basics of the Soroban Rust SDK compared to Solidity, up to deploying your own smart contracts with Rust. Learn more about migrating from EVM here.

If you’re looking for more tools and want to learn more about the sdk, you can check out the official Soroban docs.

Stay tuned for more insights and tutorials in this series, and happy coding in the world of smart contracts!

Soroban CLI

Soroban Rust SDK

Stellar | Rust vs. Solidity: Choosing the Best Smart Contract Language for Blockchain Development (2024)

FAQs

Which language is best for smart contracts? ›

Yul, FE, and Yul+ are important languages for smart contract development. Despite the numerous options available among smart contract programming languages, Solidity and Vyper have marked a significant influence. To choose the right one, let us learn the basics of both smart contract programming languages.

What is the best blockchain for smart contracts? ›

Ethereum is the world's first and one of the best smart contract platforms which remains the most popular choice among developers. Following Bitcoin's decentralized concept, Ethereum has become a leader in smart contract platforms. Since its inception in 2015, the platform has launched more than 4,400 dApps.

Is Solidity best for blockchain? ›

Solidity is the most popular blockchain programming language of the Ethereum Virtual Machine (EVM), also widely used across a range of EVM-compatible blockchains.

What is the difference between smart contract and Solidity? ›

Smart contracts are programs that govern the behavior of accounts within the Ethereum state. Solidity is a curly-bracket language designed to target the Ethereum Virtual Machine (EVM). It is influenced by C++, Python, and JavaScript.

Is Solidity the only language for smart contracts? ›

Solidity is the primary programming language for developing smart contracts on the Ethereum Virtual Machine (EVM). However, Rust has emerged as a strong alternative in the blockchain ecosystem, especially for blockchains that support WebAssembly (Wasm), such as Polkadot, Klever and Solana.

Why is Ethereum the best blockchain for smart contracts? ›

Ethereum provides a programmable platform that gives a whole level of decentralized experience. It allows users to build applications for themselves on a decentralized development platform. It uses Solidity as the programming language to build smart contracts and decentralized applications.

Which blockchain does not support smart contracts? ›

Smart contracts do not run on the Bitcoin blockchain. The technology was introduced as part of the specification for Ethereum in 2014, which included a smart contract definition. So when it comes to smart contracts, Ethereum is the name of the game.

How many smart contracts are there in blockchain? ›

A Flipside Crypto report shows that over 637 million Ethereum Virtual Machine (EVM) smart contracts have been deployed across seven layer-2 blockchains since January 2022. EVM-compatible smart contracts refer to software that the computing state of the Ethereum blockchain can understand.

Is Solidity solid enough? ›

This soundness theorem states that the Solidity type system prevents stuck execution, but not runtime type errors. This is quite dangerous and can lead to Ether indefinitely locked into a contract or to unexpected runtime reverts.

Is it worth learning Solidity in 2024? ›

Solidity, the programming language used for creating smart contracts on Ethereum, is crucial for anyone looking to dive into the world of Blockchain development. This article will outline the fundamental knowledge, skills, and steps needed to become a proficient Solidity developer in 2024.

Is it still worth it to learn Solidity? ›

Yes, it is worth learning Solidity. Solidity is a powerful language that can be used to create a variety of decentralized applications.

What is the best smart contract blockchain? ›

The top 10 best smart contract platforms in 2024 are Ethereum, Binance Smart Chain (BSC), TRON, Arbitrum, Cardano, Solana, Polygon, Algorand, Avalanche, and Tezos.

Is rust better than Solidity? ›

In terms of security, Rust has the advantage. All thanks to the memory security features. For Solidity, they are not as robust as in the case of Rust.

What are the main advantages and disadvantages of using Solidity to write smart contracts? ›

Using Solidity, you can create smart contracts that are safe, clear, and dependable. They have the potential to improve operational efficiency, reduce costs, and reduce reliance on third parties.

Is Rust better than Solidity? ›

In terms of security, Rust has the advantage. All thanks to the memory security features. For Solidity, they are not as robust as in the case of Rust.

What is the clarity language for smart contracts? ›

The Clarity language allows users to supply their own conditions for transactions that ensure that a contract may never unexpectedly transfer a token owned by a user. Contracts written in Clarity are broadcasted on the blockchain exactly as they are written by developers.

What is the best efforts language in a contract? ›

“Best efforts” is at the top of the scale and is generally perceived to mean that a party must do all that can possibly be done to seek and obtain an end, even if the impact would be materially adverse to the seeking party and even if there is a material monetary cost to the action.

What language does Solana use for smart contracts? ›

You can create Solana smart contracts primarily with Rust, but other languages such as C, C++, Solidity (via Solang compiler) and Python (via Seahorse framework) are also suitable.

Top Articles
Retention of Documentation in ISO Standards
Is Autism an Intellectual Disability? | RDIconnect
Overton Funeral Home Waterloo Iowa
Live Basketball Scores Flashscore
What spices do Germans cook with?
Explore Tarot: Your Ultimate Tarot Cheat Sheet for Beginners
Delectable Birthday Dyes
Kris Carolla Obituary
World of White Sturgeon Caviar: Origins, Taste & Culinary Uses
Raid Guides - Hardstuck
Little Rock Arkansas Craigslist
Detroit Lions 50 50
Zürich Stadion Letzigrund detailed interactive seating plan with seat & row numbers | Sitzplan Saalplan with Sitzplatz & Reihen Nummerierung
Babyrainbow Private
ExploreLearning on LinkedIn: This month&#39;s featured product is our ExploreLearning Gizmos Pen Pack, the…
D10 Wrestling Facebook
Scenes from Paradise: Where to Visit Filming Locations Around the World - Paradise
Mail.zsthost Change Password
Mani Pedi Walk Ins Near Me
Gdlauncher Downloading Game Files Loop
Alexander Funeral Home Gallatin Obituaries
Grandview Outlet Westwood Ky
Schedule 360 Albertsons
Craigslist Southern Oregon Coast
1973 Coupe Comparo: HQ GTS 350 + XA Falcon GT + VH Charger E55 + Leyland Force 7V
Yisd Home Access Center
Will there be a The Tower season 4? Latest news and speculation
Ff14 Sage Stat Priority
The Bold and the Beautiful
Craigslist Cars And Trucks Mcallen
Mega Millions Lottery - Winning Numbers & Results
Shnvme Com
Uhaul Park Merced
Staar English 1 April 2022 Answer Key
Dadeclerk
Rage Of Harrogath Bugged
Joey Gentile Lpsg
Why I’m Joining Flipboard
Colorado Parks And Wildlife Reissue List
Newsweek Wordle
Pekin Soccer Tournament
Pixel Gun 3D Unblocked Games
Mother Cabrini, the First American Saint of the Catholic Church
Verizon Forum Gac Family
Erespassrider Ual
Mlb Hitting Streak Record Holder Crossword Clue
Lira Galore Age, Wikipedia, Height, Husband, Boyfriend, Family, Biography, Net Worth
Urban Airship Acquires Accengage, Extending Its Worldwide Leadership With Unmatched Presence Across Europe
Myhrkohls.con
Jasgotgass2
The Love Life Of Kelsey Asbille: A Comprehensive Guide To Her Relationships
Yoshidakins
Latest Posts
Article information

Author: Catherine Tremblay

Last Updated:

Views: 5892

Rating: 4.7 / 5 (67 voted)

Reviews: 82% of readers found this page helpful

Author information

Name: Catherine Tremblay

Birthday: 1999-09-23

Address: Suite 461 73643 Sherril Loaf, Dickinsonland, AZ 47941-2379

Phone: +2678139151039

Job: International Administration Supervisor

Hobby: Dowsing, Snowboarding, Rowing, Beekeeping, Calligraphy, Shooting, Air sports

Introduction: My name is Catherine Tremblay, I am a precious, perfect, tasty, enthusiastic, inexpensive, vast, kind person who loves writing and wants to share my knowledge and understanding with you.