Building Smart Contracts with Rust

Building Smart Contracts with Rust

Smart contracts are event-driven programs stored on a blockchain that trigger action when certain conditions are met. They are used to automate & fast-track the execution of agreements between participants without involving intermediaries. Smart contracts can be accessed by anyone on a blockchain, once published. They are smaller and simpler than other programs due to the expenses spent in deploying them. Being transparent and immutable, they make reliable and impartial third parties. Their execution is serverless and decentralized/not controlled by a single entity.

Smart contracts are written in various programming languages depending on the blockchain they are run on. For example, Solidity is used on Ethereum and other EVM compatible blockchains, Cadence on Flow and Rust on Solana, Near, Substrate and so on.

Rust is a general-purpose and Turing complete programming language designed for performance and safety with syntax like C++. Though it wasn’t really designed for blockchain like the other Smart contract languages specific to their blockchain networks, Rust has become increasingly popular over the past five years and its usage is expected to grow even further in the coming years.

Rust enforces memory management rules at compile time, it uses minimal runtime resources, which reduces overheads, is safe and efficient. It comes with the cargo and crates ecosystem that make the development process more productive. Smart contracts written in Rust are compiled to wasm or web assembly. The WebAssembly System Interface, WASI is an initiative to implement development standards in blockchain with smart contracts being one of its modules. Its implementation would enable developers to run smart contracts universally on blockchains supported by WASI. Web Assembly satisfies requirements of a virtual machine required to run smart contracts and overcomes the limitations of Ethereum Virtual Machine (EVM). Some of the Rust APIs include near_bindgen on NEAR, smart_contract for Wavelet, EWASM for Ethereum like blockchains, Ink!, Mantle and so on.

Ink! and Mantle are embedded Domain Specific Language (eDSL) based APIs that require developers to follow certain rules or patterns to turn their Rust code into smart contracts whereas near_bingden and wavelet do not require much modifying or refactoring of code as a contract interface.?Their APIs automatically generate and inject code using macros and even allow developers to generate eDSL style API smart contracts.

All of them have a common architecture comprising of a wasm executor in which Rust contracts are executed, and the interfaces between contract and blockchain comprising methods that facilitate interaction between the two. The client side programs, or web applications communicate using RPC interface, APIs specific to each blockchain sharing a common purpose of communicating with the blockchain. For example, Solana uses JSON RPC and Near uses NEAR RPC API to interact between smart contract and client application. The RPC interface allow applications to broadcast signed transactions to nodes, as well as query the current state of the blockchain (account balances, access keys, view function calls, etc.)

Some resources and motivation to get started building smart contracts with Rust-

-?????????https://developer.concordium.software/en/mainnet/smart-contracts/general/contract-module.html

-?????????https://welcome.near.university/developers/protocol/smart-contracts

-?????????Hello World: https://soldev.app/course/hello-world-program

-?????????Note-Taking Application: https://soldev.app/course/deserialize-instruction-data

要查看或添加评论,请登录

Khushboo Gehi, MSc的更多文章

  • Privacy Enhancement using Federated Learning & Blockchain

    Privacy Enhancement using Federated Learning & Blockchain

    Machine learning pipelines executed within cloud infrastructure, are computationally intensive & use specialized…

  • Hierarchical & K-means Clustering

    Hierarchical & K-means Clustering

    Hierarchical clustering is a good way to segment data. It provides a tree structure to the data based on similarities.

  • Extracting Text from Image/PDF

    Extracting Text from Image/PDF

    PDF or portable document format is a complex structure. Since the it is binary structure, the raw text is difficult to…

  • Covid Vaccine Response Agent

    Covid Vaccine Response Agent

    This article is about a conversational agent trained to respond to frequently asked questions about covid-19 vaccines…

  • Scraping Data Off the Web

    Scraping Data Off the Web

    Web scrapping is a process in which data is extracted from websites for various purposes like marketing, research, data…

  • A not-so-perfect Chatbot

    A not-so-perfect Chatbot

    Chatbots are almost everywhere, most of us have interacted with at least one chatbot by now through voice/text…

  • Basic Face Detection

    Basic Face Detection

    Facial detection and recognition are commonly applied in security bio-metrics, social media, personal devices,etc…

  • Time Series Analysis using CNNs

    Time Series Analysis using CNNs

    Time series analysis can be implemented in multiple ways including linear models in machine learning, recurrent neural…

  • Using LSTM To Navigate Robots

    Using LSTM To Navigate Robots

    Long Short-Term Memory networks or LSTMs are a type of Recurrent Neural Networks that reuse the output of a previous…

  • Churn Prediction using Deep Neural Network

    Churn Prediction using Deep Neural Network

    Customer churn is essential in business as getting new customers requires more efforts and investment. This business…

    3 条评论

社区洞察

其他会员也浏览了