Solana Smart Contracts - Solana Programs in Rust and Typescript | Serpent Academy | Skillshare

Playback Speed


1.0x


  • 0.5x
  • 0.75x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 1.75x
  • 2x

Solana Smart Contracts - Solana Programs in Rust and Typescript

teacher avatar Serpent Academy, Passion for teaching and learning

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

    • 1.

      Intro

      1:40

    • 2.

      Intro to Smart Contracts in solana

      2:32

    • 3.

      Solana Smart Contracts Life Cycle

      6:18

    • 4.

      Create And Deploy First Smart Contract

      9:41

    • 5.

      Call a Solana Smart Contract from a Client

      10:17

    • 6.

      Create Smart Contract, Send Data to Smart Contract in Solana

      23:48

    • 7.

      Serialize and Deserialize, Save Data on Account with Solana Program

      60:51

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.

79

Students

--

Project

About This Class

Learn how Smart Contracts in Solana Work how to write your first Solana Program and Send Serialized Data so you can communicate by storing data in the on-chain and being able to read it with any type of client: a video game, and app, a web browser. 

It's recommended for this class that you know a little bit of Rust.

Code for the class:

https://github.com/serpentacademy/Basic-Template-Solana-Smart-Contract

https://github.com/serpentacademy/Send-Data-to-Solana-Smart-Contract

Meet Your Teacher

Teacher Profile Image

Serpent Academy

Passion for teaching and learning

Teacher

Hello, I love coding, science, art, creativity. We are in a great era a Renascence of knowledge is happening right now.

I also love sports and reading, when i was in high school I read poetry a lot, and for sports I was all about basketball and soccer. 

I will love to teach programming and art tutorials, have more than 10 years programming and in robotics.

Let's share this journey together!

 

See full profile

Level: Intermediate

Class Ratings

Expectations Met?
    Exceeded!
  • 0%
  • Yes
  • 0%
  • Somewhat
  • 0%
  • Not really
  • 0%

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.

Transcripts

