Skip to content
by Unity Nodes
NEAR Protocol

L1C4 - Show and Tell exploring our newest sample It's called thanks!

about 34:29 long

Nothing is loaded from YouTube until you press play, and then without tracking cookies.

About this video

NEAR Certified Developer

This course is an opportunity for web developers to earn a Certificate of Completion that represents the ability to design, develop, test and deploy smart contracts on the NEAR platform.

Slides: bit.ly/near-ncd

Overview

During this course we practice the following:

perceiving web 3 in the context of human history reading contract code in Rust and AssemblyScript writing contracts using Rust and AssemblyScript testing contracts using unit and simulation tests deploying contracts and a sensible user interface

---

Follow the latest from NEAR Protocol on: Website: near.org Discord: near.chat Blog: near.org/blog Twitter:   / nearprotocol   GitHub: github.com/near github.com/nearprotocol #Blockchain #FutureIsNEAR #NEAR #nearprotocol

Transcript

5,726 words

Captions as YouTube publishes them, usually machine-generated, so product and people names can be misheard.

  1. 0:07

    i'm just kidding okay so look i've got you know four steps five steps here i'm just going to walk through these really quick um and i'm gonna tell you briefly so i'll take like a minute or so and move through this if you find this confusing or overwhelming please don't worry uh just ask for help okay um uh yeah oh sasha is suggesting something to adjust your name and discord so you're saying not mainnet account but actually your first name and then a pipe character and then your mainnet account sasha is that

  2. 0:38

    what you prefer for the names it doesn't matter like i i personally prefer to call people like like with their first names and near accounting this is uh this is mandatory here this is why we are here like but people ask when when do we use near we use it right here okay so so definitely you want the mainnet account in the name and then if you also want to use your first name you're welcome to do that right but that's not mandatory

  3. 1:02

    you're saying some people may want to remain pseudonymous for example right that's perfectly fine absolutely absolutely yeah yeah you don't have to tell us your your name if you can imagine that we're working together and i don't need to know your name i just need your attention actually and i need your commitment to the work uh your name is your own if you want to keep it that's fine

  4. 1:19

    i can respect that so so this is a brief demo you're going to need one mainnet account if you don't already have one please let me know before we get off this call i'd love to send you five near to get set up to do that uh two testnet accounts wallet.testnet.nerd.org create a couple of test net accounts you'll have them no problem we've the faucet funds you with 200 near wallet.testnet you can do it right now use the email recovery method it's the

  5. 1:43

    fastest thing it's not secure but it's super fast all right so um the uh the technologies that we're going to need node.js git and near cli if you're familiar with node this is how you install near cli if if you're not please ping me uh later and that's all the text that's here i'm going to split my screen left and right i'm going to use environment variables to manage some of the details and you can try

  6. 2:06

    you know export you know we're all equal in this life if you want you know whatever your variable names are key value pairs with an equal in between no space um and then if you get an error about missing environment variable it's like the all caps thing right and you can echo dollar sign to dereference the variable or read the value whatever and then whatever the the name of the variable is all caps okay so this is basic sort of bash and tools if you're uncomfortable

  7. 2:30

    at this point no stress at all this isn't a prerequisite just keep asking i'll gladly help you with it on the left hand side i'm going to clone the thanks repo it's it's github.com learn thanks so this you should know now is the github organization that we're using there is a repository called thanks and that's the one i'm going to be demonstrating for you there's another one called near account utils that i'll be using for visibility reporting right inspect inspecting the state of the blockchain

  8. 2:58

    so that i just posted into the chat the github.com learner is the github organization and i'm going to be cloning both of these repos on the left-hand side nothing for the first few minutes i'm just going to play with a couple of commands near cli near state you know you can do your account.testnet or your account.near you can do this on on mainnet and on uh testnet and i'll show you how to switch between the two

  9. 3:22

    and then i'm gonna run the storage uh the this utils in the right hand side has storage to be able to see the storage behind the account okay so you'll see what that looks like for some of these accounts and um uh you know uh uh you we want to get uh you know uh this this thanks you know set up this this application so um on the left hand side i'm going to build and then deploy thanks to my testnet account at that point if you've been following along you

  10. 3:52

    can actually also read the state you know if you have near cli installed you can actually do this from your computer it's all public information by the way um and then on the right hand side i'm gonna you know turn on a monitor for my um deployed contract and i'm gonna start interacting with the contract okay so that's what we're about to do it's been about four or five minutes i'm explaining it now i'm gonna get it done hopefully in the next five ten minutes max so

  11. 4:16

    uh here we go um so let's get over here and uh you can still see my screen right it's left and right panels can you see that okay yeah okay great how's the font size is it okay it's a little bit too small yeah okay that's going to be a little bit tricky here because the formatting uh of these tools uh is uh is roomy so i may need to mess around with the formatting a little bit let's see how it goes okay so uh so now uh what what do i wanna do

  12. 4:53

    i'm here i'm in this uh uh you know cloned repo called thanks it's just in my personal folder on my computer i'm running a mac um i've got uh uh node installed um and i've got um uh near cli installed as a prerequisite okay that's where i'm at everybody cool if you're not sure what i'm doing uh that's okay but we're not gonna be able to cover it in the next five minutes just keep asking okay um and and if you are comfortable with what i'm doing like just keep up no problem at all you get the

  13. 5:30

    idea right it's called near cli uh do we have a guide yeah i mean look flex i'm happy to write a guide for you i've got these pages uh if you need more then i'm happy to make it so i'm i'm avoiding the temptation to make the perfect guide for everybody until you ask for it then i'll make what you need but before then you have you know 40 people uh in this cohort uh maybe you know 10

  14. 5:54

    of which i'm sure would love to help with any question and the others might be a little bit too busy or something like that um yeah so anyway uh maybe that's enough on that and so now this near cli if i just type near i'll get this again that you know kind of formatting is a little bit uh tricky in this width but it you know it looks something like this and you can see all these different commands like create account check state check the keys i'm going to play with state and

  15. 6:19

    keys right now near state near state sharif.testnet will report to me that i have an account here it has you know nineteen thousand near on it funny money on test net um it has a contract uh attached to it because of the code hash if you're coming from ethereum this is different the accounts it's like having ens built in there's a friendly name like this dot testnet on testnet.near on mainnet and this gives you some metadata about that

  16. 6:50

    we can check another contract near uh state maybe uh umgondo.test.net i think i have an account there no how about ajax.testnet yeah so this this account here has no contract installed an account on near you has one or no contract 001 contracts deployed you make the account you deploy the contract to it and then you can call methods on that contract that's the setup okay yeah wong you have a question

  17. 7:24

    how long you have your hand raised you have a question okay just interrupt me if you end up with a question so that's near state and then near keys you can see here i have several keys on this test account and these keys are one of two types it's either a full access key here yeah one contract for account adrian and then you can have sub-accounts and that's what we're about to do is to deploy the thanks contract to a sub-account so that it's thanks.test.thanks.sharif.testnet i'm

  18. 7:56

    about to show you how to do that full access keys and function call access keys those are the two types on near there are eight actions four associated with you know identity create account delete account add key delete key those four actions you can see that in our docs docs.near.org create account delete account add key delete key two associated with money stake and transfer and two

  19. 8:22

    associated with code deploy contract call function function call okay those are the eight things that you can do the eight basic things you can do the rest api you've got you know the hdb verbs and you've got yours you know crud operations so on near there's eight things that you can do from the outside you can do them by sending a transaction to the network and from the inside you can do them using cross-contract calls like one contract can deploy another

  20. 8:46

    contract one contract can add a key to another contract that makes sense to another account and here the word account and contract is basically the same thing on near because an account may or may not have a contract deployed to it okay so that's the keys you can see the keys will be different depending on the account that i'm using so here's ajax that testnet keys i may only have a couple of keys here several full access keys

  21. 9:10

    right and one function call access key okay so that's what that's that's my keys yeah yeah so when we when you say that your name dot test net is it like a wallet because if it is a wallet then how we are deploying contract in it so like there's some confusion yeah no problem um so i think um the the best thing that i can do is to open here just a browser oops and show you that the wallet

  22. 9:50

    this is my sharif.nir account i have three point nine near yeah yeah sure the the wallet is a web-based interface that keeps my keys inside of local storage on the browser or i can use the ledger if i want a hardware wallet something like a ledger right the ledger works with near to be able to sign transactions for any high high value wallet you do that but i'm not talking about the wallet i'm talking about accounts

  23. 10:21

    so and a wallet is a terrible name for the software that holds your private keys your secrets your password that you use for signing transactions right that's what a wallet is an account is your your name and an account includes the account name any data in storage any contract that's been deployed any keys that are attached and several other things that's an account on there and if you want to look for a place where you can learn more about this and read the specifications for some of you that maybe want to move more

  24. 10:52

    quickly you can go to the nomicon here this is the link to that and read about the account model with all of the details here that you'll find about the account different account ids here's the list of data that you find on an account right so there's a ton of information here in this nomicon this is not the same as our docs which is also another great resource and this is not the same as near.org

  25. 11:28

    learn which is yet another good resource so these are maybe the three best places for you to start and roll up your sleeves and dig in so now we're taking a look at this thing and i want to look at something else now i want to do so you know here i can run in yarn storage accounts collect keys keys whatever i want to run storage so yarn storage and then maybe sharif.testnet and see what that looks like and this is you know some problem because i haven't run yarn yet the module is not found if you're not familiar with node

  26. 12:07

    so now i've run yarn or npm install and now i can run this program and you see of course the formatting is terrible terrible terrible this is what the the storage will look like when it's full okay so we're about to do this if i want to i can export this is the the environment if you're not familiar with the environment i can export an environment variable called near env to be mainnet if i want and now when i run

  27. 12:39

    um you know something like near statesharif.testnet it'll say i don't know what you're talking about but i can look at my mainnet account and you'll see the three near the 2.9 or whatever near that i have there on this account so this piece of text is how you set that variable in your terminal again if you're familiar with the stuff it's obvious to you at this point if you're not familiar with it then it's going to take you more than a couple of minutes to figure it out and that's fine so now i'm going to run yarn storage

  28. 13:13

    a specific account that i set up this week that has this thanks application on it called thanks.fuzzydice.ner and you'll see that this account on mainnet has a contract deployed with this data in it this is the account uh that has this thanks application running it has an owner it allows anonymous thank yous it has received one contribution totaling five times 10 to the 24. if you can see that

  29. 13:47

    5 times 10 to the 24 near as measured in yakuto near so 10 to the 24 is basically five near and uh five has been transferred actually to fuzzy dice okay and this is another account that i control uh i'm writing them you know something like appreciate you okay so this is the thing that we're about to set up okay so now let's let's do it uh it's gonna be a little bit tricky with this kind of

  30. 14:11

    sliding back and forth like this but we can see how it goes um so these are all the files i'm going to run dev deploy first for testnet just a time check we're at 8 30. so i'll deploy the contract here briefly and then i will uh you know show you how we can actually monitor that how we run the report uh and uh and so on okay so so let's check it out so now um um i'm gonna need uh to to npm install or

  31. 14:44

    yarn because i've just cloned this you saw there's no node modules folder here so now i've installed dependencies and i'm going to run scripts dev deploy this is gonna tell me hey you're missing the contract and the owner but i don't care that's fine i'm just gonna try and delete these two things and you know i wasn't able to then it's gonna clean up this near dev folder for local keys for development then it's going to run yarn run build yeah that's great no problem

  32. 15:16

    okay now it's going to redeploy the contract and we're going to end up with this account id so when we're using dev deploy this is a specific command dev deploy that generates an account for us and throws a contract in there it's a time stamped account so we don't need to worry about making our own accounts so for development it's super fast okay so this is the account let me export let me do um what is my near env right now it needs to be on test net no it's on mainnet so

  33. 15:50

    let me export you can also unset if you want to clear this thing out on set near andv obviously maybe you know that already so export near env equals testnet now yarn storage and i'll put in this dev account that was generated for me and you'll see here no records found you know so there is an account near state and i can near state and i can paste this see there is an account it does have a contract deployed because it's not all ones it's not the default code hash there is a contract deployed it takes up

  34. 16:29

    30 kilobytes and there's 200 near on this dev account that was just created by the near cli command called near dev deploy and i want to show you uh here briefly that um that these scripts are are just right here uh you know it's just bash so uh here's the dev deploy command uh and after i build release i'm just pulling that down so these are all these are all very readable so

  35. 17:14

    okay so so there is a contract there is an uh sorry and there is an account that was just built there is a contract deployed to this account uh and uh now we want to check out the storage and we ran it we got no records found okay so here's what i'm to do i'm going to watch run this watch program that's going to maintain visibility on this contract just like looping right so actually i could do this with

  36. 17:48

    like export contract equals you know and then type that in and now i can do watch contract if you see that that command and it's just going to loop now every second just kind of you know watching this this contract okay now over here i'm going to take this you know export contract equals and paste that in as well and then i'm going to copy this command right down here near call contract but first i need to set the owner actually so echo owner is blank so export

  37. 18:24

    owner is maybe sharief.testnet what's my near environment here it's blank so that's the same as test net that's fine i can make it explicit so i don't get confused and now i'm going to run this command and when i run this i want you to keep your eye on the right-hand side of the screen because it's about to light up so i'm going to run this keep your eye on the right-hand side

  38. 18:48

    the transaction is complete and boom there it goes my contract is now initialized and this is from the blockchain the serialized uh object that represents the contract serializes json and uh if you want to see what that looks like on the contract level i know we're five minutes over the demo uh walk through but for some people who are keeping up this will save you some time when you clone thanks you'll see in the assembly script folder

  39. 19:18

    this index.ts and uh here if you look there's a class it's called contract we could have called it banana if we want it doesn't matter contract and then there's an owner allow anonymous is a boolean contributions um those are the three uh sort of uh members there of this contract oh boy um and so here you can see owner allow anonymous and contributions so just to remind you again owner allow anonymous and contributions because of nearby gen

  40. 19:50

    this contract can be serialized to json on the blockchain and so when i initialize the contract its state kind of whips up and it gets serialized on chain so i'll stop with like the amount of details at this point but what i want to show you now is that actually i can call this contract so scripts say thanks thanks so much for being here and see if that if that works uh i don't think the exclamation point helps in dash missing speaker variable so export speaker is maybe ajax.testnet that's

  41. 20:28

    another account that i have and let me try that on the right hand side you should see that method appear the results of that method ajax says thanks so much for being here with no contribution let's try that again and this time i'm going to add maybe you know three near and so again you'll see this contribution gets added but this time the contributions also lights up i've just sent money from ajax.testnet this three near contribution again that's 10 to the 24.

  42. 21:01

    so that's three near and that gets added here total and received and if i want to i can keep going if i try and do this again with another three near i'll get an error because it's going to look pretty bad but it's not the maximum contributions have been reached please transfer funds because we have an assert statement there that is stopping us here's that assert statement you know maximum contributions assert financial safety limits is happening whenever you try and say something to the contract we're asserting these safety limits in

  43. 21:35

    case you decide to go cowboy on me and deploy this to main net i don't want you holding a bunch of money in an account that hasn't been reviewed for security so it'll stop you but now actually i want to transfer some funds so let's do uh near state age uh this is um uh dev uh account but i am the owner sharif.testnet so statesharief.testnet 19730 near in this account now watch i'm going to issue a transfer and then this three near is going to show up it'll be 19733

  44. 22:15

    okay so scripts um oh we can run run a report first maybe here's a report what it looks like you'll see you know these people have commented you don't have to do this report and this is the financial work here so not forgetting you know set 19 000 let me bring this up again this number should change to 733. so scripts transfer that'll transfer to the owner you'll see the right hand side received will move to transfer okay so that just happened and then 19 730

  45. 22:54

    should become 197.33 so that money just got transferred to the owner of the contract so that's a quick tour of this contract it's this file here uh you know 100 lines of code and this file here with some models you know for the message uh and contribution tracker if you're familiar with javascript or typescript this should look like um you know a good friend that you haven't seen in a while if you're not familiar with javascript or typescript this this might be a little bit disorienting for you

  46. 23:24

    um but uh just keep asking questions and the key piece is if we look at sort of what what did we actually do here uh in step one i just set up my windows in step two i cloned the repositories in step three on the right hand side i played with you know near state the near cli near keys near storage to view all this stuff that's all that happened there right and then on the left left-hand side i also ran this you know dev deploy instead of the the deploy script i'll i'll do the deploy script for you now

  47. 23:55

    uh to show you what it looks like to deploy to mainnet and test that no problem and on the right hand side i had this watch command watching storage actually um yeah uh when i run dev deploy it says missing contract yeah that's right it'll say that the first time because you don't have that variable then what you want to do after that is type export contract equals and then like the dev you know whatever the the number is you want to do that and that'll be your contract not that one

  48. 24:26

    obviously dev123123 but whatever the one is that you are using and then here uh you know what we did with this is we just started using the scripts you know after this these scripts here um which you can read about in in the read me there's there's a you know some some documentation here that explains all of these things in the readme of the repository which you can go and check out now learn dashner is the organization thanks is the name of the repository if you want to run this on linux mac or

  49. 24:58

    windows we've got some notes down here for you and so i'm hoping that this has given you kind of a clear sense of what you could be doing with these contracts now what i'd like to do is if anybody wants to take the chat challenge of actually cloning this repo and deploying a contract to their testnet account i'd like to send you some some tokens so has anybody done that please raise your hand

  50. 25:22

    in the zoom call you can do it with a little click i think i'd like to see how many people have tried to do this um gosh i don't know where it is in my interface here but there's a way to raise your hand you should be able to click on something to raise hand okay so it looks like you seen and the gentleman whose name isn't appearing but you spoke a little bit earlier with the mic on ubuntu is there a way that we can request for these

  51. 25:53

    uh afterwards can you can you get near on testnet yeah i mean what you should what you should do is just go to wallet.testnet.near.org right wallet.testnet.net.org and make an account and we give you 200 near from the faucet okay yeah i was like exactly asking for the like yeah yeah create an account oh request more than 200 near on the test net yeah if you want to you can just make dev deploy accounts and delete them with yourself as the beneficiary that's how i

  52. 26:36

    got 20 000 in there just while while testing it makes sense yeah no no sweat okay so it looks like flex 13 uh is up for a challenge here so what what's actually happening flex 13 do you have any storage no records found near state flex 13 do you have a contract deployed no you haven't deployed a contract yet looks like maker.testnet has something have you deployed a contract maker maker.testnet has not deployed a contract yet so you've made test net accounts but you haven't deployed a

  53. 27:08

    contract yet how do you deploy a contract right how do you do that so you've cloned thanks for example and you go to scripts so first let me just check here scripts x deploy and then we should see here the build and let me just uh check so near end and owner are going to be two important variables that we need with this so echo near end is testnet echo owner is sharif.testnet i'm going to deploy thanks.sharif.testnet

  54. 27:56

    so if i type here near state sharif.testnet you can see there is an account there obviously but if i type near state thanks.sharif.testnet there's no account i'm about to deploy one now scripts x deploy to testnet is my near end and sharif.testnet is my owner building the contract deploying the contract initializing the contract all of this happens in the script you can check out the script

  55. 28:26

    yourself we still don't have anything there up we just made the account so now there is an account but there's no contract it's all ones now starting deployment and we've deployed a contract you see the difference here all ones versus this code hash for the contract and the code hash is deterministic if if it's on a if you compile on the same machine then you should see it right there

  56. 28:52

    so it looks like alex has deployed to dev with this uh yeah reboot your brain nice flex so you can watch the recording so i just want to show you look near state thanks.sharif.testnet didn't exist when i ran this script xdeploy it got created then we built the contract made a sub account here saved the keys locally and then deploying the contract so we made the account there's no contract deployed then we deployed the account right over

  57. 29:23

    here and now you can see there is a contract that's deployed because it's not all ones the code hash is not all once so i know there's a contract deployed i don't know what the contract is i can't request the source code that's something under development still but i know there's an account there i know there's a contract there and so now if i want to i can run here yarn storage

  58. 29:46

    with thanks sharif.testnet and you'll see it's ready to go if anybody wants to from your repository that you've cloned you can type um uh here make make sure that the contract variable is set to thank sharif testnet make sure the speaker is set to something that you've locally logged in as you'll do that with like near login hit enter and follow the prompts and that way you can sign the event with the

  59. 30:30

    speaker and make sure near end is test net and at that point you can sign this and actually say hello to me and i'll see it here i think that would be pretty cool okay so someone looks like they deployed to thanks at ys24 okay great let's give that a shot so here we go thanks ys24 fantastic thanks ys24 let me just say um uh thank you by uh changing the speaker to sharif.testnet because i'm about to give you a big thank you for taking on this challenge

  60. 31:12

    and i'm gonna say thanks um with uh nice work totally awesome here is i don't know what five thousand near okay oh too much it's limited to five near sorry about that um so uh here's five near thank you so um oh wait a second sorry about that um the the contract uh was uh was set to my my dev deploy uh that would have been so funny uh to send uh that near uh yeah so here's five near for you thank you so much so much really appreciate that okay we should

  61. 32:03

    see that on the right-hand side on your side um uh ys24.testnet you can run the report and you'll see the data okay so um this was a quick demo it's all recorded hopefully it's useful i'm more than happy to do this again for you right so as a teacher my patience runs deep so please be selfish ask again you can watch the recording you can hit me up dm i can join your group and give you a one-on-one demo where you ask all the things that you want i have no problem committing much more time

  62. 32:36

    outside of these windows of meetings if you want an hour with your team or something like that but please help me scale let's not have a one-hour one-on-one meeting schedule something with your team send me a request on discord can we meet for 30 minutes can we meet for an hour can you go over the demo can you help us with this can you help us with that you'll find i'm incredibly generous uh if i can give up the time to help you this week i will do it because the only thing that

  63. 33:01

    matters is that you perform as best as you possibly can by friday so is there a way to run the scripts in windows look i just have to tell you right now windows is going to be a challenge you might want to run like ubuntu in some virtual machine or something like that on windows if anybody has a windows machine with some suggestions please help this is a perpetual challenge is running these scripts on windows obviously some of these bash scripts are

  64. 33:23

    written specifically for you know kind of a linux compatible uh environment uh you know the way that i'm testing the environment variables with the dash z and all that stuff if you are familiar with writing shell script on windows you want to rewrite some of these for windows users you're more than welcome to do that right okay so um yeah virtualbox awesome that's fantastic okay so listen i just want to end this

  65. 33:50

    on you know just the the uh the most um kind of you know positive note that we can possibly end this on which is um thank you so much for deciding to do this with us i am certain that the last 30 minutes has been completely overwhelming for most of you maybe one or two people are still tracking welcome good for you it's your responsibility if you're keeping up to help others just like it is mine decide that you're going to help other people catch up with you and if you have a question if you're disoriented it's your

  66. 34:29

    responsibility also to demand the help that you need i want to be super clear about that no one's going to come and save you you're going to save yourself and we're here to help okay okay awesome