[Report] Tutorial Repository for developing Near Contracts in Rust (mar 01-> mar 30 2022)

Project Title: New Full Tutorial for Near in Rust.

One-liner: Tutorial Repository for developing Near Contracts in Rust

Project Summary: : There are many great tutorials about creating NEAR contracts in Rust. This project isn’t intended to be a replacement to any of those. Instead, it will be detailed examples about the features of Rust using NEAR contracts. Several times when the compiler gives an error, a new developer may feel compelled to just try making changes until the error go away.

This tutorial will show all possible implementations for all kinds of features in rust. Including ownership, modules, traits, generics, enums and so on. That way it can work as reference for aspiring rustaceans.

Project Members: Lucas Lemos, Matias Wald

Period: Mar 01 → Mar 30

Extra : Project has the main branch in Brazilian Portuguese. Translations to English and Spanish are also being made by Matias Wald.

The following list are the results obtained by me:

Week 05

  • In the previous week, I shared a post about my free course about NEAR Dapps in Rust. Lecture is in brazilian portuguese. It was shared in twitter, linkedin and some reddit forums. One person subscribed. I contacted this developer and had a 2-hour session teaching him about the NEAR protocol, the platform, shared links of information related to development and, in the final hour, showed him how to implement a simple rust contract, run unit tests, deploy and run the functions.
  • Met with a developer interested in learning about rust. Gave a summary about developing in the language, and some instructions on topics that are very useful to know. Including issues that one should be weary about that aren’t common in most popular languages out there.
  • Participated in NEAR University AMA (mar 04). Showed my chess game submission that granted my NCD. Discussed the issues that I had while developing it. And shared some ideas for dapps acquired from developing this project.
  • Decided on the subjects of lessons 5 to 8 of Tutorial_NEAR_Rust :
    • Lesson 5 will be about rust macros. What they are. Some of the most useful ones a developer should know. But not how to create macros.
    • Lesson 6 will be about rust enums. The standard enums: Option and Result . Custom enums. Match instructions. How to create a very compact error system using enums. What is the ? operator.
    • Lesson 7 will be about traits: What traits are. Most used standard traits. How to create traits. Generic Functions.
    • Lesson 8 will be about collections. Standard rust collections. NEAR collections. How to use both.
  • Created the implementation of lesson 5 code example. Now need to write the readme with the actual lecture. Link: https://github.com/On0n0k1/Tutorial_NEAR_Rust/blob/main/lesson_5_macro_usage/src/lib.rs
  • Studying how to create and manage NFTs in a near Dapp for a later lesson.
  • I’m currently sick in the last days of this week. Which is why I unfortunately, wasn’t able as much as I wanted recently. Hopefully I will be better in the next couple of days.

Week 06

  • Recovered from my illness from last week.
  • Finished Lesson 05 about “Using macros in Rust”. Link: https://github.com/On0n0k1/Tutorial_NEAR_Rust/tree/main/lesson_5_macro_usage
  • Met Matias Wald, which agreed to translate the documentation and markdown files into spanish and English. Looking forward to it.
  • Started Lesson 6. It is a lesson about “Enums”. It will be a workspace divided into 4 sub-lessons.
  • Lesson 6: Explains how to use workspaces.
  • Lesson 6-1: Explains what are enums and how to use them.
  • Lesson 6-2: Explains standard library enums, Result and Option.
  • Lesson 6-3: Explains how to create a practical error system using enums.
  • Lesson 6-4: Advanced. Explains how to use enums to group several different types into a single behavior/function/method.
  • Hopefully I will be finished with all these sub-topics before next week.

Week 07

  • Finished code implementation for lesson 6-1. Carefully made sure that it had examples showing enums and showing general uses for match instructions. Included documentation for all functions. Final code implementation has 880 lines of code. Link: https://github.com/On0n0k1/Tutorial_NEAR_Rust/tree/main/lesson_6_enums/lesson_6_1_simple
  • Started the readme explaining everything that happens in the code example.
  • Wanted to create a front-end example for a tutorial using svelte. Unfortunately, had an issue with the bundlers that caused the library to misunderstand “near-api-js” module. Spent a few days studying “svelte”, “rollup” and “near-api-js”, trying to understand how to load dependencies properly. Fortunately, found out that we will have some new examples in near university soon. Looking forward to it.
  • Got into contact with a brazilian web3 group, and maybe will create a free course or workshop discussing near and how to develop dapps. Discussions ongoing.

Week 08

  • Refactored the project so it has folders in each of the languages available. Link: https://github.com/On0n0k1/Tutorial_NEAR_Rust
  • Finished writing Readme.md for lesson 6-1. While it’s just a “sub-lesson” for enums, the code and text ended up huge. It explains all kinds of way to declare enums and how to use match statements. Close to the end of the lesson, I gave some insight on how to best use enums when designing your project. Enums restrict our code, that is good in some ways, bad in others. A developer should be aware of these characteristics to avoid falling into a refactoring nightmare. Link: https://github.com/On0n0k1/Tutorial_NEAR_Rust/tree/main/PT-BR/lesson_6_enums/lesson_6_1_simple
  • Lesson 6-1 had most of the content. The following sublessons should be a lot smaller.
  • Lesson 6-2 will talk about Option and Result. With a few examples. I.E. If we call pop function in a Vec, it returns an Option.
  • Lesson 6-3 will go into details about Result. Most specifically, how to use “?” as a quick way to escape from a function in case of an error.
  • Lesson 6-4 I think I will push this one into a later lesson. It would show how we can combine together several structs, an enum and a trait to create one object that behaves in several different ways.
  • I announced a rust lesson in the brazilian web3 group for april 09 09:00 am. Will make sure to have some good examples to show by then.
  • Matias Wald already translated lesson 1 and 2 to english. It’s looking good!