<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Drayfocus</title>
    <description>The latest articles on Forem by Drayfocus (@doctordrayfocus).</description>
    <link>https://forem.com/doctordrayfocus</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F614461%2F108d5b49-171c-4515-a54f-5a0284587337.jpg</url>
      <title>Forem: Drayfocus</title>
      <link>https://forem.com/doctordrayfocus</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/doctordrayfocus"/>
    <language>en</language>
    <item>
      <title>Best Practices for Building API Gateways in a Microservice Architecture</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Mon, 18 Jul 2022 20:08:53 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/best-practices-for-building-api-gateways-in-a-microservice-architecture-1k9j</link>
      <guid>https://forem.com/doctordrayfocus/best-practices-for-building-api-gateways-in-a-microservice-architecture-1k9j</guid>
      <description>&lt;p&gt;In a microservice architecture, the API gateway is a centralized hub that aggregates and distributes information from various services  It is the main entry point for all microservices in the architecture that communicates with all other microservices, parses incoming requests and responses, and then routes them to the appropriate services. It also allows clients to access the application via HTTP, forming a layer between the client and the rest of the microservice architecture. &lt;/p&gt;

&lt;p&gt;API gateways provide three main services:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Authentication - The apigateway authenticates users and handles authorization. This means that it controls who can access the application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Authorization - The apigateway handles authorization for requests from clients, ensuring that they can only perform operations allowed by their role or permission level.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Routing - The apigateway routes requests to appropriate microservices based on their path, as defined by a routing table definition.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Benefits of building API gateways.
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It can handle authentication, authorization and logging for multiple microservices&lt;/li&gt;
&lt;li&gt;It provides a common platform for data consumption by different microservices&lt;/li&gt;
&lt;li&gt;It ensures standardized communication between microservices&lt;/li&gt;
&lt;li&gt;It can be used to cache data, which improves response time by reducing network latency and bandwidth usage&lt;/li&gt;
&lt;li&gt;You can easily scale your application horizontally and vertically by deploying multiple instances of the API gateway&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Best practices for setting up an effective API gateway.
&lt;/h2&gt;

&lt;p&gt;Here are 5 best practices you can put in place to build an effective API gateway system.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Setup a Network Handler
&lt;/h3&gt;

&lt;p&gt;This is a substantial setup for an API gateway. A network handler is a piece of code that is in charge of sending and retrieving data from other microservices. It communicates directly with the Rest API exposed by each microservice.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LnMuclU2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/J7aK510.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LnMuclU2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/J7aK510.png" alt="Setup a Network Handler" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Consider Direct Database Queries
&lt;/h3&gt;

&lt;p&gt;Direct Database Queries are used to retrieve data from a microservice database using a database user who has read-only access. This works best when the microservices use SQL databases, which allow for complex join queries. This might be a good idea when you need to combine query results from multiple microservices, doing so over the network handler can be expensive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--JDTkoFc1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/XP9ymkk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--JDTkoFc1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/XP9ymkk.png" alt="Direct Database Queries" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Setup a Data Aggregator
&lt;/h3&gt;

&lt;p&gt;A data aggregator's purpose is to collect data from Network Handler or Direct DB queries, process or modify it, and package it in a format that can be sent to a client.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AGKThsDl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ZV7eT2M.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AGKThsDl--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/ZV7eT2M.png" alt="Setup a Data Aggregator" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Implement caching into your Network Handler
&lt;/h3&gt;

&lt;p&gt;Caching is essentially a method for your API gateway to save information about all previous requests so that if you receive another request with the same parameters, the gateway will know not to go through the process of actually making the call. Instead of making another call, it will simply retrieve the data from its cache memory and return it because fewer calls are made overall, the load on your servers is reduced, which improves performance and lowers costs.&lt;/p&gt;

&lt;p&gt;In your network handler, caching occurs during the GET request and is then cleared or updated during the POST, UPDATE, or DELETE request. Caching should also be made optional for GET requests containing data that is likely to change frequently over time.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. Implement event based request in your Network Handler
&lt;/h3&gt;

&lt;p&gt;There are two types of requests you can make through your network handler: synchronous and asynchronous. Synchronous requests necessitate the network handler waiting for a response before proceeding with its own processes. Asynchronous requests do not necessitate the network handler waiting for a response before going about its business.&lt;/p&gt;

&lt;p&gt;You can create asynchronous requests using event-based request functionality without sacrificing functionality or performance. This functionality is best suited for PUT, POST, or DELETE requests that do not require an immediate response.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion.
&lt;/h2&gt;

&lt;p&gt;So far, you have learned that API gateways are single points, the benefits of building API gateways, and lastly, 5 tips to building effective API gateway systems which are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Setting up a Network Handler&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Using Direct Database Queries&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Setting up a Data Aggregator&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implementing caching into your Network Handler&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implementing event based request in your Network Handler&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bonus.
&lt;/h2&gt;

&lt;p&gt;I decided to make a simple template generator for API Gateways. This template generator implements all of the suggestions made in this article. The template generator is available on &lt;a href="https://github.com/Doctordrayfocus/ApiGateway-Generator"&gt;github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the meantime, the template generator only works for PHP projects; a NodeJS version is in the works. If you can help build for other languages like Python, Go, and so on, please contact me on Twitter at &lt;a href="https://twitter.com/drayfocus"&gt;drayfocus&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can connect to me on Twitter  &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt;, and Linkedin  &lt;a href="https://www.linkedin.com/in/drayfocus"&gt;Akinola Ayomide&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>api</category>
    </item>
    <item>
      <title>Five ways to optimize your backend APIs in a microservice architecture</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 09:26:59 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/five-ways-to-optimize-your-backend-apis-in-a-microservice-architecture-3071</link>
      <guid>https://forem.com/doctordrayfocus/five-ways-to-optimize-your-backend-apis-in-a-microservice-architecture-3071</guid>
      <description>&lt;p&gt;In the beginning, there was the monolith. And it was good. You had one application, with a single code base, and it did everything you needed.&lt;/p&gt;

&lt;p&gt;But then your business grew, and so did your code base. It started to get hard to manage and maintain, so you split it into multiple services. Then you split those up into even smaller services because each of those new services had their own code base and database.&lt;/p&gt;

&lt;p&gt;This is what we call microservice architecture. It's an architectural style where your application is made up of lots of small services (microservices) that work together. Each microservice has its database, programming language, and the team responsible for maintaining it — but they don't have access to any other microservices in the system.&lt;/p&gt;

&lt;p&gt;Building a backend system in your microservice architecture is froth with a few problems, so in this article, you are going to learn how to optimize your APIs in a backend service, and address some problems you are likely going to face.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is API optimization?
&lt;/h2&gt;

&lt;p&gt;API optimization is a process that can be used to improve the performance of your application. Optimizing your API can help reduce latency, decrease response times and improve the user experience.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why should you optimize your API?
&lt;/h2&gt;

&lt;p&gt;By optimizing your API, you will be able to:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Shorten the amount of time it takes developers to integrate with your API.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduce the amount of code required to integrate. This will save you money and increase developer productivity.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Reduce the number of bugs in your API to improve user satisfaction and save money on support costs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Serve a large number of users who are using your API with various devices, browsers, and networks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Five ways to optimize your backend APIs in a microservice architecture
&lt;/h2&gt;

&lt;p&gt;When developing your backend APIs in a microservice architecture, some optimizations must be made to improve application performance. Here are some ideas to help you get there.&lt;/p&gt;

&lt;h3&gt;
  
  
  1.  Use the APIGateway pattern instead of directing clients to multiple microservices.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--g4DORHJg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/D4qRhFf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--g4DORHJg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/D4qRhFf.png" alt="Direct client to multiple microservices patterns" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The direct client to multiple microservices patterns allows one client to communicate with multiple microservices by connecting directly to their backend APIs.&lt;/p&gt;

&lt;p&gt;One significant disadvantage of this pattern is that it can be difficult to manage the overall architecture. This is because you must configure all of the communication between each of your clients and each service, which can be time-consuming and error-prone.&lt;/p&gt;

&lt;p&gt;Another disadvantage is that it does not scale well. When there are too many microservices, it becomes more difficult for your clients to communicate with each one, slowing their ability to send requests and receive responses from each one. This may imply that your system isn't capable of handling as much traffic as it could. Also, security may be an issue in this pattern because all of your microservices are exposed to external API access, exposing your application to multiple points of attack.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EjqsUe8R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/XwOc5B8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EjqsUe8R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/XwOc5B8.png" alt="API gateway pattern" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;An API gateway pattern, on the other hand, is a microservice pattern that enables different microservices to work collaboratively in a distributed system. The API gateway pattern is made up of two parts: the gateway and the API clients. The gateway is in charge of receiving client requests, processing them, and responding to them. The client is in charge of sending requests to and receiving responses from the gateway.&lt;/p&gt;

&lt;p&gt;The pattern allows you to build an API gateway that receives calls from other microservices and responds to them on their behalf. The API gateway has its own set of rules and policies that it enforces to ensure that only the appropriate calls are made to the appropriate microservices.&lt;/p&gt;

&lt;p&gt;With this pattern, all of your microservices are protected within an internal API system, with only the API Gateway exposed to the outside world. It improves each microservice's autonomy, scalability, and deployment flexibility.&lt;/p&gt;

&lt;h3&gt;
  
  
  2.  Use one database per service instead of a shared-database pattern.
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uU5lAEuI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/zKGZfYC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uU5lAEuI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/zKGZfYC.png" alt="Shared-database pattern" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The shared-database pattern is a microservice architecture that employs a shared database to establish a single point of data truth. Because the same database is used across the microservices, you can perform complex queries on the data. While this works well for small applications, it can become complicated for larger ones. For example, if one microservice changes its database schema, other microservices may need to be notified so that they can update their database schema accordingly. There is also a single point of failure for your application because if the database fails, all of your services fail. Because all database workload from all of your microservices is routed to a single database, your API performance may suffer.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--bh0SMWQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/8cty1oz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--bh0SMWQn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://i.imgur.com/8cty1oz.png" alt="Database-per-service pattern" width="880" height="495"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The Database-per-Service pattern is one in which each microservice has its database that is configured to be isolated from the others. Each microservice has its database, which can only be accessed by the microservice to which it belongs. This prevents the various databases from interfering with each other or becoming mixed up, making it easier to manage and keep them clean. This pattern directs all database workloads to their respective databases, making it easier to maintain and scale.&lt;/p&gt;

&lt;p&gt;Data from each service can only be accessed through the API provided by the service. While this may be fine for backend systems that do not require complex data queries across multiple microservice data sets, it can lead to "API Hell" for those that do.&lt;/p&gt;

&lt;h3&gt;
  
  
  3.  Avoid “API Hell”.
&lt;/h3&gt;

&lt;p&gt;API Hell is a microservice API architecture design pattern in which a single data query action requires multiple API requests to multiple microservices. The network latency that exists when making network requests to other microservices, as well as the n+1 issues that may arise when combining queries for different microservices, make this approach a bad idea.&lt;/p&gt;

&lt;p&gt;In an e-commerce application, for example, you might want to get all users' orders and order delivery information. The User microservice holds your users' data, the Order microservice holds your orders, and the Delivery microservice holds your delivery information. To obtain the final data, first, request the User microservice to obtain the users (n), then for each user, obtain their orders from the Order microservice (n+1), and finally, obtain their delivery information for each order (n+2). Keep in mind that each data request requires an API call. While this may not be noticeable when dealing with small amounts of data, it can cause a significant drop in API performance as your data grows. So, how do you solve this?&lt;/p&gt;

&lt;p&gt;Here are some approaches you can take to deal with this:&lt;/p&gt;

&lt;h4&gt;
  
  
  - Duplicate your data:
&lt;/h4&gt;

&lt;p&gt;You can choose to make a copy of the database table that contains related data between microservices. Create a system that updates each copy of the database table when the original table is updated. This allows you to easily combine those data and create your complex query.&lt;/p&gt;

&lt;p&gt;The problem with this approach is that it does not ensure data consistency and integrity. Data updates will not be real-time, and any problems that cause a failure in the update of other copies of a database will cause them to be out of sync with inconsistent data.&lt;/p&gt;

&lt;h4&gt;
  
  
  - Directly read microservices databases from your API Gateway.
&lt;/h4&gt;

&lt;p&gt;You can delegate the heavy lifting to your API gateway. For SQL databases used by microservices, you can create a new read-only database user that reads and combines database tables from different microservices and performs complex join queries at the database level. You can avoid the n+1 problem and data inconsistency issues while still retaining the flexibility and scalability that microservices provide. Data integrity can be ensured because ApiGateway access is read-only, and updates to the database can only be made by the microservice that owns it.&lt;/p&gt;

&lt;p&gt;The temptation to move some business logic to the APIGateway is a problem with this approach. You should avoid this at all costs because you undermine the purpose of microservices. Only queries that are not microservices specific should be directed to your APIGateway's database query modules. Database write actions (update, create, and delete) and complex microservices-specific actions are still routed through the API to the appropriate microservice.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.  Implement event-based actions.
&lt;/h3&gt;

