Reader small image

You're reading from  Rust for Blockchain Application Development

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781837634644
Edition1st Edition
Concepts
Right arrow
Author (1)
Akhil Sharma
Akhil Sharma
author image
Akhil Sharma

Akhil Sharma is a Software Engineer and an entrepreneur. He is the CTO of Dominate, a SaaS product company, and the founder of Myrl Tech, a tech services company providing technology consulting to some of the top enterprise companies in the world such as HP, 3M, Honda, Bose, and Adobe. He has 12+ years of industry experience and a solid understanding of building digital products. He is adept at multiple programming languages such as Golang, Rust, Ruby, Python, and JavaScript. He has mentored hundreds of engineers offline and discovered that they knew the programming language and the concepts around it but were unable to use them in real-world applications. He aims to close this gap by teaching how to apply the concepts practically and build projects in real time.
Read more about Akhil Sharma

Right arrow

Exploring NEAR by Building a dApp

In the fast-paced world of blockchain technology, the NEAR Protocol shines as a pioneering platform for building decentralized applications (dApps). Its remarkable focus on usability, scalability, and developer-friendly features has made it the preferred choice for diverse applications. This chapter provides an essential overview of NEAR and why it stands out in the world of dApp development.

The NEAR Protocol represents a paradigm shift in blockchain development. It offers a robust infrastructure with high performance and user-friendliness at its core. NEAR’s unique sharded architecture ensures scalability by parallelizing transactions, enabling an impressive throughput of thousands of transactions per second. Its developer-centric approach abstracts complex blockchain mechanics, allowing developers to focus on creating secure and efficient smart contracts.

By the end of this chapter, you’ll have a comprehensive understanding of...

Technical requirements

Here’s what you will need to get started with the NEAR blockchain.

Prerequisites

To develop a smart contract, you will need to install Node.js. If you want to use Rust as your main language, then you’ll need to install rustup as well.

You’ll also need the following:

  • Node.js: Download and install Node.js (https://nodejs.org/en/download/)
  • Rust and Wasm:
    1. Follow these instructions for setting up Rust: https://doc.rust-lang.org/book/ch01-01-installation.html.
    2. Then, add the wasm32-unknown-unknown toolchain, which enables compiling Rust to WebAssembly (Wasm) – https://webassembly.org/– the low-level language used by the NEAR platform:
      # Installing Rust in Linux and MacOS
      curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
      source $HOME/.cargo/env
      # Add the wasm toolchain
      rustup target add wasm32-unknown-unknown

Next, we must set up the environment with the required installations.

Installation...

Introducing NEAR

In this section, we’ll embark on an exciting journey to explore the reasons why developers should choose the NEAR blockchain as their platform of choice for building dApps. We’ll delve into the essential concepts that form the foundation of NEAR’s ecosystem, starting with an in-depth understanding of accounts, addresses, and access keys. Furthermore, we’ll unravel the intricacies of smart contracts and the blockchain state in NEAR, equipping developers with the knowledge to unlock the full potential of this innovative platform.

Why choose NEAR?

The NEAR blockchain offers compelling reasons for Rust developers to choose it as their preferred platform for developing and deploying smart contracts. Rust is a highly robust and secure programming language known for its memory safety and performance, and NEAR provides a seamless integration of Rust into its development stack, making it an ideal choice for Rust developers.

Here are the...

Learning about the advanced concepts of NEAR

In this section, we’ll delve into the advanced concepts of the NEAR blockchain, expanding our understanding of its inner workings and exploring key topics that enable developers to build robust and scalable dApps. We will cover essential concepts such as transactions and gas, data flow, token management, storage optimization, validator networks, and the NEAR SDK.

First, we’ll talk about transactions and gas.

Transactions and gas

Transactions are the fundamental units of activity in the NEAR blockchain. They represent actions performed by accounts, such as transferring tokens, calling contract methods, or updating account data. To execute a transaction, users need to allocate gas, a unit of computation and storage resource, which determines the complexity and cost of the transaction.

Let’s explore a code example of a simple transaction using the NEAR SDK for Rust:

use near_sdk::borsh::{self, BorshDeserialize...

Getting started with the NEAR blockchain

At this point, we have clarity on most of the important concepts of NEAR Protocol. Now, we’ll get a bit more hands-on and delve into the core concepts of developing the NEAR blockchain. In this section, we will cover essential topics and tools that will equip you with the necessary knowledge to build robust dApps on NEAR.

By the end of this section, you will have a solid understanding of the core concepts and tools necessary for developing sophisticated dApps on the NEAR blockchain, empowering you to create innovative solutions within this thriving ecosystem.

First, we’ll explore the Contract class, which serves as the foundation for your smart contracts on NEAR. We will delve into the various modules, types, and structs that can be used to define and manipulate data within your contracts.

The Contract class

In NEAR Protocol, the Contract class provides a set of functionalities that allow developers to define and interact...

Creating our first project with NEAR

In this section, we will explore smart contract development using the NEAR Protocol. Our focus will be on creating a crossword game smart contract while leveraging the capabilities of NEAR to build an interactive and decentralized gaming experience.

Crossword games have always captivated people with their intellectual challenges and the joy of uncovering hidden words. Traditionally played on paper or in digital formats, crossword games have now found their way into the realm of blockchain technology. By building a crossword game smart contract, we can combine the time-tested enjoyment of crossword puzzles with the security, transparency, and decentralization provided by NEAR.

Let’s take a step-by-step journey to develop the crossword game smart contract. We will start by understanding the structure and rules of the crossword game itself.

Understanding the structure and rules of the crossword game

The smart contract we’ll...

Summary

In this chapter, we delved into the NEAR Protocol, a blockchain platform tailored for developers, and explored its foundational concepts. We discussed essential elements, such as accounts, access keys, smart contracts, and blockchain state, establishing a solid understanding of NEAR’s core principles. We highlighted NEAR’s developer-friendly ecosystem, which features implicit accounts, named accounts, full access keys, and function keys, making it an attractive choice for blockchain projects.

We also ventured into advanced topics, including transactions, gas, data flow, tokens, storage options, validators, and consensus mechanisms. This deep dive into NEAR’s intricacies demonstrated its robust capabilities for building dApps. Finally, we got hands-on experience by installing the NEAR SDK and NEAR CLI, creating a crossword game smart contract, and deploying it, illustrating the practicality and versatility of NEAR in application development.

In the...

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Rust for Blockchain Application Development
Published in: Apr 2024Publisher: PacktISBN-13: 9781837634644
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Akhil Sharma

Akhil Sharma is a Software Engineer and an entrepreneur. He is the CTO of Dominate, a SaaS product company, and the founder of Myrl Tech, a tech services company providing technology consulting to some of the top enterprise companies in the world such as HP, 3M, Honda, Bose, and Adobe. He has 12+ years of industry experience and a solid understanding of building digital products. He is adept at multiple programming languages such as Golang, Rust, Ruby, Python, and JavaScript. He has mentored hundreds of engineers offline and discovered that they knew the programming language and the concepts around it but were unable to use them in real-world applications. He aims to close this gap by teaching how to apply the concepts practically and build projects in real time.
Read more about Akhil Sharma