Article cover

25.05.2022

24

Like

201

Views

How I developed a Project On NEAR Platform ?

Hello , I am Aysu. Today, I will tell you about the app that I developed with the near protocol in the Near Developer Course I attended thanks to the Patika.dev platform. First of all, patika.dev is a free software training platform that includes bootcamps and workshops.

Near Protocol Training Summary

In the first part of the training, basic informations are given; Introduction to web3, what is blockchain , what is near protocol, how to create near testnet etc.


In the second part of the tutorial, I learned how to use assembly script in near protocol , how to build smart contracts on the near platform. I would like to explain how I use assembly script and Near platform in my own project by skipping the web3 part.

Near Testnet Account

The fee charged for each transaction made on the blockchain is called gas. While developing an application for the Near platform, you must create a membership of the Near testnet and then near platform defines 200 near for you in an environment called testnet that you can use only for trial and development purposes.


Go to https://wallet.testnet.near.org/create link, choose a security method, I prefered secure passphrase (recommended) , save the words another place that given to you. In the next step you will be asked to enter the word in random order , 200 NEAR on your testnet account and you have a NEAR wallet -is an in-browser web based wallet- now !


My Project Summary


My project name is Near Music. In my project, which comes to my mind based on Spotify, the number of streams is purchased by users, not the monthly subscription.


Users simply create a membership and buy subscription types so they have right to listen to music. For example, listening to 500 songs is 0.5 near, while listening to 1000 is 1 near 1500 is 1.49 near.

There are two types of roles, Admin and User. Admin can create, modify, make inactive songs or subscription types. And user can create a membership and buys as many subscriptions as they want, also list songs and see account details. Each time the user listens to a song, the right to listen to the songs decreases by one.

I used three models to store datas ; Song, Subscriber, Subscriptiontype. I added Song model as an example.


P.S @nearBindgen decorater makes classes serializable.

We described the models, it’s time to create a contract. Contract is actually a class with its own functions and variables. In my contract class I defined three collection, persistentVectors so I can store my data derived from the three models I mentioned above. (songs,subscribers,subscriptionTypes) Then I define all functions can be used by Contract owner (who publish contract to near) , or User (who calls contract).

I would like to show both how the code is called and how it works by both user and owner.


How Works Sample Owner Function :



addSong function takes some parameters like artist songName etc. It creates a model then add to the songs Persistent Vector so it becomes persistent on the blockchain .

How Works Sample User Function :


First we check is the user have enough depositto buy subscription, if user is real and is here a really subscription type . Then user deploy contract so buy a subscription , finally user is added to the subscribers vector.


How To Call a Contract Published to the Near Platform?


Owner :


near call $CONTRACT addSong ‘{“artist”:”$artist”,”songName”:”$songName”,”description”:”$description”,”albumName”:”$albumName”,”genre”:”$genre”,”label”:”$label”,”country”:”$country”}’ --accountId $OWNER

User :

‘{“subscriberId”:’$subscriberId’,”subscriptionTypeId”:’$subscriptionTypeId’}’ --accountId $USER --deposit $attachmentDeposit

This is how user buy subscription on contract.

Words starting with $ are variables that change according to the user.


Final Words:


I really enjoyed while building an app with NEAR Protocol. I tried to explain my project from the point of view of both the software developer who wrote the backend application and a user. If you want to examine it in more detail, I am attaching my project. Good luck with !


https://github.com/aysuays/NearMusic

Web3 Fundamentals and NEAR

Comments

You need to log in to be able to comment!

Aysu Gür

Location

Ankara, TR

© 2021 Patika Dev

facebook
twitter
instagram
youtube
linkedin

Disclaimer: The information /programs / events provided on https://patika.dev and https://risein.com are strictly for upskilling and networking purposes related to the technical infrastructure of blockchain platforms. We do not provide financial or investment advice and do not make any representations regarding the value, profitability, or future price of any blockchain or cryptocurrency. Users are encouraged to conduct their own research and consult with licensed financial professionals before engaging in any investment activities. https://patika.dev and https://risein.com disclaim any responsibility for financial decisions made by users based on information provided here.