&lt;p&gt;Microservices rely heavily on event-based actions. They enable the microservice to sync with other services as needed, reducing overall system latency. This is especially important when multiple services are involved in an interaction, or when working on an application that requires quick action and response times. Client requests to your API Gateway can trigger events, which are then handled by the corresponding microservice.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.  Implement Cache
&lt;/h3&gt;

&lt;p&gt;Caching can be used in a microservice architecture to improve performance and scalability by reducing the number of API calls made to backend services. It's especially useful if your application receives a lot of traffic or needs to handle a lot of requests per second. Requests to other microservices that do not return frequently changing data, such as a list of countries or regions, can be cached on your APIGateway. Instead of making API requests to the microservice every time, your APIGateway can easily get this data from the cache.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So far, you’ve learned about API optimization for microservice architecture. You understood why you need to optimize your APIs and got introduced to five ways to optimize your APIs which include:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use the APIGateway pattern instead of directing clients to multiple microservices.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use one database per service instead of a shared-database pattern.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Avoid “API Hell”.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement event-based actions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Implement Cache.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can connect to me on Twitter  &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt;, and Linkedin  &lt;a href="https://www.linkedin.com/in/drayfocus"&gt;Akinola Ayomide&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>microservices</category>
      <category>backend</category>
      <category>api</category>
    </item>
    <item>
      <title>Building a scalable system from the ground up</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 09:23:47 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/building-a-scalable-system-from-the-ground-up-1eng</link>
      <guid>https://forem.com/doctordrayfocus/building-a-scalable-system-from-the-ground-up-1eng</guid>
      <description>&lt;p&gt;There is a lot to be gained from designing a scalable system from the ground up, especially if you are building it for a startup that is still in its early stages and has the potential to grow. As developers, we are frequently faced with the choice of ignoring scalability and building (version 1) faster or incorporating scalability into the system and moving a little slower. Doing it, either way, has no visible effect at first, but as the system grows larger and begins to do more work, the scalability of the system will be put to test.&lt;/p&gt;

&lt;p&gt;At &lt;a href="https://www.ceedcap.com/"&gt;Ceedcap&lt;/a&gt;, a start-up studio where I work as a software engineer, the majority of my time is spent designing and developing scalable systems for start-up businesses. It can be difficult to create such a system for projects that must move quickly. But, over time, I was able to decipher the code. To explain my approach, I'll use the most recent project I'm working on (Squareroof) as a case study.&lt;/p&gt;

&lt;p&gt;Case study: &lt;a href="https://www.mysquareroof.com/"&gt;Squareroof&lt;/a&gt;- a platform to easily own shares of rental properties. &lt;/p&gt;

&lt;p&gt;Goal: To build a system that enables users to buy shares of properties, administrators to manage the platform activities, and collect and analyze real-estate data.&lt;/p&gt;

&lt;p&gt;Timeline (Version 1): 5 weeks&lt;/p&gt;

&lt;p&gt;Approach:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Use a popular project structure and framework
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mVHjo_5g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1649620111394/T9QbfEdIx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mVHjo_5g--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1649620111394/T9QbfEdIx.png" alt="backend-frameworks.png" width="750" height="500"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by &lt;a href="https://www.mindinventory.com/blog/best-backend-frameworks/"&gt;Mindinventory&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A software project structure is a set of rules that determine how your code, files, and folders will be organized. The project structure makes it easier to find things and for new contributors to understand how your project is organized. It also makes it simple for your team to maintain the same organizational approach from project to project.&lt;/p&gt;

&lt;p&gt;Using a popular project structure appears to be the obvious approach, but we are often tempted to create our own, especially when our language of choice does not enforce any. For example, if you use Nodejs, use common project templates provided by frameworks such as Express, if you use Python, use Flasks or Django, and if you use PHP, use Laravel, CodeIgniter, and so on.&lt;/p&gt;

&lt;p&gt;The benefit of this is that it makes it easier to onboard new developers who will work on the codebase as the product grows. I chose Laravel Lumen for the backend and VueCLI project structure for the frontend for Squareroof.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Choose Microservice over Monolithics:
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FKCS_otc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1649620632997/MS5z0ExGC.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FKCS_otc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1649620632997/MS5z0ExGC.png" alt="Microservices-1024x796.png" width="880" height="684"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by &lt;a href="https://www.krasamo.com/microservices-architecture-for-real-world-business-needs/"&gt;Krasamo&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Monolithic applications contain everything—front-end, back-end, and databases—in a single location. Because all of the application's components are in one place, they are simple to build and deploy. Microservices is a type of architecture that divides a large computer program into smaller, modular programs. It allows each section of your code to operate independently and focus on its functionality while still communicating with other sections as needed.&lt;/p&gt;

&lt;p&gt;I've built several monolithic projects that worked well at first but became a pain as the codebase grew and new features were added. It became more difficult to navigate. This also has an impact on the rate at which new features or changes can be implemented.&lt;/p&gt;

&lt;p&gt;Splitting the project components into microservices, on the other hand, made the codebase more manageable and easier to navigate. This is in addition to the benefits of long-term scalability.&lt;/p&gt;

&lt;p&gt;Microservices can be difficult and time-consuming to set up. However, with the advent of tools such as Docker and Kubernetes, it is becoming easier. For Squareroof, I decided to devote some of my time to developing a system that makes setting up and publishing a microservice as simple as setting up a monolithic application. This was accomplished by developing a common template for the backend microservices and a separate template for the frontend microservices, and then publishing them using the docker and Kubernetes APIs. This made it simple to quickly spin up a new microservice with only a few steps, without sacrificing scalability.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Set up CI/CD (Continuous Integration / Continuous Development) Pipeline
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DHtbDHGT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1649620428986/k518v6pV5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DHtbDHGT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1649620428986/k518v6pV5.png" alt="60d315cb607a32718b6e86c3_CICD pipelines work.png" width="800" height="480"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;Photo by &lt;a href="https://www.wallarm.com/what/what-is-ci-cd-concept-how-can-it-work/"&gt;Wallarm&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;A CI/CD pipeline is a set of processes that allows for frequent, dependable software releases. The process is known as "continuous integration" and "continuous deployment" because it is automated and can be repeated as many times as needed for new features and updates. It allows developers to automate the process of developing, testing and delivering code.&lt;/p&gt;

&lt;p&gt;Initially, I didn't see this as a critical step for Squareroof. To publish a new change, I had the habit of logging into the server and manually running each step. As the codebase grew in size, this became more difficult and time-consuming. Then I decided to implement a CI/CD pipeline by writing all of the manual steps into a script and triggered it whenever I made new changes. This not only gave me more time to code but also eliminated deployment errors and mistakes.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Building a system that can scale with the company can be difficult, but it will save you a lot of time and effort in the long run. You should also recognize that it is a journey. One does not simply build a scalable system and then stop; one must continue to improve on the existing system to fit into solving the problem that the product is addressing.&lt;/p&gt;

&lt;p&gt;Let's connect on Twitter &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt; and on LinkedIn &lt;a href="https://www.linkedin.com/in/drayfocus/"&gt;Akinola Ayomide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>scalability</category>
    </item>
    <item>
      <title>Rust Concepts for Writing Solana Programs</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 09:21:47 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/rust-concepts-for-writing-solana-programs-gd7</link>
      <guid>https://forem.com/doctordrayfocus/rust-concepts-for-writing-solana-programs-gd7</guid>
      <description>&lt;p&gt;Developers who turn to Solana do so because Solana has the ability to process many transactions per second. This is possible because Solana does not use only Proof-of-Work (PoW) or Proof-of-Stake (PoS) consensus algorithms like Bitcoin or Ethereum do. Instead, it uses an alternative consensus algorithm called Proof-of-History (PoH) which doesn't require massive amounts of energy like PoW or PoS does.&lt;/p&gt;

&lt;p&gt;Solana programs can be written in C, C++ and Rust programming languages. These programs are similar to smart contracts in Ethereum. In this article, you will learn some key concepts in Rust you need to know to write solana programs because unlike C and C++, Rust is a low-level language that gives the feel of a high-level language. Rust automatically takes care of low-level operations, but also exposes these low-level operations to developers. This makes Rust language fast, powerful, and easy to write.&lt;/p&gt;

&lt;p&gt;Rust Concepts for Solana Programs&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variable ownership&lt;/li&gt;
&lt;li&gt;Struct&lt;/li&gt;
&lt;li&gt;Vector, String, and HashMaps&lt;/li&gt;
&lt;li&gt;Enums and pattern matching&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;Packages, crates, and modules in Rust&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Variable Ownership
&lt;/h2&gt;

&lt;p&gt;Rust &lt;strong&gt;variables&lt;/strong&gt;, like any other programming language, have a life that is determined by the scope in which they are defined. This scope can be either local or global. Rust variables can also be mutable, immutable, or shadowed. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;Mutable&lt;/strong&gt;: These variables are assigned using the "let" keyword, and they can be reassigned. They can also be changed if their values are mutable. An example of a mutable variable is one whose value may change during the lifetime of the program. Examine the code  below:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;greetings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="n"&gt;greetings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello world"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Immutable&lt;/strong&gt;: These variables are assigned using the "const" keyword, and they cannot be reassigned at any point in the program. To make an immutable variable, add the "mut" keyword before it. An example of an immutable variable is one whose value will not change during the lifetime of the program.  Sample code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// variables are immutable by default&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;greetings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hello"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// this will throw an error&lt;/span&gt;
&lt;span class="n"&gt;greetings&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Hello world"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// You can make a variable mutable by adding the&lt;/span&gt;
&lt;span class="c1"&gt;// "mut" keyword&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"dancing"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// this would work&lt;/span&gt;
&lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"singing"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

&lt;span class="c1"&gt;// variables defined with the "const" keyword cannot &lt;/span&gt;
&lt;span class="c1"&gt;// be reassigned or made mutable&lt;/span&gt;

&lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;MY_ACTION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Walking"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// this will throw an error&lt;/span&gt;
&lt;span class="n"&gt;MY_ACTION&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"Dancing"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Shadowing&lt;/strong&gt;: This is simply a way of showing that you want to reassign a variable to a new one in Rust without changing its value or type. It involves declaring another variable with the same name as the old one and assigning it some value or expression that evaluates that value. Sample code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The value of count is: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;count&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are two types of variable ownership in Rust. These types are called, creatively enough, "Owning" and "Borrowing." &lt;/p&gt;

&lt;p&gt;An &lt;strong&gt;owning variable&lt;/strong&gt; owns the data it points to, so the data will be destroyed when that variable goes out of scope. &lt;strong&gt;Borrowed variables&lt;/strong&gt; do not own the data they point to, so this data will not be destroyed when that variable goes out of scope. &lt;/p&gt;

&lt;p&gt;You can have both owning and borrowing variables referring to the same piece of data, but you cannot have two owning variables or two borrowing variables referring to the same piece of data at the same time. This is because if you had multiple owning variables pointing to a single piece of data and all those variables went out of scope at the same time, Rust wouldn't know which one(s) should be responsible for destroying that piece of data. &lt;/p&gt;

&lt;p&gt;It would be like multiple people trying to eat a single hamburger: how do you decide who gets to keep it? Similarly, if two borrowing variables were pointing to a single piece of data and both tried to change it (for example by assigning a new value), Rust wouldn't know which one(s) should "win" over the other(s). This could easily lead to subtle bugs in your program where one borrows. Here is an example below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// You can declare your variable here&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Walking"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// You need to pass the variable into the "calculate_length" function,&lt;/span&gt;
&lt;span class="c1"&gt;// if pass it like this&lt;/span&gt;
&lt;span class="c1"&gt;// let len = calculate_length(action);&lt;/span&gt;
&lt;span class="c1"&gt;// This means you are transferring the ownership of "action" &lt;/span&gt;
&lt;span class="c1"&gt;// variable to the function "calculate_length",&lt;/span&gt;
&lt;span class="c1"&gt;// this means the variable would no longer be&lt;/span&gt;
&lt;span class="c1"&gt;// available in the "main" function scope again.&lt;/span&gt;

&lt;span class="c1"&gt;// But since you still need to use the variable &lt;/span&gt;
&lt;span class="c1"&gt;// in the "println!" macro below, instead of transferring ownership,&lt;/span&gt;
&lt;span class="c1"&gt;// you will send a borrowed reference of the &lt;/span&gt;
&lt;span class="c1"&gt;// variable to the "calculate_length" function.&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;calculate_length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The length of '{}' is {}."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;action&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;len&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;calculate_length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Struct
&lt;/h2&gt;

&lt;p&gt;In Rust, a struct is a custom data type that lets you define the data that you'll use in your code. It's a collection of variables (called fields) that can store different kinds of related information.&lt;/p&gt;

&lt;p&gt;Let's say you're building an app that lets users create a profile and track their favorite locations to have brunch. You'll want to keep track of each user's name, age, email address, and the number of times they've been to brunch this month. You can combine these variables into one data type called Profile, like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Profile&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

    &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;

    &lt;span class="n"&gt;times_been_to_brunch&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will use Struct to define and structure on-chain data when building Solana programs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Vector, String, and HashMaps