1. Intro: Welcome to this are landless Maori contract cause why does this matter? Contract as my contract is MPS program is stored on the blockchain. You not need new mental run and do even the thrust to both bodies. Empowering Fairplay. Yslow lemma. Easily do option. Transaction costs less than a penny. Faster than, than Visa. And as he's definitely faster even if 500 thousand TPS, real bows, decentralizing and startups. Mouth. Boss, he was Bay Company was user's weakness heart contexts in real time, you'll do your ecosystem, you're talking, doesn't matter if you're building a video game, a bank of decentralized applications. So lambda company or long-term solution for creating and allocate. What are we learning in this course? So lambda is more complicated slide. But I'm going to create our first contract in Solana, unseen data to asthmatic contact and store that data on chain and off-chain. We're going to learn how to serialize and de-serialize data, both off chain and the side. We're going to learn how to transfer soul with a smart contract. Welcome to this course. I'm very happy to have you here. 2. Intro to Smart Contracts in solana: It programs in Solana, are they equivalent for smart contracts in other blockchains? And they are powering DeFi and gaming. Dow's. A lot of more things. Programs, programs processing instructions. Programs are stateless. Programs. Supported in accounts marked as executable. Programs are. Bpf loader is recommended to write programs in gross pose. You can use C plus plus and you can use see what Ross is easier and more secure. Health programs have a single entry point instruction. So when you want to invoke a program, the basic arguments are the program idea. You want to invoke the array of accounts, the instruction data. Writing programs. Angkor is a powerful solution built on Ruby on Rails for writing programs with smart contracts. Focusing on security is built over Salama. How do you write programs? The first step is to write the programs in roast recommendation and test them on local host. Then you can go to definite or testing it. And finally, you can go light to maintenance programs. Programming invocation is done by making RPC connection with the API of the current cluster. The cluster can be maintenance, doesn't it? Definite and local host for testlet and definite, you can request so lambda because programs leaves in accounts and accounts pays rent units Alana. At the beginning you can test in local host. You can ask for some coins from some Solana and you can test in the developer network and the test network. And finally, when you have your program ready to go live, you can do some Solana and pay the rent. Because we are going to see next accounts. How do they play a program? Once you establish your new cluster environment, you in the terminal or in the command line, you write Solana pronoun deploy with the proton BIPAP. You can include your cargo package manager if you are in rows. 3. Solana Smart Contracts Life Cycle: Lambda is my contract lifecycle. The communication between the Earth and the own Chain. Program can communicate with the cylinder network. There are three ways by the project and a program. For example, in roast Solana network, where the program will live forever. Hold it away. With a client. We can send a pulse section by passing instructions to specify which program in this alarm network we are running for, we can quite some information section and query uses the JSON RPC API Upsilon with the methods that Solana approved, for example, get the counting for. A client. Can communicate, can be anything, can be the command line, can be an unreduced up how Unreal Engine game unit, the aim, or any third-party robot can be anything the client, but it needs to follow the instructions. To send RPC API, correct? Format the JSON with the valid signal to some accounts. So we can have our response. Transactions. Transactions are composed of signatures. Message message contains, Heather account address. The account addresses out of the entities interacting. For example, it can be your account. Now that accounts of your friends or of our network of the decentralized application. You'll need to pass arrays and block the instructions. A single instruction can only call one program. Data bytes are passed on past patterns. Instructions can only point to one smart contract or program. Pass. The program can use this data to perform an action. Instructions are composed of program AD accounts on beta. The product ID is a smart contract that you're calling. The account is the subset of transaction accounts or should we pass? This? Proof of history uses these four. The timing, the execution of the programs. There is no collisions. The data is a byte array of the data to perform actions. Here we have an example of the Solana Hello World program is a clear, clean coal. In TypeScript, we have an instruction. We have here the data that we sent to a solid my clusters to the API, to the blockchain. We need to say that the program will deserialize the information. And then we said a less again to the response. We have an await send unconfirmed transaction. Here we are passing a public key. Signer is false, right? W is true because we are changing the counter of the helloworld, the number of times the proton has been called on chain Solana contain called. Here we have the roast is my contract that receives the parameter entry 0 implementation, program entry point implementation that has a public key. The program that is loaded to the account to say hello world to. The parameters will be taken from solar Nick Hello World example on GitHub. Programs, as we said, can be writing in Ross and C plus plus and C recommended roast for security, performance. Multithreading. The apps. The apps is in next generation of apps. And instead of interacting with the centralized database on a server, you interact with the blockchain and anyone can call the programs both. If they know how to use the smart contracts both. Sometimes you need some signer. Only downer can the signing of the ulna is needed. The program can be executed. If you deploy a Selena program. Beautiful lives forever in the blockchain. Coke can use smart contracts or programs. Anyone know how to communicate with programs by submitting transactions with the instructions, needs to have the signatures. The foundation needs to know how to use negation RPC API to communicate with the blockchain and also learn how to create the smart contracts. Both are important. Finally, let's see an example. You have a video game and your backend. You send the request using a signal to the client that is paying a bit of a base station or in a PC, there is a call-to-action and he can sign with the back-end to receive an NFT. You need a signature of the honor, that indicator of the video game the client is paying on the PC. Finally, if the client accepts to pay that fee for the NFT, now you can communicate the client directly to the RPC API. And we both signatures. The user can receive the NFT that has a lot of value. An example of an implementation. 4. Create And Deploy First Smart Contract: Let's create a basic Solana proton, but it's only console logging. And we're going to invoke this program with that CLI on TypeScript. You can use a web browser if you do video application. The first step, we spoke cargo, new library, main, basic. We open the Visual Studio. I recommend you install the extension for. You can go to programs. You can search for nickel preferences. Extension. You can search for us. It will be very handy for cold competition. To source. I believe this boilerplate code. Let's move first category to get the dependencies. We will need to learn a program. Great type library. We category dominance. We wait until the category. Want to fast-forward. The abilities finish. Now let's go to our program. Okay, so let's write the program we're going to use from Salina program. That is a great, We want to use a counting for. We're going to use the entry point for these are requirements for Rodin. The entry point. That is where we write the program. Also the message, or we can cause a low in the environment in the cluster. The public key for aware. Now let's create an entry point processing instruction. We neglect the function not processing instruction. We pass first parameter of the program. Reference to the public account. That is an array full day counselor? Correct. We can maybe some accounts we can say Balkans weekend console. Hitting the counting for we pass in the account is right the whole weekend if you sold it for reading. Finally, the instruction buffer. Finally, we write the program. Let me see. Where is my contract? Bronze. For example, we can, finally at the end we say the program, we're going to program. Ivy, number of accounts. But we are passing distortion data. We first get proton number of accounts. Accounts link because Santa way of accounts. Finally, data. Now, Let's create a cylinder. We can deploy with a new medium. We write lambda nu. With the force. We enter a bit 39, passphrase. See we have the capital to get the key. We get there based on what private copy we get. So lemme. Okay, so here is our keeper that we're reaching for the terminal. We copy, we replicate. Now we can get this lemma balanced. And 0 of our gallstone keeper asked for r. We get some envelope and then we can view the mitochondria. We can deploy to the bed nets. We can see our determinant that our current RPC URN. Definitely. If we wanted to change, we need to write lambda config set with the flat URL paste. We can change domain it. If you are willing for both. We are using DevNet. So this is how you set the URL on the BPF program. Opposed to fast-forward. Awesome, We have our contract and rebuild to white group. We can deploy. We need to copy these lines. Be deployed the program. Okay, great, so the program is employed. We have Programme ID. So now let's build the client. We can interact with the smart contract by invoking are telling the program. 5. Call a Solana Smart Contract from a Client: Okay, so great, we can deploy our program. Now let's see it again so we can get, okay, so now let's create the client. Work anything I did it three CLI moving to the left, three MPA minute. The package managers, so we can style the web trip learner. We put everything as default. We MPM. When installing bulges. And I will fast-forward. We move to the CLI folder and we create the new file that is going to invoke the program. We already styling MPM styling so we can room with a terminal, we can bloom at absolute file. I'm going to fast-forward. Perfect. Now let's start working the program. First we import everything from. Then we create a connection with a constant equals new cluster API. We are in bed. You can change to mainly Beta function. We're going to call the program, would get first a constant. For the private key. From here you put private key so we can get it by lambda series. This one venture with anyone because next case, well next we're going to create the assignment. Went to sign the transaction. The soul, the proton can be called signer. Keep their secret key. With the key. The program. That is aware. Programme going to call our permanently. Perfect. Now let's clean it up. And I section, section equals new class action. Now, we can use it to add instructional methods. Section can have multiple instructions. So for example, here, we have a new tree. In section instruction, we pass keys. Which accounts are we passing? An empty array? No accounts. We also passing doctrine fields. Programmer, you are also passing data. We're passing buffer of empty data. We are located 0. Here. We can wait. Perfect. Finally, we are waiting for the confirmation. Okay, so we have three confirmed transsexual connection section. It could be multiple signers. Then the booming signal to our console logging. Finally, we are calling the main function. Now. We can run with MDX index. Also. You want to create some logs. You can do that by using these Solana. We take the URL, definite. We are opening a WebSocket. We are waiting. We have a signal. Let's run again. You can see that workshop and open up late. You can see this is a transaction 44 management. The periods of the parameter. We pass it 0 counts or gifts. And the instruction is an empty array. You will see that 44 sigma2, 44. Perfect. You have created your first as smart contract. You have with an off-chain client. Now let's pass. Some data. Lives forever in the blockchain and we can see the lights and this year, thank create powerful, it's matter contexts. 6. Create Smart Contract, Send Data to Smart Contract in Solana: Okay, so welcome. We are building as a client and that contract that receives data from a client. Let's create ML library. Let's create mechanical project. Let's send nato program. Now. Let's open. Yes, I notice. Now we need to install the dependencies we are using lambda program. Also follow the library. Great type library. Perfect. Now we can build terminal. Perfect, So build was done successfully. Now let's go to the source folder. Go to run a program called Les, delete this boilerplate code. Unless you start by using this Helena program library or great. We are using the accounting for object for the accounts we are passing. In this case, we are passing an empty array because we only want to pass some data, some number. We are also using entry point. Also for entry point where using the progress would to write all the code that performs the operations in the smart contract. We're also using the message for console logging, using the public key for actually passing the product ID. That's the only thing we're using in this program. We close. Now let us define the entry point. We're calling function processing structure. But we actually process the instructions. Convert the data from byte decoded data. We define the function processing instruction. We pass as arguments program AD. There is an object from public key, reference to the public key. Then we pass the account as an array of account info objects. Finally, my institution data is going to be our reference to an array in the year of eight bit. Then we write the program result. That is all the code that will perform the contract. Closing angle brackets. We first declare. We're also finding a lead with the key, the remanent. Asa. Backdoor. These two data we want to split. First. We're going to play also on. Then to get the value that we're passing, we're declaring a variable value of type on signing 64-bits. We use the remanent. Remanent. We are getting from 0 to non-inclusive the eight elements of the array. Then we are performing an slice. There's light into actually map this data, map it to a 64 integer from Little Endian. We're up, or if they were up, was successful. We set default. Perfect. Nounlist message. These are console log. The value. Unfortunately. Perfect We have arrived with, I'm finishing up the call for the smart contract. We have passed some data and we have the coded from Little Indians. Use 64 bits integer. Now it's time to deploy the program and create the client that can invokes. This is my contract. So we get the directory for the CLI for the client would change to the client directory. And we npm, we need the package manager. We set everything as default. We go, we npm install the dependencies. We're using lambda work three AS we wait until one of us forward. Perfect. Now, let's install also. For d is no script. No. Perfect. Now let's npm install the big number. There are script library for encoding and decoding. Cep be numbered OJS. Now let's create our index dot ds, our TypeScript file that will communicate an invoke, the program grid, the connection to the cluster. I'm actually in bulk and send some data. Perfect. Now first, let's import our Solana library. Next lesson. Require constant, the big number Library. Require. Next. Let's create the connection as a constant using the connection class. Brushing the Cluster API URL. Definite, but you can also use minute if you are in production code. Great. Let's not create the machine function. Main. I want to write all the code. First, let's define the key. Monkey is doing a caret. Create the UN, iterate from our private key is an array of integers. How do we get our private key? Lambda nu? We can create a new, a new key pair. We need to force. This is a way you can get a keeper. You enter a phosphorous. You get the root for your key pair. In this case, we already created one previously and it's already in the comfy get. Git config, config, get. We can get all the defaults. We get our deeper and we get a copy to get the actual array of integers. This is area of integers. We copy and paste it on the key rate of eight bit integers. Assignor, we play through a web trick deeper. I worked three, keep her from secret key. We pass. Next, we are defining the movie. So to get the parameters, we need to actually deploy program. We need to go back. Let's define these parameters as Web three dot public-key. Public-key. We pass a string, string as constructor, hash it proton from the stream. So we need to go back. We check our balance. We have some so lemme epsilon that you request them later. The rope with Nana, the number of Solana you want your indefinite. We know WACC and we will BPF. We now have the problem ID string. Now. We have the public key for the parameter. Now let's create the data we're going to send. With a constant data. Uses a type buffer. We offer from. We use the uint8. Off big number. Let's pause for example, in number three, we are using the Indians. Perfect. Now let's create a transaction. Transaction. The new section. So what section has multiple instructions? We're only passing what instruction to these transaction. That is to invoke the program sending the data. We have the transaction instruction. Instruction only contains the accounts. We are passing the accounts that can be credit or debited. In this case, we are only sending an empty array of the object of transaction, require the account name of keys and we pass an empty array, then we need the programmability. Finally, the data as a buffer. We're passing, we're passing these eight array. Finally, let's create an await because it can more than 1 second, a couple of seconds. We use a Web three sending confirmed transaction. Here is when we ask for the wallet. Or in this case we already have the assignment because you just in TypeScript with no browser. We now react. Here, we need to pass it connection the transaction and the array of signers can be more than one signer. So you can debit more than one signer or private key and public key pair standing point. Then we're going to console log the signal to get this arrow function. We say they're all function we want to console log. Perfect. Now let's call the main function. Now in the terminal web socket so we can see the logs of the programs. So we need the problem ID. Lana logs programmatically. With a URL flag. Definite. We get our socket so we can read all the console log from the roast smart contracts deployed on chain. Now we call the client with MPI X d is null, and our file. Here we have two terminals. The WebSocket that will print all the smart contract in the main terminal. I'm on the terminal abuse code. We are printing the sigma two. As you can see. It can take a little seconds because Q we've seen a tool and we have the number value three parts, it's always great. This will also appear in the, as you see if I see also their local terminal. Great. Now let's run again. Websocket can close because it only open for less than a minute. You can run again, there was a bit as you can see, we received the number three on the transaction. Running. Again. As you can see, we have the value 321 and we write the code, and we also have the signature tool 44, and also in our local permanent 44 new sheet. So everything is perfect. 7. Serialize and Deserialize, Save Data on Account with Solana Program: In this tutorial, we wanted to learn how to serialize and de-serialize data. So CUTLAS means to create a byte stream. We can send it. Then we receive the byte stream, we deserialize and we process, we make changes in the object. And then we utilize again to save that information on a Solana program. We are using Birch board allows us to, for example, we have a JSON object and we can see the allies it in JavaScript client then emerge in our smart contract. We can deserialize into a struct. We can use all the data, make the changes. Then we can see again and save it on the smart contract. Using Birch board stands for binary object representation, CDL license for hashing yourself in security critical projects that 30 cases, consistency, safety and speed. So we certainly great ally of Solana because it is focused on security and speed. And as we say, safety and consistency. What is serializing and deserializing? Civilization is a mechanism of converting an object into a byte stream. For this, we use our buffer. We have an object converted into, for example, an array. In the ears of eight bits. Personalisation is a process of converting the byte stream into a regulated object that was not a united by the byte stream. Let us start. Okay, so the first step, we want to create the category, the category with the flat library. Then we open a studio. You open the folder. The first step will be to install dependencies. First, the category, the rules dependencies. And also we're creating the terminal client directory CLA. In the Gadigal. We are using for these purples, this program, the rational, you can get the latest one. Now we're using 1.11.2. Then we are also using Bosch directions. 0.91. For library, library. We save it. We run category. These are the dependencies we need for creating the smart contract. Insulin. I will fast-forward because it will take awhile. Okay, perfect. So we created a folder for the client to come in to a CLI. For the recreate, we npm, we need to create the package JSON, everything as default. You want to enter. Here as you can see, package Jason. We need to create dependencies we're using for this project. This one? Yes. This is to communicate with the Asian or PCA API. We can send transactions, we can query that data in an account. We also need Ferroni. We're creating a TypeScript. The version four is going to be then they're reducing types, null. Morning running TypeScript. Reducing the length is one. Whereas washing buffer. For these six. We are also using this. We'll learn that buffer layout. With this, we are going to help in the client side to create the buffer and serialized data. Truthful the weekend, send a sub byte code. For this purpose solution 3. Similarly, whereas using more, let's use the latest one. Also for me TypeScript, we're using. The latest one to board is for serializing and deserializing data. These boards in the client-side, in the TypeScript, you can use direct application. Any, any application that uses TypeScript can be a web browser, can be only a server. Finally, we need to build these npm packages, so we run npm install. These are going to stall or the older client dependencies for TypeScript. I will fast-forward because it will take awhile. We begin by importing dependencies we're using. We're using the board. And the board. What else? We're using the lamina program. We are using the account info. We're using next account, account info. Also using from Solana program, the entry point. From the entry point. Proton. We are also using the message for console logging in the long chain salon a cluster. And we're using the program. Whereas using program, you're seeing coma. And these these are the dependencies we are using. Now, the next step, east door, define the type of Estate story when accounts. We're going to write the notation. This is known as traits. So we can inherit some of the functionality. You will see at the end of this goal that we are going to use, this area lies. In this case, we are right. We are creating as public. We are calling new account. We are only having one member. Account they're of type 32. Perfect. Now let's create the entry point for the program processing instruction function. Now let's create public function processing instruction parameters. We are using here. Reference to the type. We are passing the MLF accounts, reference to another array of account info. Finally, we are passing production data. But it's a reference to an array of integers of 8-bits. Perfect. We save it. At the end. We need to create the programs root. We write all our code, and at the end we used photon. Okay? We're going to write here. The first step is to get the account. So we can read the rate of the account started. Remember, accounts can hold balance. Bumpkins and Beta. Violence is known as Solana balance or you can hold a token, an NFT for example. Let's write the parameter suit. The first step is to create an ether. Net. Accounts equals reference, reference to the accounts, but do get the first account. Your account. Then equals to count account. We save. We need to return a promise. If you want to get the second account. If you come, you're passing multiple accounts, you can have a count to write these both. Moment, we only have one account. Passing. The next step, we have the account. Now, let us start decode the instruction we have passed. We first work. You can see here in these two, we have working with this with accounts. Now let's process the institution data. We can console log the code. Let's start calling. The first step. We can create a variable, can call it data, receive it. That we are receiving an encoding, a CDL. I said data from older client. We need to first DCD elevation. We've received with estimating account the CDR lines. By running these metal from the instruction data. We map. This is to shun data, and we handle the error. We write the message if there is a narrow, wide, for example, only. Actually. Finally, we write the program invalid instruction and data. Now, we use bromine. Now, if this doesn't read through my narrow, we can console log object that he's not. Everything is fine here. Now, let's run a security check. We have already worked with the data. And with the accounts. We get the account. At the end of the program, we're going to use it. And now let's work with the proton. Maybe. Let's run a security check because you download of the account. Most also on the product ID. So only you can modify the data. Imagine that you put this publicly and anyone can modify the data. It will not be secure for your project. Running here, security check. Before we write anything, we need to write the security checks. If the account owner, He's not equal to the program. We're going to return the program, finished. My contract. We don't narrow. It will be approved on metal type in quadratic form. Okay. Perfect. If everything is okay. If you are the owner, you send the account and the account that Cal this smart contract is also the owner of the contract. Now let's increment this total number of times. By adding the first CELAC, the account data. Usually we have the CDL license, the data, receive it. Well now we need to deserialize with these same methods, both the account data. Let us do that. Let's briefly account. We also use these metal that I, farmers slaves. We use the count, the reference to the account. Question mark. Everything is perfect. Perfect. We need to increase the counter here we have deserialize the data. Now, we use this account. We will pull the equivalent value that the receiver household. We want to change the counter. The counter. We're going to add the receiver. Count we are adding. Finally, we need to see delays. We say, we need to change these two mutable. We can change. Finally, we need to see their lives. Again, debate that we write here. Account delays. We can use this, you realize, because we're using plates as you see here, we're using the circulating account. Both were using the inheriting these traits from bondage. Because as you know, gross is not an object-oriented programming, but it uses traits to do these type of things with annotations. Script, this will recollect protocols. For example, we see the lice and we use this goal, the account. Moral. Perfect. Finally, we can such a console log. We can write those. We pass the written account. Great. So they might contract for TBL AC and BC TLAs in data. Now ready, we need to deploy this contract. So we go to the terminal. We have an issue with them, landmark Gloucester with the DevNet. We are deploying to the test net that is operational now because a lot of people is calling in Solana with great. There's a lot of developers. Munoz. We go back to our terminal and we need to change them. To change, you grow Solana, conflict with the flag URL, and you set the test. Now you are you are communicating with the RPC, doesn't it? You check you so Lana, balance, intestinal, you can ask for some we have some Solana, you can Solana drop one for example. We have one. Finally, we run the category view BPF to compile the program. We can upload it to them. Deployed to the Gloucester. Gloucester. Perfect. So to deploy copies, we want to get I'm going to want to get a product. We're going to check the parameter V on a block explorer it. Finally, you copy your parameter. You will explore a docile and that blue block explorer. You need to change them. Isn't it? Doesn't it? Little bit slow because there is a lot of people making programs right now in Solana and all the world. You can see that you wrote here lemme, lemme. You can see there's a lot of people also ended up someone on these web socket based parameter. Here you can see the address of the program. The violence is executable. The weight of this beautiful there is account also the account owner they have for sole. Going to see 4.1. Now that we have deployed our program, we want to work on the client side. We move to the client folder. Now let's create the client. So we create the folder for the CLI for the client. We went to create here a new file, index book pipes group. We have the file. We want to copy. The first thing is to import the dependencies. We're using board. We're also importing web three from Solana. Whereas importing buffer layer terms dilemma. We also are 14 buffer. Better effect. Now, let's define their public key account where we are going to be a web. Dot leaky. Perfect. Now let's create a class that will store the state of dayGreeting account. We create the glass, rename it. Count. What we're going to cover count there, that is going to be initialize it as 0. Constructor with the fields AS counter. Number equals two. Fields are fields. Then we set these counter. Perfect. Now let's define the schema that it use it for serialization and deserialization. So let's put here, we write as chemo. Chemo equals to new, locating them up. Here. Reading account plus. Using the kind is we're using with the fields counter. Signing 32. We close this. Perfect. Now let's get the greeting size. Where you see the CLAs. Clas makes compatible. These objects, both in JavaScript and engrossed, in this case with TypeScript. So we use, we want to get the size of these CLAS, an object map because we want to send some Solana. We don't buy, we don't pay rent, and we stay forever in the destination cluster. We write const equals to c delays. Daygreeting schema. We create a new plus a new instance of the class of beating account Perfect comma. Then we get the length. With these programming. With this utilization, we can get negative thing size. We can get later, we pass the size so we can calculate the number of Lamport's we need to be rent exempt. The next thing is going to create a connection. So let's create a connection. As I say, we are using, there, isn't it? Because of evidence is not working right now. Gone. Connection, a new connection. Book cluster. The test not because divinities not working right now. A lot of people are parameters always great. Tom it. Next week we can assume function. We will create an async function main. Here. We're going to create that equal to from. And we need here, we're getting the key. So we need our array of eight bit integer. So to get that d mu, you need to write the force flag. Works for Lana. With the force plan. I already have one, so I will do Solana. Here I have my key pair, that is Apache CLI. Cli. You can get that will get me to get these numbers, these copy. Then the next step is to create a buffer. So we're going to use that buffer layout. This is all an app dependency, getaways alumna so we can interact and we can use JavaScript to create a buffered, create the byte code and send that bytecode to us all and asthma contract. And we can de-serialize data and then perform the operations and DTLS again to save it. So we're creating a layout equal to what buffer layout. The type, struct. More full. Assignment 32. They're perfect. So now let's let data. Buffer. We are, with the buffer. We are allocating the layout. Perfect. Finally, we will delay delays. Or in cold, they're counted. We can say, for example, a value three. Data. Perfect. Now we have our buffer. Now let's create the assignor because we need an account, these key needs to create a signer that is a keeper. We can pay for the transaction cost for the price of invoking the program and creating the account to store the data. Let's be a designer. So we write, let's call it signer. From the type three dot, keep bare. Bare. Now, we're getting from secret key, public key. Now we have the center. Now let's create a polychaete with a permanently we have the parameter at the top. Here. That constant program. The type, Web three dot, create a new key. The program maybe. Perfect. So now we have a public key. The permanently. Now, the first time we call the program, we need to create a saved. To create the first thing we create them account we're creating. So you can put anything. What it must be unique. For the elite detour of security of the salon. Caching topic. We create the account with the seed. We pass the signer public key, this IV, that it can be any text. Texts on the program with the next step is to declare, let this equal to 0, then get the lamppost to get the rent exception. Right? Lump board equals to wait. We use a connection. Minimum balance exception. We pass Greek king size. Perfect. Perfect. Next, let's create the transaction. We are passing two instructions. The first instruction to create these account and transfer the Lamp ports, so it lives forever in the second transaction, we will use it to invoke the program. So let's get grade the first, the first transaction. So first let's define the transaction. So let's create a section. Let's call it transaction. For this project, we are creating a new web three dot. Perfect. We agreed that transaction. Now less consumption. We're using a web system program. Because the system problem is the one who created the account. Creates the account with cheap. Pass an object from poorly key is the assignment. For base fully key. The public key. Then this IEP meetings. Perfect. Then new account key. Then the Lamp ports to be random sample space size. Finally, the program maybe plus a comma closes. **** here. We close here. First transaction, the system program is creating an account, sending some Lamp ports to the account. The account is rent XM and can live forever in the blockchain. Now we need to create another transaction. Okay, so now let's add a second instruction to a transaction. To a simpler section. The section can have multiple instructions. If one instruction fails, all the transaction will fail and will revert to the previous state. So let's transection dot app called New with three doc transaction structure. Now let's pause first four keys. Here we pass the account. In this case we are passing. For public key. We need to pass an object. For the public good. We're past the account. Key, signer. This account is not signer and ease work right through because we are we are saving that. Perfect. Okay, So the next in the object e is the product. Maybe. The last debate. Perfect. We call our second instruction. We're saying these data buddies, these buffer with a counter. We are saying the number three in the counter. So everything we run this, we call this function will counter in the onchange, swollen neck cluster. Finally, let's, let's awake and confirm transaction. With past that connection. The transaction, the array of signers, signers can be multiple signers. In this case only one. Then dot. Then we pass the signal to cause a look. Reasonable. Finally, let's work a new function here. Report the greetings. House1, a sinc function. First we use a constant, we get the accounting for. So we are requesting from the blockchain the account. We are reading the number of Greetings, the number in the smart contract in the account that this might contract rights on the data, we await for our connection. Using it the accounting for these specific account list. Using their greeting schema, account, the account data. Finally, we are console logging. Coma, coma. We use a number, greeting, counter, coma, coma. Close this report. So we run this code. Let's run mpm. T is index. We can now also bone-mass lemma. We need the chromosome. We have preliminary chocolates. Let's call it this. We need to handle this bijection. To put here if account info equal to gamma. Great to have some errors so we can debug and you can learn. Because we need to not error, but we need to run the main function. At the end, we run the main function. Let's open up this open, I will so good, because you are here. We're opening a web socket to here, to the logs in the chain. We have the number three, right? Maybe I open the WebSocket late. So if you want to run this code again, recommended, you can change. See you that count what the best way is to comment this because we are not creating an account already called the account. Also we have here where account instead of BB King and getting with cheap. Recommend these lines. And we create this poorly key equals new three. Fully key. We pass here. For example, list up four instead of three. So now I want to have seven. Also here. Let's connect to a server socket. Healing Visual Studio or the logs off the off-chain here of the client. And on the terminal, we are creating a socket here to unlocks the Unchained on the cluster. So they have different logs. We said double side debugging is great. We must have saving seven times grid because we are adding the number we pass is added to the previous seven times. Maybe the workshop, it does not working. Let's try again. Check if we are in the current. Okay, so now let's start for example, seven to 14. Okay, finally, there is a trick. If you don't get the logs, The unchecked, you can here to all the logs, then you can copy the old, the old texts and you can check, for example, we can start writing that. You write only Solana looks URL and you pass this. We run the program. You need to copy all the, all the, all these because sometimes I don't know why it doesn't here to one specific product. But here you will see it. It will work where we're copying all the text, searching for our program. We wait until it's at 2121, so we copy all common. When we copy, we can open a new paste all the text to Control a Control T or Command a viewer in my control sheet. You paste all the logs. There are a lot of logs. That is why it's not working. You search for your for your product, maybe the logs. Because there's a lot of people, I know there's a lot of bootcamp painting in the world. Here is the logs deleting counter seven. As you see it. This is great. We have right to the ultimate contract, same data by serializing and deserializing and healing for the logs, both online and off chain. So wonderful. You are one step closer to your goal.