&lt;/h2&gt;

&lt;p&gt;These are custom variables in Rust and are known as &lt;strong&gt;Collections&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vectors&lt;/strong&gt; are like arrays. But unlike arrays, they can grow and shrink based on what's added to them or removed from them and you don't have to specify the length when you declare them.&lt;/p&gt;

&lt;p&gt;Vectors in Rust are helpful for when you want to store data in a contiguous area of memory. When you create a vector, it allocates memory along a single, continuous region of space that's guaranteed to be big enough to hold the amount of data you're asking it to. The only downside of vectors is that they can only store one type of data and they don't have key-value pairs. In Solana programs, Vectors are used to collect and handle instructions passed into the program. Here is an example of a vector:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_vector&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nd"&gt;vec!&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="n"&gt;my_vector&lt;/span&gt;&lt;span class="nf"&gt;.push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;my_vector&lt;/span&gt;&lt;span class="nf"&gt;.push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Strings&lt;/strong&gt; are collections of characters—like "Hello world!". They are another way to store data, but unlike vectors, strings are growable. That means you don't have to specify how big they'll be upfront (which is nice if you don't know how much data you'll need). Like vectors, strings can only store one type of data. But unlike vectors, strings are complicated—they're composed of multiple parts which help with things like indexing and slicing. Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt; &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"السلام عليكم"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Dobrý den"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"שָׁלוֹם"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"नमस्ते"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"こんにちは"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"안녕하세요"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"你好"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Olá"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Здравствуйте"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
 &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;hello&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hola"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;HashMaps&lt;/strong&gt; allows you to use keys and values for storing information. They're kind of like dictionaries: the key is the word and the value is the definition. Unlike strings and vectors, HashMaps can store different types of keys and values. But because keys are stored in buckets (which means the same bucket could contain multiple keys), HashMaps aren't great for keeping track of ordering. Here is an example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;std&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;collections&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;HashMap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;scores&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;HashMap&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Blue"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="nf"&gt;.insert&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;String&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Yellow"&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Enums and pattern matching
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Enums&lt;/strong&gt; are a way of grouping together different kinds of data. For example, you could have an enum that represents all the possible playing cards in a deck, like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nf"&gt;Club&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="nf"&gt;Spade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
   &lt;span class="nf"&gt;Heart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
   &lt;span class="nf"&gt;Diamond&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;pattern matching&lt;/strong&gt;:If you want to know what the highest-value card is in a player's hand in your card game, you can use pattern matching to write a function that takes a vector of Cards and returns the highest-value one. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;card_at_hand&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
   &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Club&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Spade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Heart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Diamond&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt; 

  &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;highest_card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;    &lt;span class="nf"&gt;find_highest_card&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;card_at_hand&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The largest card is: {:?}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;highest_card&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;#[derive(Debug)]&lt;/span&gt;
&lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;Card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
   &lt;span class="nf"&gt;Club&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
   &lt;span class="nf"&gt;Spade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
   &lt;span class="nf"&gt;Heart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
   &lt;span class="nf"&gt;Diamond&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;



  &lt;span class="c1"&gt;// This function will get the highest card from a vector collection of different cards&lt;/span&gt;
  &lt;span class="c1"&gt;// passed into it as an argument.&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;find_highest_card&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hand&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;Card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="c1"&gt;// create a mutable variable that will hold the largest card&lt;/span&gt;
&lt;span class="c1"&gt;// by default you can create a dummy card&lt;/span&gt;
     &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;high_card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Club&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

     &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

     &lt;span class="c1"&gt;// now lets loop through the card and use 'match' to filter out the &lt;/span&gt;
     &lt;span class="c1"&gt;// highest card&lt;/span&gt;
     &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;hand&lt;/span&gt;&lt;span class="nf"&gt;.iter&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;match&lt;/span&gt; &lt;span class="n"&gt;card&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="c1"&gt;// if this card matches a club, get its number and check if it is the highest &lt;/span&gt;
             &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Club&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                 &lt;span class="n"&gt;high_card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Club&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                 &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
             &lt;span class="p"&gt;},&lt;/span&gt;
             &lt;span class="c1"&gt;// if this card matches a spade, get its number and check if it is the highest&lt;/span&gt;
             &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Spade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                 &lt;span class="n"&gt;high_card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Spade&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                 &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
             &lt;span class="p"&gt;},&lt;/span&gt;
             &lt;span class="c1"&gt;// if this card matches a heart, get its number and check if it is the highest&lt;/span&gt;
             &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Heart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                 &lt;span class="n"&gt;high_card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Heart&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                 &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
             &lt;span class="p"&gt;},&lt;/span&gt;
             &lt;span class="c1"&gt;// if this card matches a diamond, get its number and check if it is the highest&lt;/span&gt;
             &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Diamond&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                 &lt;span class="n"&gt;high_card&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;Card&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;Diamond&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
                 &lt;span class="n"&gt;highest_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="n"&gt;num&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
             &lt;span class="p"&gt;},&lt;/span&gt;
             &lt;span class="c1"&gt;// if the card doesn't fit any of the above conditions, do nothing&lt;/span&gt;
             &lt;span class="n"&gt;_&lt;/span&gt; &lt;span class="k"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

     &lt;span class="p"&gt;}&lt;/span&gt;

     &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;high_card&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the Solana program, Enum is useful for matching instructions to the right function that would execute the instruction. It works like a web router in many web programming frameworks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Error handling
&lt;/h2&gt;

&lt;p&gt;Rust has a fairly simple set of tools for error handling.&lt;/p&gt;

&lt;p&gt;Rust has a very simple mechanism for handling errors: the Result type, which is an enum that can have either an 'Ok' or an 'Err' variant. Result types can be used in conjunction with functions that have returned, and when those functions are called, the return value of the function will be a Result type. Below is an example of  how this works with a couple of functions with the first function returning an integer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This function will return an integer when you call it, but if you wanted to use it in a situation where the user could input something other than an integer, you can adjust the function to return a Result instead:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Solana programs, you will use the 'Ok' and 'Err' variants of the Result Enum to handle return results or handle errors.&lt;/p&gt;

&lt;h2&gt;
  
  
  Packages, crates, and modules in Rust
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Packages&lt;/strong&gt; help developers organize their libraries and modules help us organize our code. &lt;/p&gt;

&lt;p&gt;Packages are collections of crates. These *&lt;em&gt;crates *&lt;/em&gt; are "libraries" or "modules" that can be linked to other crates. Crates have a special root module named after the crate's base directory which contains all the public items in the crate. A single crate can contain multiple files, but there can only be one crate per directory. &lt;/p&gt;

&lt;p&gt;Rust has two kinds of crates: binary and library. The main function inside of a binary crate will be compiled into an executable file that runs as a stand-alone file. Binary crates cannot be linked to other crates as library crates can. Instead, they will be run from the command line with the command ".exe". Library crates cannot contain any main functions and will instead be compiled into a ".dll" file (on Windows) or ".so" file (on Unix). The .dll or .so file contains code that is linked to other library crates for use by others. &lt;/p&gt;

&lt;p&gt;You will make use of many Solana libraries when building a program, which will provide some helper functions that would make building easier. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In the article, you learned about concepts in Rust used in writing Solana Programs. Concepts such as :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variable ownership&lt;/li&gt;
&lt;li&gt;Struct&lt;/li&gt;
&lt;li&gt;Vector, String, and HashMaps&lt;/li&gt;
&lt;li&gt;Enums and pattern matching&lt;/li&gt;
&lt;li&gt;Error handling&lt;/li&gt;
&lt;li&gt;Packages, crates, and modules in Rust. For further information, you can read &lt;a href="https://doc.rust-lang.org/book/title-page.html"&gt;Rust documentation&lt;/a&gt;. In the next article, you  will learn how to build a Solana program and launch it on the Solana test blockchain.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Lets connect on Twitter &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt; and on LinkedIn &lt;a href="https://www.linkedin.com/in/drayfocus/"&gt;Akinola Ayomide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>rust</category>
      <category>solana</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>I Simply Want To Build</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 09:15:48 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/i-simply-want-to-build-nbf</link>
      <guid>https://forem.com/doctordrayfocus/i-simply-want-to-build-nbf</guid>
      <description>&lt;p&gt;It all started when I saw a mud house project at school. I was only five years old, and I remember being astounded. The mud house was about the height of a red-paint bucket, had a green aluminum roof, and had four rooms with orange bulbs dangling from the roof each. I took turns with my classmates flipping the bulb switches, our excitement going through the roof anytime the orange light came on. &lt;/p&gt;

&lt;p&gt;This project sparked my curiosity so much that I decided to build my own. I spent the majority of my childhood and adolescence attempting to do so. I recall spending the money I received for my 16th birthday on building materials (cardboard, gum, cartons, and so on).&lt;/p&gt;

&lt;p&gt;I tried numerous times to replicate the mud house project, but I always failed. It's either that I couldn't figure out how to make it work or that I ran out of resources to do so.&lt;/p&gt;

&lt;p&gt;When I was 18, I became interested in programming. A friend recommended it to me. He told me I could build things with it. I was intrigued because I had always wanted to build something. I resolved to find out how I could do so.&lt;/p&gt;

&lt;p&gt;I've spent the last five years of my life learning and building websites. I adore the fact that I can build anything I want using only my PC. I am no longer limited by how many resources I can obtain, but rather by how much I can imagine. Every day, I jump out of bed, eager to explore my world of limitless possibilities.&lt;/p&gt;

&lt;p&gt;Not only do I want to build things, but I also want to build them well. This motivates me to learn about a variety of programming languages, frameworks, and software development domains. I currently have experience with front-end development, backend development, mobile app development, and DevOps.&lt;/p&gt;

&lt;p&gt;Programming inspired me to create software, but I still want to do more. I'm hoping that one day I'll be able to build my mud house project.&lt;/p&gt;

&lt;p&gt;I love creating things. Let's talk about it if that's something you're interested in.&lt;/p&gt;

&lt;p&gt;Twitter - &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;LinkedIn - &lt;a href="https://www.linkedin.com/in/drayfocus/"&gt;Ayomide Akinola&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Introduction to Rust Programming for Solana</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 09:12:45 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/introduction-to-rust-programming-for-solana-24m0</link>
      <guid>https://forem.com/doctordrayfocus/introduction-to-rust-programming-for-solana-24m0</guid>
      <description>&lt;p&gt;Solana programs can be written in C, C++ and Rust programming language. These programs are similar to smart contracts in Ethereum. C and C++ are low-level languages because many computer low-level operations like memory management are not done automatically, but they are much faster than high-level languages like Python, Javascript, PHP and so on, which take care of low-level operations automatically. On the other hand, Rust is a low-level language that gives the feel of a high-level language. Rust automatically takes care of low-level operations, but also exposes these low-level operations to developers. This makes Rust language fast, powerful, and easy to write.&lt;/p&gt;

&lt;p&gt;This article is part of a &lt;a href="https://drayfocus.hashnode.dev/series/building-on-solana"&gt;series&lt;/a&gt; and in the article series, I will introduce some basic concept of  Rust programming that is needed to successfully write a solana program. For this article I will address the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installing Rust and Cargo&lt;/li&gt;
&lt;li&gt;Writing your first Rust program&lt;/li&gt;
&lt;li&gt;Rust common programming concepts&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Installing Rust and Cargo
&lt;/h2&gt;

&lt;p&gt;We need to have Rust installed on our machine to run Rust code. To install Rust, follow this &lt;a href="https://www.rust-lang.org/tools/install"&gt;installation documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you are done with the installation, type this in your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;rustc --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This prints out the Rust compiler version installed.&lt;/p&gt;

&lt;p&gt;Rust, like many other low-level languages, has to be compiled to machine language before running. Rustc is responsible for that.&lt;/p&gt;

&lt;p&gt;Cargo, rust equivalent to Javascript's NPM and PHP's Composer is also installed when you install Rust. Apart from package (also know as crate) management, cargo is used to improve Rust development flow, such as compiling and running code with a single command and setting up a new Rust project with a standard folder structure.&lt;/p&gt;

&lt;p&gt;To confirm Cargo was installed on your machine run,&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cargo --version
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should print out the cargo version installed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Write your first Rust program
&lt;/h2&gt;

&lt;p&gt;To get started, open your terminal to the folder you want your program to be. Then create a new program using this command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cargo new my_first_program
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should print this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Created binary (application) `my_first_program` package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see a new folder named "my_first_program" created in your present folder. Open the "my_first_program" folder in your favourite code editor. For me, I use VSCode, here is the content of my folder,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--feejRZMQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645953392732/TX3rrrcsb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--feejRZMQ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1645953392732/TX3rrrcsb.png" alt="Screenshot from 2022-02-27 10-14-35.png" width="300" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The file "Cargo.toml" is similar to package.json in Javascript or composer.json in PHP. It is used to manage rust dependecies in your program.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;package&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"my_first_program"&lt;/span&gt;
&lt;span class="n"&gt;version&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"0.1.0"&lt;/span&gt;
&lt;span class="n"&gt;edition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"2021"&lt;/span&gt;

&lt;span class="cs"&gt;# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;dependencies&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Inside the "src" folder, you have "main.rs" file. Rust files end with .rs extension. This main.rs is the entrypoint of the program, similar to index.js in Javascript. It contains a function "main",&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;"fn" is used to define a function in Rust, and "printIn!" marco is similar to console.log() in Javascript or print() in python. &lt;/p&gt;

&lt;p&gt;Now that  you have your first program setup, let's run it. Open your teminal and make sure it is on your program directory, then run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="n"&gt;cargo&lt;/span&gt; &lt;span class="n"&gt;run&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will compile your code then run it. The output should be similar to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Compiling my_first_program v0.1.0 (/home/dray/www/Rust/my_first_program)
    Finished dev [unoptimized + debuginfo] target(s) in 1.25s
     Running `target/debug/my_first_program`
Hello, world!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you can also try it out on this interactive code editor.&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://codepen.io/drayfocus/pen/GROXbxx"&gt;https://codepen.io/drayfocus/pen/GROXbxx&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Congratulations! You just built your first Rust program. To build a complex Rust program, you will need to understand  how to use variables, functions and other programming concepts in Rust.&lt;/p&gt;

&lt;h2&gt;
  
  
  Rust common programming concepts
&lt;/h2&gt;

&lt;p&gt;Like every programming language, Rust makes use of common programming concepts like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Variables&lt;/li&gt;
&lt;li&gt;Constant&lt;/li&gt;
&lt;li&gt;Function&lt;/li&gt;
&lt;li&gt;Loops&lt;/li&gt;
&lt;li&gt;Control flow&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's explore each concepts&lt;/p&gt;

&lt;h3&gt;
  
  
  Variables
&lt;/h3&gt;

&lt;p&gt;Variables in Rust are defined with the "let" keyword. For example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"hello world"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Rust, there are two types of variable datatype. Scalar and compound datatypes. &lt;/p&gt;

&lt;h4&gt;
  
  
  Scalar datatypes
&lt;/h4&gt;

&lt;p&gt;Scalar datatypes are datatypes that holds just a single value. Here are some Rust scalar datatype:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Intergers
Integers are numbers that can either be positive or negative. Unsigned integers can only take positive values (so no need of adding + or - sign, because they will always be positive), while signed interger can take both negative and positive values. Integers are also represented by the range of number they can store. For example, a signed 8-bit number can store numbers from -128 to 127 (check &lt;a href="https://www.tutorialspoint.com/unsigned-and-signed-binary-numbers"&gt;here&lt;/a&gt; to learn how to make the calculation).  Here are some examples of integers in rust
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The default number datatype is u32 (unsigned 32-bit integer)&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_number&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// signed 32-bit &lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;signed_number&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// unsigned 8-bit&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;49&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// signed 8-bit&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;i8&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Floating point number&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This datatype holds decimal numbers. It has two types based its bit length, 32-bit (f32) and 64-bit (f64). f64 is the default in rust.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// default is f64&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_float&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;35.41&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// float with f32&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_other_float&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;f32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mf"&gt;23.4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Boolean
Boolean are true or false values.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;false&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_other_boolean&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;String&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This datatype is use for storing string values. It used double quotes around its content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s"&gt;"My rust program"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Characters&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These datatypes are used to store letters and characters, such as alphabets, emojis, Japanese aphabets and so on. It uses single quotes around its content&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_char&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sc"&gt;'Ƶ'&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;love_emoji&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;'❤️'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Compound datatypes
&lt;/h4&gt;

&lt;p&gt;These are datatypes that holds multiple values into one type. They are of two primitive types, tuples, and arrays.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Tuples&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tuples hold multiple datatypes into one. It has a fixed size, that is, it cannot grow or shrink in size.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_tuple&lt;/span&gt;&lt;span class="p"&gt;:(&lt;/span&gt;&lt;span class="nb"&gt;i32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;45.23&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;true&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can access each item of a tuple by referencing the item's index,&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://codepen.io/drayfocus/pen/ZEaqzeR"&gt;https://codepen.io/drayfocus/pen/ZEaqzeR&lt;/a&gt;]&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Array hold many datavalues, but every items in it must be of the same datatype. It  also has a fixed size like tuples.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_other_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"monday"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"tuesday"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s"&gt;"wednesday"&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="c1"&gt;// this array must contain f64 datatype and must have a lenght of 5&lt;/span&gt;
&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_another_array&lt;/span&gt;&lt;span class="p"&gt;:[&lt;/span&gt;&lt;span class="nb"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mf"&gt;2.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;45.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;56.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;45.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;45.6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Items in a array can be obtained by referencing its index,&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://codepen.io/drayfocus/pen/dyZgbZy"&gt;https://codepen.io/drayfocus/pen/dyZgbZy&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Vectors are another compound datatypes in Rust, but they are not primitive datatypes. Vectors are like arrays, in that they only take items of similar types, but they can have a variable size (items can be added or removed).&lt;/p&gt;

&lt;h3&gt;
  
  
  Functions
&lt;/h3&gt;

&lt;p&gt;Functions in Rust are similar to functions in other programming languages. It is used in executing blocks of code a line at a time. The "main" function is the entrypoint of a rust program, other functions can be called in the main function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// in your main.rs&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Hello, world!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nf"&gt;my_new_function&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;my_new_function&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I was called, and I am working!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run "cargo run" in your terminal to build and run the code. The output should be similar to this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Blocking waiting for file lock on package cache
    Blocking waiting for file lock on package cache
   Compiling my_first_program v0.1.0 (/home/dray/www/Rust/my_first_program)
    Finished dev [unoptimized + debuginfo] target(s) in 37.28s
     Running `target/debug/my_first_program`
Hello, world!
I was called, and I am working!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or run it on this interactive code editor&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://codepen.io/drayfocus/pen/oNoavyg"&gt;https://codepen.io/drayfocus/pen/oNoavyg&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Functions can also take parameters and these parameters needs to be typed&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;my_func_para&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;34.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;45&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;my_func_para&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;para1&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;f32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;para2&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"First parameter: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;para1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Seconde parameter: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;para2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On interactive code editor&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://codepen.io/drayfocus/pen/qBVJWMW"&gt;https://codepen.io/drayfocus/pen/qBVJWMW&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Functions can also return data. This returned data needs to be typed&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"5 multiple by 2: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;multiply_by_two&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"60 divided by 5: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nf"&gt;divide_by_five&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// with the return keyword and semicolon&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;multiply_by_two&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// without the return keyword and semicolon&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;divide_by_five&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On the interactive editor&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://codepen.io/drayfocus/pen/ExbdYOz"&gt;https://codepen.io/drayfocus/pen/ExbdYOz&lt;/a&gt;]&lt;/p&gt;

&lt;h3&gt;
  
  
  Loops
&lt;/h3&gt;

&lt;p&gt;Loops are used to run a block of code in a repeated manner. There are three type of loops in Rust: &lt;strong&gt;loop&lt;/strong&gt;, &lt;strong&gt;while&lt;/strong&gt; loop, &lt;strong&gt;for&lt;/strong&gt; loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;loop_example&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;while_loop_example&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;for_loop_example&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;loop_example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// create a mutable variable.&lt;/span&gt;
    &lt;span class="c1"&gt;// Variables are immutable by default, so we need to add the mut keyword&lt;/span&gt;
    &lt;span class="c1"&gt;// to make it mutable&lt;/span&gt;
    &lt;span class="c1"&gt;// I will explain the concept of variable mutability and referencing&lt;/span&gt;
    &lt;span class="c1"&gt;// in the next article.&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// create a loop&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;loop&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="c1"&gt;// repeatedly add one to counter&lt;/span&gt;
        &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="c1"&gt;// break out of the loop if counter equals 10&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;break&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"The result is {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;while_loop_example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// create a mutable variable&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// while counter is not equal to 0, run the block of code&lt;/span&gt;
    &lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"counter is: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// counter is now zero, this will run!&lt;/span&gt;
    &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Counter is empty!"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;for_loop_example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// create an array&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_items&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="c1"&gt;// loop through all the array items&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;my_items&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"for loop item: {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In an interactive code editor&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://codepen.io/drayfocus/pen/ZEaqEzP"&gt;https://codepen.io/drayfocus/pen/ZEaqEzP&lt;/a&gt;]&lt;/p&gt;

&lt;h3&gt;
  
  
  Control flow
&lt;/h3&gt;

&lt;p&gt;Control flow are used to control the condition at which a block of code should execute. In Rust, control flow is done using &lt;strong&gt;if and if else statement&lt;/strong&gt; and  &lt;strong&gt;else if statement&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;main&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;if_else_example&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nf"&gt;else_if_example&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;if_else_example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;my_value&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am greater than {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;my_value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"I am less than {}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;my_value&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;else_if_example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;my_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;my_value&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Value is 1"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;my_value&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Value is 2"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;my_value&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Value is 3"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;println!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Value is 4"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In an interactive code editor&lt;/p&gt;

&lt;p&gt;%[&lt;a href="https://codepen.io/drayfocus/pen/yLPRLeZ"&gt;https://codepen.io/drayfocus/pen/yLPRLeZ&lt;/a&gt;]&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;So far, you have setup your environment for Rust programming, installed Rust compiler, and Cargo. You also wrote your first Rust program and got introduced to common programming concepts that Rust has. In the next article, we will explore other programming concept specific to Rust, like variable ownership, Structs, Enums ( and its special types like Options and Result), Traits and so on.&lt;/p&gt;

&lt;p&gt;Let's connect on Twitter &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt;, and Linkedin &lt;a href="https://www.linkedin.com/in/ayomide-akinola-9b940117a"&gt;Akinola Ayomide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>rust</category>
      <category>solana</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Introduction to Solana Blockchain</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 09:06:14 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/introduction-to-solana-blockchain-54fi</link>
      <guid>https://forem.com/doctordrayfocus/introduction-to-solana-blockchain-54fi</guid>
      <description>&lt;p&gt;Solana is an open-source blockchain system that aims to provide a high-performant, decentralized, secure and scalable system. It was release in April 2019. Solana aims to provide a very fast and scalable system with about 50,000 transactions per second and a maximum of 710,000 transactions per second. This impressively fast system allows the transaction fee to be very low with about $0.00025 per transaction. These are really interesting numbers, but it should also be noted that solana is still less mature when compared to other existing blockchains like Ethereum. &lt;/p&gt;

&lt;h2&gt;
  
  
  Why does solana exist?
&lt;/h2&gt;

&lt;p&gt;The early blockchain system like Bitcoin and Ethereum are limited in the amount of workload they can process within a given time. For example, bitcoin can process a maximum of 7 transaction per seconds and 30 transactions per second for ethereum. This limitation is responsible for the high transactions fees in the blockchain network, with the average of $60 per transaction for Bitcoin and $65 for Ethereum.&lt;/p&gt;

&lt;p&gt;Scalabilty is always at the core of every technology that influences our day to day activities. For instance, Visa processes 1,700 transactions per second on average and can have a maximum of about 65,000 transactions per second. With this in mind, blockchain developers are challenged with creating a system that is decentralized, secure and also scalable. This is where solana comes in.&lt;/p&gt;

&lt;h2&gt;
  
  
  Difference - Solana and Ethereum blockchains
&lt;/h2&gt;

&lt;p&gt;Solana and ethereum differs majorly in their underlaying technology and consensus mechanism.&lt;/p&gt;

&lt;h3&gt;
  
  
  Underlaying Technology
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Ethereum&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ethereum uses stateful architechture as a mechanism to acheive decentralization. Every transactions in the ethereum blockchain is being transmitted to every nodes on the blockchain in real-time. For example, if I want to send $3 to a friend, the validity of the transaction must be transmitted and updated in all the mining nodes on the ethereum blockchain before the transaction can be valid. This is the major cause of the slow transaction speed in ethereum.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Solana&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Solana uses a stateless architechture to acheive decentralization. Every transactions is initially sent to the mining nodes, but there is no need for updating the time the transactions was completed. The time tracking is taken care of by the cryptographical calculations which is made possible by its consensus mechanism (Proof of History).&lt;/p&gt;

&lt;h3&gt;
  
  
  Consensus Mechanism
&lt;/h3&gt;

&lt;p&gt;Consensus in a blockchain is an agreement protocol to validate that the data about to be added to the blockchain is valid. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Ethereum&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ethereum 1.0 uses the proof of work consensus mechanism. This mechanism ensures that all mining nodes compete to become the leading node (the one that adds a new block to the blockchain) and spends energy by making some high-computational calculations to prove their validity. This is energy consuming and involves a large waste of useful energy. Ethereum 2.0 aims to switch to a better alternative - Proof of Stake. The Proof of Stake is less energy consuming because the leading node is selected at random and also based on its stake ( its total assets on the blockchain). &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Solana&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Solana uses a combination of Proof of Stake and Proof of History to achieve consensus amongs its validator nodes. The Proof of Stake is similar to that proposed by ethereum 2.0 while the Proof of History helps to support its stateless architechture where the timestamp of each transactions is calculated cryptographically.&lt;/p&gt;

&lt;h2&gt;
  
  
  The way forward
&lt;/h2&gt;

&lt;p&gt;In the web3 ecosystem, Ethereum is still the most used blockchain in terms of the number of Decentralized applications, Decentralized Finance (DeFi) and Non-Fungible Tokens (NFT) currently hosted on it. That said, solana is one of the fastest growing blockchain for building DeFi , Dapps, and NFTs majorly because of its scalability, fast transaction speed, and low transactions fee.&lt;/p&gt;

&lt;p&gt;In the upcoming articles of this series, I will discuss how you can build Web3 apps (NFTs, DeFi and so on) using solana program. Solana program is similar to Ethereum's smart contract but it uses Rust programming language. So, I will also touch on Rust and explain some of the basics concept of Rust you will need to know to build a solana program.&lt;/p&gt;

&lt;p&gt;Let's get in touch on Twitter &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt; and Linkedin &lt;a href="https://www.linkedin.com/in/ayomide-akinola-9b940117a"&gt;Akinola Ayomide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>solana</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Cryptography and its uses</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 09:02:15 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/cryptography-and-its-uses-5ca7</link>
      <guid>https://forem.com/doctordrayfocus/cryptography-and-its-uses-5ca7</guid>
      <description>&lt;p&gt;In 50BC, the roman emperor Julius Ceaser wanted to send secret messages to his generals during the Gallic war. To do that, he converted the plaintext messages to unreadable texts using a process known as cryptography.&lt;/p&gt;

&lt;p&gt;Cryptography is coined from the greek word "Krypto" meaning hidden, and "-graphy" meaning writing. It is the study of secret communication using a series of encryption and decryption processes. Encryption is the convertion of human readable data to unreadable data (Ciphertext), while decryption is the conversion of these encrypted data(Ciphertext) to readable data (plaintext).&lt;/p&gt;

&lt;p&gt;In this article, we will explore,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How cryptography works&lt;/li&gt;
&lt;li&gt;Role of cryptography in Blockchain, and&lt;/li&gt;
&lt;li&gt;Other uses of cryptography&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How cryptography works
&lt;/h2&gt;

&lt;p&gt;Cryptography makes use of mathematical techniques for secret transmission of private messages usually through an insecure medium. These techniques aim to provide confidentiality, authenticity, and integrity to the message being transmitted. &lt;/p&gt;

&lt;p&gt;It achieve confidentiality by converting the plaintext to unreadable text (ciphertext) using encryption algorithms, conserve integrity by using hashing techniques, and authentication using secret keys only known to the communicating parties. These encryption algorithms are of two types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Symmetric encryption&lt;/li&gt;
&lt;li&gt;Asymmetric encryption&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Symmetric encryption
&lt;/h3&gt;

&lt;p&gt;Symmetric encryption involves the use of a &lt;strong&gt;single secret key&lt;/strong&gt; to encrypt and decrypt data. For this to work, both the sender and reciever must share the same key. An example of symmetric encryption is the Ceaser Cipher. In Ceaser Cipher, the letters D to Z are encrypted by letters that comes three times latter that them&lt;br&gt;
 in the alphabet. While the remaining letters A, B, and C are represented by X, Y, and Z respectively. Here, the secret key is the shift key - "3".  For example&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Plaintext&lt;/strong&gt; - "You can now attack"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ciphertext&lt;/strong&gt; - "Vlr zxk klt xqqxzh"&lt;/p&gt;

&lt;p&gt;This encryption can be cracked because the shift key can easily be determined. Overtime, more secure encryption was developed using advanced mathematic calculations such as permutation, transposition and so on. Other examples of symmetric encryptions are Block Cipher, Steam cipher, and one-time pad cipher. In symmetric encryption, the secret key for encrypting and decrypting data needs to be distributed between the communicating parties. Distributing this secret key securely can be difficult and sometimes involves the establishment of a third party key distribution center.&lt;/p&gt;

&lt;h3&gt;
  
  
  Asymmetric encryption
&lt;/h3&gt;

&lt;p&gt;This encryption method evolved to solve the key distribution problem in symmetric encryption. Asymmetric encryption make use of two keys, a &lt;strong&gt;public key&lt;/strong&gt; and a &lt;strong&gt;private key&lt;/strong&gt; in the encryption and decryption processes. The public key is freely distributed and it is mathematically derived from the private key. The public key is derived in such a way that it is impossible to reverse engineer it to get the private key.&lt;/p&gt;

&lt;p&gt;The private key is used to encrypt the data, which can only be decrypted using the public key. This can also happen interchangably, where the public key is used for encryption and the private key is used for decryption. An example of asymmetric encryption is the Rivest-Shamir-Adleman (RSA) scheme which uses computational factorization together with the public and private key concept to encrypt and decrypt data. Another example is Elliptic Curve Cryptography (ECC) which uses algebric structure of elliptic curves over finite fields, as its computational approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Role of cryptography in Blockchain
&lt;/h2&gt;

&lt;p&gt;In blockchain, data are encrypted and grouped into blocks. Blocks are linked through cryptographic hash, hence producing a chain of blocks. Except the first (genesis) block, the linkage of every sucessive block helps to strenghten the authenticity of the preceeding blocks.&lt;/p&gt;

&lt;p&gt;Asymmetric encryption is used to generate public and private keys for accounts on blockchain. Bitcoin and Ethereum use the Elliptic Curve Cryptography (ECC). First, a random 256 bit ramdom number is generated. This random number becomes the private key. Then, the encryption algorithm is applied to the private key to generate the public key. This algorithm uses prime number factorization principle which state that, no matter how large a number is, it can be produced by multiplying prime numbers. It is easy to produce a number by multiplying prime numbers but it is very hard to reverse the process. Blockchain relies on this concept to ensure that a public key cannot be reverse engineered to give the private key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other uses of cryptography
&lt;/h2&gt;

&lt;p&gt;Cryptography is used in secured wireless communication systems such as Bluetooth and WiFi. Bluetooth uses a symmetric encryption - steam ciphers E0 to encrypt its payload. &lt;/p&gt;

&lt;p&gt;Hypertext Transfer Protocol Secure (HTTPS) uses both symmetric and asymmetric encryption to securely transmited data between a web browser and a web server. Let's assume the web browser is the &lt;strong&gt;King of France&lt;/strong&gt; and the web server is the &lt;strong&gt;King of Spain&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;The king of Spain wants to securely send a &lt;strong&gt;large box&lt;/strong&gt; containing &lt;strong&gt;Gold&lt;/strong&gt; to the king of France. So, the king locked the &lt;strong&gt;large box&lt;/strong&gt; with a &lt;strong&gt;special key&lt;/strong&gt;. He then placed this &lt;strong&gt;special key&lt;/strong&gt; into a &lt;strong&gt;small box&lt;/strong&gt;, which he also locked using a &lt;strong&gt;smartlock&lt;/strong&gt; whose &lt;strong&gt;passcode&lt;/strong&gt; is only known to the king of France. He then sent both &lt;strong&gt;large&lt;/strong&gt; and &lt;strong&gt;small&lt;/strong&gt; boxes to France. For the king of France to access the &lt;strong&gt;Gold&lt;/strong&gt;, he first opened the &lt;strong&gt;small box&lt;/strong&gt; using his &lt;strong&gt;secret passcode&lt;/strong&gt;, then got the &lt;strong&gt;special key&lt;/strong&gt; out of the &lt;strong&gt;smaller box&lt;/strong&gt;, and used it to open up the large box containing the &lt;strong&gt;Gold&lt;/strong&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The &lt;strong&gt;Gold&lt;/strong&gt; is the &lt;strong&gt;data&lt;/strong&gt; being sent from the web server to the web browser.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;special key&lt;/strong&gt; is a &lt;strong&gt;random symmetric private key&lt;/strong&gt; generated by the web server.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;locked large box&lt;/strong&gt;, is the &lt;strong&gt;encrypted data&lt;/strong&gt; using the &lt;strong&gt;private key&lt;/strong&gt; on the web server.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;smartlock&lt;/strong&gt; used to lock the &lt;strong&gt;small box&lt;/strong&gt; is the &lt;strong&gt;public key&lt;/strong&gt; of the web browser.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;locked small box&lt;/strong&gt; is the &lt;strong&gt;encrypted random private key&lt;/strong&gt; of the web server using the &lt;strong&gt;public key&lt;/strong&gt; of the web browser.&lt;/li&gt;
&lt;li&gt;The &lt;strong&gt;secret passcode&lt;/strong&gt; is the &lt;strong&gt;private key&lt;/strong&gt; of the web browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary a &lt;strong&gt;random private key&lt;/strong&gt; on the web server is used to encrypt the data, then the &lt;strong&gt;random private key&lt;/strong&gt; is encrypted using the &lt;strong&gt;public key&lt;/strong&gt; of the web browser. The two encrypted data is then sent through the network protocol to the web browser. The web browser uses it's &lt;strong&gt;private key&lt;/strong&gt; to decrypt and extract the &lt;strong&gt;random private key&lt;/strong&gt; of the web server then used the private key to decrypt the encrypted data.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Cryptography plays an important role in many electronic and communication system. It is also the backbone of blockchain technology. Knowing about cryptography will be helpful in building safe and secure applications. &lt;/p&gt;

&lt;p&gt;Let's connect on Twitter &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt;, and Linkedin &lt;a href="https://www.linkedin.com/in/ayomide-akinola-9b940117a"&gt;Akinola Ayomide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Book Review: Blockchain in Action</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 08:58:59 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/book-review-blockchain-in-action-3680</link>
      <guid>https://forem.com/doctordrayfocus/book-review-blockchain-in-action-3680</guid>
      <description>&lt;p&gt;"Oh my gosh! I am going to become a blockchain expert". That was me after reading the first two chapters of Blockchain in Action. Well, after finishing the book, I haven't become an expert just yet, but I was grounded with the knowlegde and inspiration to become one.&lt;/p&gt;

&lt;p&gt;Bina Ramamurthy, the author of Blockchain in action started with explaining the concept of blockchain in simple terms and with relatable examples. Then she took me on a step by step journey of building smart contracts and Decentralized Applications (DApps) using standard engineering design principles.&lt;/p&gt;

&lt;p&gt;Blockchain seats on over four decades of research in mathematics, and majorly cryptography. She explained the concept of cryptography and how they are used to enforce security and privacy in blockchain. She explain symmetric and asymmetric encryption keys and how asymmetric encryption is used to generate the public-private key pair used in blockchain to create accounts and signing transactions.&lt;/p&gt;

&lt;p&gt;With the help of the book, I built smart contracts addressing real world scenarios such as electronic voting, micropayment channels and electronic educational certification. Each of these examples  were progressively converted to a full Decentralized Application. During building, the book introduced me to tools such as Truffle for compliling and testing smart contracts and MetaMask for crypto account management. These smart contracts were deployed on Ganache, a local blockchain network, and a public blockchain networks like the ropsten ethereum network.&lt;/p&gt;

&lt;p&gt;The book also explored Fungible and Non-Fungible Tokens (NFTs). Fungible tokens are tokens that are not individually unique and are exchangeable with units of the same kind. Examples are cryptocurrency tokens(Bitcoin, Ethereum). While Non-Fungible tokens are tokens that represent assests that can appreciate or depreciate in value such as lands, art pieces etc. She went further to explaining how to create a fugible tokens and Non-fugible tokens using ethereum standards (ERC20 and ERC721 respectively).&lt;/p&gt;

&lt;p&gt;Bina explored the concept of on-chain and off-chain data, explaining that on-chain data are data stored on the blockchain while off-chain data are data in a decentralized application that are stored outside the blockchain. She emphazied the importance of designing a decentralized application with minimal on-chain data so as not to overload the blockchain.&lt;/p&gt;

&lt;p&gt;The book explored the decentralized identity of blockchain and the different types of concensus e.g proof of work, proof of authority, and proof of stake. It explained how the concensus used in bitcoin and ethereum are affecting their efficiency and what steps have been taken to solve these problems. She ended with analysing the future of blockchain technology and the different aspects of blockchain that needs innovations from people like you and me.&lt;/p&gt;

&lt;p&gt;Bina Ramamurthy is a professor in the university of Buffalo, and she has successfully converted me into the blockchain ecosystem with her work. Like a great teacher,  she brought her experience in building distributed systems and demonstrated how to build a scalable blockchain application using design principles.&lt;/p&gt;

&lt;p&gt;I will read this book as many times as possible and use it as a reference throughout my career in blockchain. It is a book that demystifies the most advance concepts in blockchain and gives a template of how to build any decentralized application. If you are a developer looking to learn about blockchain technology and also develop smart contracts, this book is for you.&lt;/p&gt;

&lt;p&gt;You can get your own copy of  &lt;a href="https://www.manning.com/books/blockchain-in-action"&gt;Blockchain in Action&lt;/a&gt;  with 35% discount. Use the discount code: &lt;strong&gt;bldrayfocus&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Let's connect on Twitter  &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt;  and Linkedin  &lt;a href="https://www.linkedin.com/in/ayomide-akinola-9b940117a"&gt;Akinola Ayomide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>web3</category>
      <category>blockchain</category>
      <category>bookreview</category>
    </item>
    <item>
      <title>What is a decentralized application (DApp)?</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 08:58:02 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/what-is-a-decentralized-application-dapp-1n2m</link>
      <guid>https://forem.com/doctordrayfocus/what-is-a-decentralized-application-dapp-1n2m</guid>
      <description>&lt;p&gt;Developers build decentralized apps (DApps) to make smart contract functionalities available to the end users. In this article, we will discuss:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What are Decentralized Applications (DApps)&lt;/li&gt;
&lt;li&gt;Components of a DApp&lt;/li&gt;
&lt;li&gt;How these components work together&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What are Decentralized Applications
&lt;/h2&gt;

&lt;p&gt;Decentralized applications are softwares that exist and run on a decentralized blockchain system. Simple right? Yes, it is that simple. &lt;/p&gt;

&lt;p&gt;They make use of smart contracts to execute actions and commands on a blockchain system. You can learn more about smart contracts in my  &lt;a href="https://drayfocus.hashnode.dev/building-a-smart-contract"&gt;previous article&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Components of a Decentralized Application
&lt;/h2&gt;

&lt;p&gt;Let's relate a DApp to a small village with a &lt;strong&gt;King&lt;/strong&gt;.  &lt;/p&gt;

&lt;p&gt;This &lt;strong&gt;King&lt;/strong&gt; stays in a &lt;strong&gt;Palace&lt;/strong&gt;, where he rules and controls the affairs of the village. He is responsible for communicating with his people and also taking care of their needs. His &lt;strong&gt;Palace&lt;/strong&gt; has a highly guarded  *&lt;em&gt;Gate *&lt;/em&gt; that gives him the needed security and environment to perform all his tasks. &lt;/p&gt;

&lt;p&gt;To pass information to his people, the king sends a group of  &lt;strong&gt;Town Criers&lt;/strong&gt; . The &lt;strong&gt;Town Criers&lt;/strong&gt; carry information round the village and also takes the request of the people back to the &lt;strong&gt;King&lt;/strong&gt;. Take note, only known and trusted &lt;strong&gt;Town Criers&lt;/strong&gt; are allowed to pass through the Palace's &lt;strong&gt;Gate&lt;/strong&gt; and access the &lt;strong&gt;King&lt;/strong&gt; for security reasons.&lt;/p&gt;

&lt;p&gt;In a DApp,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;Palace&lt;/strong&gt; is the remote CPU which has a blockchain enviroment installed (e.g Ethereum Virtual Machine - EVM). It acts as a &lt;strong&gt;blockchain node&lt;/strong&gt;, which is part of a large decentralized blockchain network like Ethereum.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;King&lt;/strong&gt; is the &lt;strong&gt;Web3 Provider&lt;/strong&gt;, which resides in the &lt;strong&gt;blockchain node&lt;/strong&gt;. It is responsible for executing commands on the blockchain node. It has direct access and can communicate back and forth with the node.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The palace's &lt;strong&gt;Gate&lt;/strong&gt; is the &lt;strong&gt;RPC (Remote Protocol Call) port&lt;/strong&gt; through which requests to and response from the &lt;strong&gt;Web3 Provider&lt;/strong&gt; passes. This port is usually well secured to protect the &lt;strong&gt;blockchain node&lt;/strong&gt; from cyber attack.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;Town Criers&lt;/strong&gt; are the &lt;strong&gt;Web3 Connectors&lt;/strong&gt;. They connect to the &lt;strong&gt;Web3 Provider&lt;/strong&gt; through the &lt;strong&gt;RPC port&lt;/strong&gt;. It works like a simple API system that sends request (In JSON) to the &lt;strong&gt;Web3 Provider&lt;/strong&gt; to execute and also recieve the response from the &lt;strong&gt;Web3 Provider&lt;/strong&gt;. A popular example of &lt;strong&gt;Web3 Connector&lt;/strong&gt; is Ethereum's  &lt;a href="https://web3js.readthedocs.io/en/v1.5.2/"&gt;Web3.js package&lt;/a&gt; .&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Bringing everything together
&lt;/h2&gt;

&lt;p&gt;Now that you know the components of a DApp, let's see how they work together.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;blockchain node&lt;/strong&gt; is connected to a blockchain system (e.g Ethereum), thus having access to the transactions and blocks of the blockchain. We also deploy our smart contracts to the blockchain system using the &lt;strong&gt;blockchain node&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User accounts and wallets are created on this &lt;strong&gt;blockchain node&lt;/strong&gt; and these accounts are responsible for sending and receiving transactions. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Actions and commands won't be auto executed on the &lt;strong&gt;blockchain node&lt;/strong&gt;, so we need an executor. The executor is the &lt;strong&gt;Web3 Provider&lt;/strong&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Web3 Connector&lt;/strong&gt; acts as an initiator of an execution. The   &lt;strong&gt;Web3 Connector&lt;/strong&gt;  can be an API or a User Interface like in MetaMask, Binance, e.t.c.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Every Decentralize Application (DApp) is made up a blockchain node that host accounts, help to deploy the smart contracts on a public or private blockchain system, and has a Web3 Provider that executes commands intiated by a Web3 Connector. I hope you now understand what a DApp is and how it works. &lt;/p&gt;

&lt;h2&gt;
  
  
  Bonus
&lt;/h2&gt;

&lt;p&gt;There many questions I haven't answered yet. For example, how did I get to understand DApps?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Blockchain in Action by Bina Ramamurthy&lt;/strong&gt; helped me in preparing this article and &lt;br&gt;
you can get your own copy of  &lt;a href="https://www.manning.com/books/blockchain-in-action"&gt;Blockchain in Action&lt;/a&gt; with 35% discount.&lt;/p&gt;

&lt;p&gt;Discount code: &lt;strong&gt;bldrayfocus&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;Let's connect on Twitter  &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt; and Linkedin  &lt;a href="https://www.linkedin.com/in/ayomide-akinola-9b940117a"&gt;Akinola Ayomide&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>dapp</category>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Deploying and Testing a Smart Contract</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 08:52:05 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/deploying-and-testing-a-smart-contract-13ap</link>
      <guid>https://forem.com/doctordrayfocus/deploying-and-testing-a-smart-contract-13ap</guid>
      <description>&lt;p&gt;Testing a smart contract before deployment is important because smart contracts are immutable after deployment. Fortunately,  Remix IDE from &lt;a href="https://remix.ethereum.org"&gt;https://remix.ethereum.org&lt;/a&gt;  has made this easy by providing us with an environment to test our smart contract without any extra setup. It provides us with test accounts and ethers that we can use to perform transactions on an ethereum test network.&lt;/p&gt;

&lt;p&gt;In this article, we would be deploying and testing a logistics smart contract. To understand the concept of the smart contract and how it was built, you can check my previous article &lt;a href="https://dev.to/doctordrayfocus/building-a-smart-contract-for-logistics-companies-3boi"&gt;here&lt;/a&gt;. &lt;/p&gt;

&lt;h2&gt;
  
  
  Deploying our smart contract
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Open &lt;a href="https://remix.ethereum.org/"&gt;Remix&lt;/a&gt; on your browser, and create a new file "Logistics.sol", if you haven't done that before.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Here is the full source code for our logisitics smart contract,&lt;br&gt;&lt;br&gt;
&lt;a href="https://gist.github.com/Doctordrayfocus/8177bd086097ace3c5c6429bba0182d5"&gt; https://gist.github.com/Doctordrayfocus/8177bd086097ace3c5c6429bba0182d5&lt;/a&gt; &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;We need to compile our code so that we can deploy it on the ethereum network. To do  that, go to Remix and switch to the solidity compiler tab on the left. You don't need to make any extra setup, the default language should be "Solidity".  Now, click on the "Compile logistics.sol" button to compile the code. You should see something similar to the image below.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hMd90GAd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883467535/N2vAluvxn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hMd90GAd--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883467535/N2vAluvxn.png" alt="compiler.png" width="720" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Lets proceed to deploy our compiled script. Switch to the deploy tab on Remix. Here, you can select the test environment but can also leave it at the default - "JavaScript VM (London)".
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ZEVyAuTt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883522651/tGR_0ouDs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ZEVyAuTt--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883522651/tGR_0ouDs.png" alt="deploy_and_run.png" width="714" height="398"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next is the account drop down. Here, Remix has provided you with 15 test accounts. Select the first account. This account will serve as the Initiator and will be used to deploy the smart contract.&lt;/p&gt;

&lt;p&gt;After the account field, the gas limit allows us limit the amount of gas that can be spent during the transaction. You can leave it at its default. Below the gas limit is a field allowing you set the cryptocurrency value to be sent along with a transaction. You can set the value to "30 ether".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KyV9S-y_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883543260/MVk5JBanq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KyV9S-y_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883543260/MVk5JBanq.png" alt="account.png" width="714" height="390"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Next, click on the "deploy" button to deploy the smart contract. On the console, at the bottom rigth corner of your IDE, Just below the code area, you will see the transaction progress and success logs similar to the image below.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--1T1Fu7RI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883563168/byE-MlbRr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--1T1Fu7RI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883563168/byE-MlbRr.png" alt="constructor.png" width="716" height="260"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Also, your smart contract will be added to the list of deployed contracts as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3UAfCvvH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883583913/1DLDW6qz0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3UAfCvvH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883583913/1DLDW6qz0.png" alt="deployed_contract.png" width="708" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Expand logistics contract and you will see buttons and text fields with names similar to the public state data and functions defined in the smart contract. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ValmoDIw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883626503/AAQeXGC6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ValmoDIw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883626503/AAQeXGC6b.png" alt="deployed_contract_buttons.png" width="712" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These buttons and text fields enable you to easily pass in data and call the smart contract functions directly from Remix.&lt;/p&gt;

&lt;p&gt;Now, let's start testing by registering members to the smart contract using the test account Remix provided.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testing our smart contract
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Register a new member
&lt;/h3&gt;

&lt;p&gt;We can achieve this by calling the &lt;strong&gt;register&lt;/strong&gt; function in the smart contract. To register the first member, select a new account from the list of test account. Set the cryptocurrency value to 10 or above (This is a requirement that needs to be met to register a new member based on the smart contract code). &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2jAvglfK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883492372/5QNrcsXK2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2jAvglfK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883492372/5QNrcsXK2.png" alt="accounts.png" width="706" height="396"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Move to the deployed logistics smart contract session and click on the &lt;strong&gt;Register&lt;/strong&gt; button to invoke the register function of the smart contract which will register the account as a new member. The transaction will be logged in the console as shown below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A-IpD0Qh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883948693/apnw__KtT.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A-IpD0Qh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883948693/apnw__KtT.png" alt="register.png" width="710" height="210"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the account address of the new member and paste it into a note and label it &lt;strong&gt;logistics1&lt;/strong&gt;. Select a new account and repeat the same step to register the second member on the smart contract. Also, copy the account address and label it &lt;strong&gt;logistics2&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PpLjS-ap--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883984470/R1o6_nt6A.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PpLjS-ap--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639883984470/R1o6_nt6A.png" alt="account_address_main.png" width="712" height="226"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can inspect the data of each member created by passing their account address and calling the &lt;strong&gt;membersData&lt;/strong&gt;,&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5tf2QtrS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884014929/pPBA4hsNv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5tf2QtrS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884014929/pPBA4hsNv.png" alt="members_data.png" width="707" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Request for delivery assistance
&lt;/h3&gt;

&lt;p&gt;Let's make &lt;strong&gt;logistics1&lt;/strong&gt; request for a delivery assistance. To acheive that, switch back the selected account to that of &lt;strong&gt;logistics1&lt;/strong&gt;. Call the &lt;strong&gt;requestForDelivery&lt;/strong&gt; function of the smart contract by passing in the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt; as a random digit e.g (6905597967) and an ether value e.g (20 ether). Click on the **requestForDelivery **in the deployed smart contract. You can inspect the transaction in the console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ewN4sd15--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884035796/XCxwyngnl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ewN4sd15--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884035796/XCxwyngnl.png" alt="request_for_delivery.png" width="715" height="240"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For futher testing, you can get the details of the delivery by passing in the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt; e.g (6905597967) and clicking the &lt;strong&gt;deliveryData&lt;/strong&gt; button as shown below. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dVgiMHlH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884053608/gVUaGN8l-.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dVgiMHlH--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884053608/gVUaGN8l-.png" alt="request_for_delivery_btn.png" width="706" height="276"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Respond to delivery request
&lt;/h3&gt;

&lt;p&gt;Let's make &lt;strong&gt;logistics2&lt;/strong&gt; respond to the delivery request. We would need to call the &lt;strong&gt;respondToDeliveryRequest&lt;/strong&gt; function of our smart contract. To do that, we need to provide the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt;.  We can easily retrieve all available deliveries by calling the &lt;strong&gt;getAvailableDeliveries&lt;/strong&gt; function. This will return an array of the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt; of deliveries that are pending.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eiA4EU6K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884088495/hffr0bLjS.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eiA4EU6K--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884088495/hffr0bLjS.png" alt="get_delivery_deetails.png" width="707" height="184"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change the selected account to that of &lt;strong&gt;logistics2&lt;/strong&gt;, pass in the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt; and click on &lt;strong&gt;respondToDeliveryRequest&lt;/strong&gt; button to call the equivalent function. You can inspect the transaction in your console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--IAQb_MxE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884121583/4r_sbSkoh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--IAQb_MxE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884121583/4r_sbSkoh.png" alt="respondToDelivery.png" width="715" height="222"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the response has been sent, the delivery will be removed from the available delivery. You can confirm by calling the &lt;strong&gt;getAvailableDeliveries&lt;/strong&gt; again. It will not contain the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt; again.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cRpQrUb6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884184531/_waa7XfMz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cRpQrUb6--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884184531/_waa7XfMz.png" alt="get_delivery_details_empty.png" width="706" height="180"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Mark delivery as completed
&lt;/h3&gt;

&lt;p&gt;Here, &lt;strong&gt;logistics2&lt;/strong&gt; will mark the selected delivery as completed by passing the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt; and calling the &lt;strong&gt;markDeliveryAsCompleted&lt;/strong&gt; function. This can only be done by &lt;strong&gt;logistics2&lt;/strong&gt; and the &lt;strong&gt;initiator&lt;/strong&gt;. You can inspect the transaction in your console.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A9uIIGG0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884218566/RnxYJHPEo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A9uIIGG0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884218566/RnxYJHPEo.png" alt="mark_as_confirm_btn.png" width="654" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--EGwDM582--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884227959/UKwwcW4Gx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--EGwDM582--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884227959/UKwwcW4Gx.png" alt="mark_delivery-as-complete_console.png" width="708" height="224"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Mark delivery as confirmed
&lt;/h3&gt;

&lt;p&gt;Switch back the selected account to that of &lt;strong&gt;logistics1&lt;/strong&gt;. Then call the &lt;strong&gt;markDeliveryAsConfirmed&lt;/strong&gt; function by passing the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt;. This can also be called by the &lt;strong&gt;initiator&lt;/strong&gt; on behalf of &lt;strong&gt;logistics1&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FyWq7Ita--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884260007/iBX_TPk9T.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FyWq7Ita--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884260007/iBX_TPk9T.png" alt="mark_as_confirm_btn.png" width="654" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DvCqujfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884296006/-lNTKeW08.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DvCqujfT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884296006/-lNTKeW08.png" alt="mark_as_delivery_main.png" width="708" height="190"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the delivery has been confirmed, the reputation of &lt;strong&gt;logistics2&lt;/strong&gt; would increase and the delivery fee would be added to &lt;strong&gt;logistics2&lt;/strong&gt; balance.  You can verify that by passing the account address and calling the &lt;strong&gt;membersData&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--K4JpnPz2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884309997/seNgvK2EL.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--K4JpnPz2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1639884309997/seNgvK2EL.png" alt="members_with_details.png" width="712" height="196"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Unfortunately, I can't write  tests for every possible scenario in this article. The tests above are positive tests i.e test made by passing in the correct data. You can perform the negative test by passing in the wrong data or using the wrong account to call a function, then inspect the response.  &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The goal of this article was to make you familiar with deploying and testing a smart contract using Remix IDE. I hope it was achieved.&lt;/p&gt;

&lt;p&gt;You can connect to me on Twitter  &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt;  , and Linkedin  &lt;a href="https://www.linkedin.com/in/ayomide-akinola-9b940117a"&gt;Akinola Ayomide&lt;/a&gt; .&lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
    </item>
    <item>
      <title>Building a Smart Contract for Logistics Companies</title>
      <dc:creator>Drayfocus</dc:creator>
      <pubDate>Sun, 10 Jul 2022 08:46:25 +0000</pubDate>
      <link>https://forem.com/doctordrayfocus/building-a-smart-contract-for-logistics-companies-3boi</link>
      <guid>https://forem.com/doctordrayfocus/building-a-smart-contract-for-logistics-companies-3boi</guid>
      <description>&lt;p&gt;Blockchain technology is a revolutionary tool that can be applied to many industries. You have already seen how blockchain can be used as a secure ledger for digital currency, but it also has many other applications. One such application is in the logistics industry.&lt;/p&gt;

&lt;p&gt;The logistics industry has been around for decades and the current system works well for most companies. However, there are still some issues within the industry that need to be addressed. For example, there are times when customer orders outweigh the capacity of the logistic company. They usually resolve this by delaying the time of deliveries which doesn't always turn out to give a good customer experience.&lt;/p&gt;

&lt;p&gt;Smart contracts are one way to address these issues. In this article, you will look at how smart contracts can be used in the logistics industry and how they can help improve efficiency and help such a logistic company shed some weight by allowing other logistics companies to plug into their system to deliver the order. You will learn how to build a smart contract by building a system that enables a group of logistics companies within a city to work together as a single unit. Each logistic company would be able to offer delivery assistance to other logistics companies that can't process a delivery quickly. Here, the smart contract acts as the trusted enabler, making the companies exchange delivery data and fees without worry.&lt;/p&gt;

&lt;p&gt;In this article, you would do the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Get familiar with Remix IDE&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Define how the smart contract would work&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Build our Smart Contract &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Remix IDE
&lt;/h2&gt;

&lt;p&gt;In this article, you will use the Remix IDE. The remix is the official Integrated Development Environment for writing Solidity. The remix is similar to most common IDEs like Vscode, Sublime text, and so on. It allows you to quickly build smart contracts, deploy, and test on Ethereum networks without going through extra setups. You can use it directly on your browser at remix.ethereum.org.&lt;/p&gt;

&lt;h3&gt;
  
  
  Overview
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BYp_mVgu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638707717829/d_8KAmaBJ.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BYp_mVgu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638707717829/d_8KAmaBJ.jpeg" alt="overview.jpg" width="880" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The picture above is what you see the first time you visit Remix. Similar to Vscode, the file explorer is on the left side of your screen, the code area on the right, then the terminal/log below the code area.&lt;/p&gt;

&lt;h3&gt;
  
  
  File Explorer
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gybj9buY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638707733602/u2W9mcPXm.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gybj9buY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638707733602/u2W9mcPXm.jpeg" alt="File Explorer.jpg" width="880" height="498"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This is where you create and manage your files, mostly solidity files (.sol)&lt;/p&gt;

&lt;h3&gt;
  
  
  Solidity Compiler
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--exYqkfqC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638707950829/I-plrBVh7.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--exYqkfqC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638707950829/I-plrBVh7.jpeg" alt="Compiler.jpg" width="869" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you are done writing your smart contract, you will need to compile it. With Remix, you can easily configure your compiler and compile your solidity script, so it can run on the Ethereum Virtual Machine.&lt;/p&gt;

&lt;h3&gt;
  
  
  Deploy and Run Transactions
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TXVbEkgO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638708159009/TzdM0DKgt.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TXVbEkgO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638708159009/TzdM0DKgt.jpeg" alt="deploy and run.jpg" width="878" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After successfully compiling your smart contract, you can deploy it on a test Ethereum network and run it directly on Remix IDE.&lt;/p&gt;

&lt;h2&gt;
  
  
  How will this smart contract work?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;The smart contract would be launched by an account into an &lt;strong&gt;Ethereum network&lt;/strong&gt; through a &lt;strong&gt;transaction&lt;/strong&gt;. This account is the contract &lt;strong&gt;initiator&lt;/strong&gt;. The transaction would include some &lt;strong&gt;ether&lt;/strong&gt; (Ethereum cryptocurrency) which the initiator will use to register itself as a member of the smart contract.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Each of the logistic companies would create an account on the Ethereum network. These accounts would be used to &lt;strong&gt;register as a member&lt;/strong&gt; on the smart contract. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;During registration, a minimum amount of ether (e.g 10) is set as the &lt;strong&gt;registration fee&lt;/strong&gt;. This fee serves as a requirement for becoming a member of the Logistics smart contract (PS - requirements can vary in real-life applications).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After registration into the smart contract, members are given a &lt;strong&gt;reputation&lt;/strong&gt; number (e.g 10). A member can request &lt;strong&gt;delivery assistance&lt;/strong&gt; from the smart contract. This member is the &lt;strong&gt;delivery owner&lt;/strong&gt;. During this request, an ether amount, equivalent to the &lt;strong&gt;delivery fee&lt;/strong&gt; is sent alongside a &lt;strong&gt;hashed&lt;/strong&gt; (encrypted) data of the delivery.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Any member of the smart contract who is &lt;strong&gt;interested in assisting&lt;/strong&gt; in the delivery would respond to the &lt;strong&gt;delivery request&lt;/strong&gt;, &lt;strong&gt;decrypt&lt;/strong&gt; the delivery details, then use the details to complete the delivery process. This member is referred to as the &lt;strong&gt;assisting member&lt;/strong&gt; of the delivery.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the delivery is completed, the &lt;strong&gt;assisting member&lt;/strong&gt; marks the delivery as &lt;strong&gt;completed&lt;/strong&gt; on the smart contract. The &lt;strong&gt;delivery owner&lt;/strong&gt; will &lt;strong&gt;confirm the completeness&lt;/strong&gt; of the delivery (&lt;em&gt;This can happen after the customer has indicated that the delivery has been completed&lt;/em&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;After the delivery has been confirmed, the &lt;strong&gt;delivery fee&lt;/strong&gt; is sent from the &lt;strong&gt;delivery owner's ** balance to the **assisting member&lt;/strong&gt; balance on the smart contract. The &lt;strong&gt;reputation&lt;/strong&gt; of the &lt;strong&gt;assisting member&lt;/strong&gt; would be &lt;strong&gt;increased&lt;/strong&gt; by some values (e.g 3).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the delivery &lt;strong&gt;failed&lt;/strong&gt; or was &lt;strong&gt;canceled&lt;/strong&gt; by the &lt;strong&gt;assisting member&lt;/strong&gt;, its &lt;strong&gt;reputation&lt;/strong&gt; would be &lt;strong&gt;reduced&lt;/strong&gt; by some value (e.g 5).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The &lt;strong&gt;reputation&lt;/strong&gt; of every member on the smart contract is important as it serves as a factor to &lt;strong&gt;validate the authenticity&lt;/strong&gt; of each member ( a logistics company). &lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Build your Smart Contract
&lt;/h2&gt;

&lt;p&gt;A smart contract is made up of &lt;strong&gt;data (states)&lt;/strong&gt;, &lt;strong&gt;functions&lt;/strong&gt; to access or change the data, and &lt;strong&gt;rules (modifiers)&lt;/strong&gt; that act as gatekeepers for the data and the functions. &lt;/p&gt;

&lt;p&gt;It is a best practice to analyze a smart contract before writing any line of code. Analyzing a smart contract gives clarity on what we want to build. &lt;/p&gt;

&lt;p&gt;The diagram below shows an overview of our smart contract.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9JXRd7Sp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638709893724/-CX0lATGg.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9JXRd7Sp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://cdn.hashnode.com/res/hashnode/image/upload/v1638709893724/-CX0lATGg.jpeg" alt="smart contract.jpg" width="877" height="486"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Your smart contract would be made up of four important components. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Name&lt;/li&gt;
&lt;li&gt;State data&lt;/li&gt;
&lt;li&gt;Rules or modifiers&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Name
&lt;/h3&gt;

&lt;p&gt;This is simply the name of your contract. It is the first step you need to take in building your smart contract.  Go ahead to your Remix IDE, and create a new file named &lt;strong&gt;Logistics.sol&lt;/strong&gt;, then define your smart contract as shown below&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Logistics&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
&lt;span class="c1"&gt;// our smart contract code goes here
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first line &lt;strong&gt;pragma solidity &amp;gt;=0.4.16 &amp;lt;0.9.0&lt;/strong&gt; indicates that the solidity version you are using is between 0.4.16 to 0.8.0. This version specification is needed to correctly compile our solidity code. The &lt;strong&gt;"contract Logistics"&lt;/strong&gt; on line 2 defines our smart contract.&lt;/p&gt;

&lt;h3&gt;
  
  
  States data
&lt;/h3&gt;

&lt;p&gt;States data are variables (data storage containers) whose values are permanently stored in contract storage. It is always present throughout the existence of the contract. Solidity is a typed language and it has different data types similar to  C++. In this smart contract, you would only use four data types.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;*&lt;em&gt;address *&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is used for storing addresses of contracts or accounts. it is a 160-bit value that does not allow any arithmetic operations.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;struct&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The struct type is used for storing related data as one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;uint&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;uint means unsigned integer. it is used for storing integer values&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;mapping&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;mapping is quite similar to a javascript array. It is used to store value in a key=&amp;gt;value pair format.&lt;/p&gt;

&lt;p&gt;You can check out other data types on &lt;a href="https://docs.soliditylang.org/en/v0.8.10/types.html"&gt;Solidity Documentation&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;When declaring state data in solidity, the data type is written before the state name. For example,&lt;br&gt;
&lt;strong&gt;address payinguser&lt;/strong&gt;:  &lt;strong&gt;address&lt;/strong&gt; is the data type, while &lt;strong&gt;payinguser&lt;/strong&gt; is the name of the state.&lt;/p&gt;

&lt;p&gt;Let's define the state data for our smart contract.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;initiator -&amp;gt; The address of the account that will launch the logistics smart contract
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;    &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;memberState -&amp;gt; Holds data for each member registered on the contract. It contains the logistics company's &lt;strong&gt;balance&lt;/strong&gt; and &lt;strong&gt;reputation&lt;/strong&gt; which are both integers.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;memberState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;reputation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;deliveryState -&amp;gt; Holds data for each &lt;strong&gt;delivery&lt;/strong&gt; that will be sent to the smart contract. It contains &lt;strong&gt;hashed delivery details&lt;/strong&gt;, ** delivery fee** in ether, &lt;strong&gt;address ** of the **delivery owner&lt;/strong&gt;, the &lt;strong&gt;delivery status&lt;/strong&gt; which is an integer that describes the present state of the delivery, and lastly, the &lt;strong&gt;address&lt;/strong&gt; of the &lt;strong&gt;assisting member&lt;/strong&gt;.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="c1"&gt;// when status = 0, it means pending
// when status = 1, it means in progress
// when status = 2, it means completed
// when status = 3, it means confirmed
&lt;/span&gt;   &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;deliveryState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;membersData -&amp;gt; This maps the account address of every registered member on the smart contract to the memberState, in key =&amp;gt; value pair format. The &lt;strong&gt;public&lt;/strong&gt; keyword allows the &lt;strong&gt;memberData&lt;/strong&gt; to be accessed outside the smart contract by the public.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;  &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;memberState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;members -&amp;gt; This maps the account address of every registered member to their state of membership in the smart contract. The membership state is an integer of either 0 or 1 as the value. 0 indicates no membership, while 1 indicates active membership.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt; &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;ul&gt;
&lt;li&gt;deliveryData -&amp;gt; This maps the hashed delivery details to a delivery state in the smart contract in a key =&amp;gt; value pair format. It is also public and can be accessed outside the smart contract.
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;deliveryState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, add all these data states to your Logistics.sol file. You should have something similar to this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Logistics&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

 &lt;span class="c1"&gt;// The address of the account that launched the smart contract
&lt;/span&gt;    &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// state data for each member registered on the contract
&lt;/span&gt;    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;memberState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;reputation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="c1"&gt;// state data for each delivery transactions executed through the smart contract
// when status = 0, it means pending
// when status = 1, it means in progress
// when status = 2, it means completed
// when status = 3, it means confirmed
&lt;/span&gt;    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;deliveryState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// mapping are live arrays with key and value pairs
&lt;/span&gt;    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;memberState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;deliveryState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Rules or modifiers
&lt;/h3&gt;

&lt;p&gt;Smart contract rules in solidity are defined using the &lt;strong&gt;modifier&lt;/strong&gt; keyword. Modifiers are used for restricting access to data or functions in a smart contract. In this smart contract, you have only one modifier, &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;onlyMember -&amp;gt; This modifier allows only accounts that are registered as a member of the smart contract to access a particular data or function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt; &lt;span class="k"&gt;modifier&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;msg&lt;/strong&gt;  used in the modifier is a global variable in solidity. It holds the information of a transaction. &lt;strong&gt;msg.sender&lt;/strong&gt; gets the address of the account that initiated the transaction, while &lt;strong&gt;msg.value&lt;/strong&gt; gets the ether (Ethereum cryptocurrency) sent with the transaction.&lt;/p&gt;

&lt;p&gt;Add the modifier to your smart contract:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Logistics&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

 &lt;span class="c1"&gt;// The address of the account that launched the smart contract
&lt;/span&gt;    &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// state data for each member registered on the contract
&lt;/span&gt;    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;memberState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;reputation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// state data for each delivery transactions executed through the smart contract
&lt;/span&gt;    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;deliveryState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// mapping are live arrays with key and value pairs
&lt;/span&gt;    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;memberState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;deliveryState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

 &lt;span class="c1"&gt;// modifiers
&lt;/span&gt;    &lt;span class="k"&gt;modifier&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Functions
&lt;/h3&gt;

&lt;p&gt;These are the actions and use-cases of the smart contract. You need to perform verification and validations before performing any action. Verification can be achieved by attaching the right modifier to the function, while validations can be achieved by using simple conditional statements. To return meaningful responses during verification and validation, let's add some error handlers to our smart contract.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt; &lt;span class="c1"&gt;// errors
&lt;/span&gt;    &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="n"&gt;insufficientFee&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;registrationFee&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For your smart contract, you have 7 functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;constructor -&amp;gt; This function is common to every smart contract and it is called when launching the contract.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt; &lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;initiator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="c1"&gt;// here, you will register the initiator of the contract as a member
&lt;/span&gt;        &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;public&lt;/strong&gt; keyword indicates that the function can be called outside the smart contract while the &lt;strong&gt;payable&lt;/strong&gt; keyword indicates that the function requires cryptocurrency input.&lt;/p&gt;

&lt;p&gt;Here, you set the initiator address and added the account as the first member of the smart contract.&lt;/p&gt;

&lt;p&gt;Remember:  &lt;strong&gt;msg.sender&lt;/strong&gt; and &lt;strong&gt;msg.value&lt;/strong&gt; are both global variables. &lt;strong&gt;msg.sender&lt;/strong&gt; returns the address to the account that is calling a function while &lt;strong&gt;msg.value&lt;/strong&gt; returns the value of the cryptocurrency attached to the transaction calling the function.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;register -&amp;gt; This function is used to &lt;strong&gt;self-register&lt;/strong&gt; an account into the smart contract.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;register&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;registrationFee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;newMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;registrationFee&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;insufficientFee&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Ether value is less than the required registration fee"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;registrationFee&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newMember&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you validated a registration fee of 10 ethers and threw in an error for lesser fees. You also set the membership state, balance, and default reputation for the new member.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;requestForDelivery -&amp;gt; A member calls this function to request for &lt;strong&gt;delivery assistance&lt;/strong&gt;. The member must send a &lt;strong&gt;hashed delivery detail&lt;/strong&gt; and an equivalent cryptocurrency value when calling the function.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function requestForDelivery(uint hashedDeliveryDetails) onlyMember public payable {
        if(members[msg.sender] != 1)
           revert notAuthorized({
                reason: "Only members of this contract can request for delivery"
            });

         uint senderReputation = membersData[msg.sender].reputation;
         if(senderReputation &amp;lt; 6)
            revert notAuthorized({
                reason: "You have a low reputation, complete more deliveries to increase your reputations"
            });

        deliveryData[hashedDeliveryDetails].deliveryFee = msg.value;
        deliveryData[hashedDeliveryDetails].status = 0;
        deliveryData[hashedDeliveryDetails].status = hashedDeliveryDetails;
        deliveryData[hashedDeliveryDetails].owner = msg.sender;

        membersData[msg.sender].balance = membersData[msg.sender].balance + msg.value;
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code above, you used the &lt;strong&gt;onlyMember&lt;/strong&gt; modifier to verify accounts that can access the function. The payable keyword is an indication that payment in the form of cryptocurrency is required. You checked for the reputation of the member to verify its access to request assistance. You also saved the delivery data and temporarily stored the delivery fee in the wallet of the &lt;strong&gt;delivery owner&lt;/strong&gt;. The delivery fee would be sent to the &lt;strong&gt;assisting member&lt;/strong&gt; after completing the delivery.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;respondToDeliveryRequest -&amp;gt; Anyone can access the &lt;strong&gt;deliveryData&lt;/strong&gt; since it is public. Interested members can respond to the delivery request by using the &lt;strong&gt;hashedDeliveryDetails&lt;/strong&gt; to respond and handle the delivery.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;respondToDeliveryRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can respond to delivery request"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;memberReputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;memberReputation&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You have exhausted your reputations"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;deliveryStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deliveryStatus&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"This delivery is no longer available"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Above, you prevented members with no reputations from assisting in any delivery. You also checked the delivery status to prevent multiple delivery assistance, then updated its status and the &lt;strong&gt;assisting member’s&lt;/strong&gt; address.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;markDeliveryAsCompleted -&amp;gt; The &lt;strong&gt;assisting member&lt;/strong&gt; of delivery calls this function after completing the delivery.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;markDeliveryAsCompleted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You don't have access to update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you ensured the account calling the function has the right access then update the delivery status as completed if it does.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;markDeliveryAsCancled -&amp;gt; This function is used to cancel delivery in progress. Only the delivery &lt;strong&gt;assisting member&lt;/strong&gt; and the smart contract &lt;strong&gt;initiator&lt;/strong&gt; can access it.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;markDeliveryAsCancled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You don't have access to update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, if the delivery was canceled by the &lt;strong&gt;assisting member&lt;/strong&gt;, its reputation drops by 5,  but if it was done by the &lt;strong&gt;initiator&lt;/strong&gt;, its reputation will drop by 6.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;markDeliveryAsConfirmed -&amp;gt; This function is used to confirm delivery. It can only be called by the owner of the delivery and the contract initiator who calls it when the owner is not available.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;markDeliveryAsConfirmed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;deliveryOwner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deliveryOwner&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You don't have access to confirm this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;deliveryOwner&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;deliveryOwner&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, you removed the delivery fee from the &lt;strong&gt;delivery owner's&lt;/strong&gt; balance and added it to the &lt;strong&gt;assisting member's&lt;/strong&gt; balance. &lt;/p&gt;

&lt;p&gt;This is the full code for our logistics smart contract:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight solidity"&gt;&lt;code&gt;&lt;span class="c1"&gt;// SPDX-License-Identifier: GPL-3.0
&lt;/span&gt;&lt;span class="k"&gt;pragma&lt;/span&gt; &lt;span class="n"&gt;solidity&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;contract&lt;/span&gt; &lt;span class="n"&gt;Logistics&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// The address of the account that launched the smart contract
&lt;/span&gt;    &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// state data for each member registered on the contract
&lt;/span&gt;    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;memberState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="nb"&gt;balance&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;reputation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

 &lt;span class="c1"&gt;// state data for each delivery transactions executed through the smart contract
// when status = 0, it means pending
// when status = 1, it means in progress
// when status = 2, it means completed
// when status = 3, it means confirmed
&lt;/span&gt;    &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;deliveryState&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// mapping are live arrays with key and value pairs
&lt;/span&gt;    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;memberState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;mapping&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;deliveryState&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="c1"&gt;// modifiers
&lt;/span&gt;    &lt;span class="k"&gt;modifier&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nb"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="n"&gt;_&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="c1"&gt;// errors
&lt;/span&gt;    &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="n"&gt;error&lt;/span&gt; &lt;span class="n"&gt;insufficientFee&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;registrationFee&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;initiator&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="c1"&gt;// here you will register the initiator of the contract as a member
&lt;/span&gt;        &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;register&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;registrationFee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;newMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;registrationFee&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;insufficientFee&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Ether value is less than the required registration fee"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;registrationFee&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newMember&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;newMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;requestForDelivery&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;payable&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can request for delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

         &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;senderReputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;senderReputation&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You have a low reputation. Complete more deliveries to increase your reputation"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;deliveryFee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;respondToDeliveryRequest&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can respond to delivery request"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;memberReputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
         &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;memberReputation&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You have exhausted your reputations"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;deliveryStatus&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deliveryStatus&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"This delivery is no longer available"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;markDeliveryAsCompleted&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You don't have access to update this delivery"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;markDeliveryAsCancled&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You don't have access to update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;markDeliveryAsConfirmed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;onlyMember&lt;/span&gt; &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;members&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
           &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"Only members of this contract can update this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;deliveryOwner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;owner&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;deliveryOwner&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;msg&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;sender&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="n"&gt;initiator&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
            &lt;span class="nb"&gt;revert&lt;/span&gt; &lt;span class="n"&gt;notAuthorized&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
                &lt;span class="n"&gt;reason&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s"&gt;"You don't have access to confirm this delivery"&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;

        &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kt"&gt;address&lt;/span&gt; &lt;span class="n"&gt;assistingMember&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="kt"&gt;uint&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;deliveryData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;hashedDeliveryDetails&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;deliveryOwner&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;deliveryOwner&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="n"&gt;reputation&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt;  &lt;span class="n"&gt;membersData&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;assistingMember&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nb"&gt;balance&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;deliveryFee&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Congratulations! You just built a Logistics smart contract. &lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;In this article, you learned how to build a smart contract to help Logistics companies become more efficient in how they collaborate . In the next article, you would learn how to deploy and test the smart contract.&lt;/p&gt;

&lt;h2&gt;
  
  
  Let's connect.
&lt;/h2&gt;

&lt;p&gt;👉 On Twitter &lt;a href="https://twitter.com/drayfocus"&gt;@drayfocus&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;👉 On LinkedIn  &lt;a href="https://www.linkedin.com/in/ayomide-akinola-9b940117a/"&gt;Akinola Ayomide&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Cheers!&lt;/p&gt;

</description>
      <category>blockchain</category>
      <category>web3</category>
    </item>
  </channel>
</rss>
