Bitcoin btc Price Today, Value, Real-Time Charts News - Forbes Historical Price Information Time period. High. Low 7 days. $31,009.00. $27,882.00 30 days. $31,009.00. $25,161.27 1 year. $41,498.12. $15,742.44 5 years. How to create NFTs with JavaScript - LogRocket Blog Learn to code an NFT non-fungible token using the Ethereum blockchain, the Ropsten Testnet, and a series of JavaScript libraries. chainlink cons Introduction to Anchor Solana development
hey hey what is up everyone we should now be live okay can everyone hear me okay hey hey hows it going welcome welcome well give some people a couple minutes to join the stream and then well get started hows everyone doing today lets get some gms in the chat awesome im excited to give this talk hope everyones having a a great and productive changing hackathon really excited to see what everyone builds all right well give it one more minute uh everyone and then were going to get started yes it is a great day to learn chaining yeah were going to be going for about an hour today do we start directly from rust um there is going to be some rust involved here today however if youre not too familiar with it um dont fret too much um youll still be able to follow along its its just a matter of the syntax but ill be kind of explaining everything as best i can cool all right i think we might get started welcome everyone i hope everyones having an amazing 2022 spring hackathon today we are going to be talking about all things anchor solana and using chain ink on solana right so im just going to share my screen here hopefully you guys can see that i might switch my view there we go gm so my name is harry pepper chris you and im a developer advocate for changing clubs and today like i said were going to be talking about building on solana how to use uh anchor on solana how to use chain ink on solana so first were going to go through just a quick introduction of what solana is and the architecture and programming model because its quite different from other chains such as ethereum then were going to give you an introduction to what anchor is and how it increases your productivity and then were going to just do a quick demo workshop using anchor to create just a simple program and deploy it and get it working and then were going to do another demo um with anchor and solana that uses chaining price feeds in your solana smart contract and then well wrap things up by talking about where you can learn more so lets go intro to solana so solana is a open source uh public blockchain and um the unit of account is a soul or a fraction of a soul is a lan port right so its about 1500 nodes and theres a number of um real enhancements under the hood to kind of um achieve the the higher tps and bandwidth that it has right so if youre interested in that kind of real low level stuff um i recommend checking out this article that ill paste in the chat here now well move on but celina has multiple clusters so they call a networker cluster right so their mainnet is called mainnet beta um they have a devnet uh which is like a a test network for developers they have a test net which is a another non mainnet network thats mainly for infrastructure type things and deployments and testing things like that and you can run a local cluster or a local solano instance on your local machine which youll be doing today as well right so um celine uses a byzantine fault tolerant proof-of-stake consensus mechanism and this thing called proof of history to maintain its state now the biggest thing i want to talk about before we go into anything else with solana is the programming account model right so in the case of ethereum and other chains the smart contract also holds the state it has the logic which is the code that says do this do that but then it also has the state that says um that stores all the variables the arrays and all those types of things in that same place on solano its different right a program is um essentially just an unchained smart contract that is just code right um it doesnt store anything it just gets executed right um and it has a program id which is basically the address or public key address that the smart contract is deployed to just like ethereum however there is no state stored in that program right so the way solana works is data for programs is actually stored in these things called accounts right and an account is basically just like a buffer but you can kind of think of it as like a file in an operating system right um and so it just has a bunch of data just like a file and has a bunch of metadata as well that says you know who can access the data in here um and its held in validated memory right so the biggest difference to know with solana is you have programs which is just the smart contract code and then you have accounts that store the actual data for smart contracts so um in an erc 20 example or a token example in a theory we have one contract that stores the token details as well as the um the uh balances of each person that holds the token all in that same contract in salon youd have a deploy program which is like a token program that has the token information um or it has all the functions to like send tokens min tokens et cetera and then you have multiple accounts for each person that holds the token right because once again you do not have um the logic stored together with the state in solana so heres basically what an account looks like on solana youve got a public key which is like a just the identifier for the account youve got a bunch of metadata that says um is a signer is it writable um who owns this account um is it an executable is it a smart contract this account or not because smart contracts are also accounts weekly enough um and most importantly its got a data section where it stores a buy array of data so thats how data is stored and its got lan ports which says how much um solana is in that account right and well get into that um very soon so in terms of how you interact with blockchain to call smart contract programs and things like that but part of me um you basically have to generate what are called uh instructions right so you can think of an instruction as like a function call right an instruction basically has three parts to it has a program id what program youre interacting with um its got like an array of accounts that you send it to say here are all the accounts that i want you to interact with um with this program id and its got this um a buy array of instruction data which is like input parameters right so if you have a function that takes in the price for ethereum or something you need to send that in any instruction data section right so thats kind of the three things that an instruction is comprised of and then a transaction is basically just a list of instructions right so you can have first do this function call then do this then do this etc so um heres just a small example here where you have instruction one interacts with you know this program id here so we want to call this program under here we want to um pass in these two accounts to basically have data modified or stored um and these are our input parameters for interacting with this program here and then similarly for instruction two its the same thing but slightly different uh data or slightly different same program id different accounts different instruction data and then we bundle those up into a transaction that contains both of them right um so basically this is very important that you understand this if youre going to be playing around and building on salon because this underpins the whole programming model right you have an on-chain program thats just code no logical state um and you build up these instructions off-chain that you use to interact with the on-chain programs and you submit these instructions via a json rpc api to to the solano um cluster and and then basically they get executed right and you also pass in all the accounts to the program that you want to have data um modified for right and any instruction data you pass it in the instruction data by array so very different you cant just call a function and pass in a string or an input parameter and then its just everythings in that function um once again its very different you say you have a program id which is just the logic the accounts get passed in so that program id knows which uh where to basically modify data um and then it takes in input parameters in the form of that instruction data by array so once again the instruction data is just a buy array of an arbitrary size thats used for sending input data to on-chain programs right so theres just an example of some instruction data i think its like a string of like a glass tube or something like that um so lets talk about the flow of uh developing and interacting with programs just quickly again so you compile the programs you can build solana programs in rust clc plus plus you compile them they get deployed in as bytecode 2 solana and then to interact with them you have an adjacent rpc api thats exposed and then you build your clients which could be a front-end or web app or whatever and then they can submit via that json rpc api um to to basically call programs on the solana network um yeah just to reiterate the um the the program itself is stateless it doesnt store anything so when we call programs we need to pass in accounts to what to say here use this account for doing um the first thing that youre going to do with accounts then this account for the second and and so on so lets just talk quickly about rent now um so solanas similar to a theorem and other chains where um you basically validators get paid transaction fees and things like that um however because we have these things called accounts that store data um we also have this thing called rent because validators need to get paid to store this data as well right so basically storage room basically covers the cost of storing data in accounts over time and theres two methods that are used for this with this one called set and forget and theres one called paper buy it so set and forget is basically where if you have two years worth of sold in the account um you never have to pay rent again so you just have to prepay like a large amount otherwise if you dont have two years worth you can pay per bite and in terms of how much is two years worth it depends on how much how big is the account how much data is in there and theres also a cell amount per kilobyte which uh is set somewhere um ill grab it from the solana docks and paste it when we get to our first exercise generally most people go with option one they just put two years worth of rent in an account and then that way they just dont ever have to pay rent again however you have to be careful with that because if you add more data to your account over time um you need to make sure that two years worth is still true because the more the bigger the account is um the more that two years worth of rent is going to be so you need to be careful about that too seeing a couple questions in the chat companies select versions of solidity in solana um yeah so you cant program with solidity in solana in solana you can only use uh with native celina anyway you can only use rust c or c plus plus there are some projects that are dealing with trying to get evm compatibility going with solana however i havent played around with them yet um and yet and arsenal programs are mutable like ethereum uh great question um just to reiterate from earlier um the solana programs do not store any data theyre just the logic right so in terms of the smart contract getting deployed and the logic yes its immutable that can never be changed but theres no data in in that smart contract right its just the logic all right lets move on um so just you know a quick recap on instructions uh that we send to the solana network you have a program id a list of accounts and data instruction data that the client sends through as an instruction right um however if you need to send some input parameter to a celina program you need to lets say its a string you cant just send it as a string like you do in ethereum um you need to basically serialize it into a buy array because once again the um instruction data that we send is in by array form so if you need to send the string harry as an input parameter program you basically need to turn it into a byte array right so thats what serialization is converting an object in memory into a stream of bias and then when that buy array gets accepted onto the in the solana program um via via the program to basically do stuff with it you dont need to deserialize it you need to turn it back into a string right so its a bit finicky salama in raw salan anyway where you need to basically serialize and deserialize this instruction data um if you want to use it on chain however when we get to anchor soon youll see that um you can that kind of stuff kind of gets attracted away so um just a quick visualization here so examples of serializing and deserializing um you may want to youll be serializing instruction data sent from a client via the json rpc api onto a celina program where its then deserialized and turned back into its original form or it could even be the other way around you could be serializing account info data thats going to be stored in the accounts via the program as well um but enough about that lets lets start talking about anchor so in the web 2 world you have things like rails uh right um and in ethereum world you have things like hard hat truffle and web3 js and basically these are all tools designed to increase your productivity right and they do that by abstracting away some of the more low-level details of the underlying platform so in solana we have this thing called anchor that basically does that for you right so anchor is a framework built by project serum um which is a decentralized exchange exchange and d5 ecosystem built on solana um and anchor basically is a framework for quickly building secure solana programs right and it basically does this by reducing uh coding efforts um and and by generating various boilerplate code for you so im just going to paste a link to the anchor docs in the chat before i continue for those that want to read more so anker basically uses a number of tools so once can we we build smart contracts in this workshop were going to build them in rust um it generates these files called idl files interface description language files which is very similar to an abi file um in the ethereum world if youre coming from a solidity point of view and were going to go through that in a minute and then you generate your clients or off chain kind of programs use using you know javascript or typescript etc and anchor has its own cli for interacting with programs and deploying them and things like that as well so in terms of how the workflow of anchor works right first we have our smart contracts which in this case were going to write in rust and then with those smart contracts you know we build them which basically compiles the program into byte code just as if just like if were not using anchor um however also with anchor it generates this idl file as well that says how to interact with the program and from that idea we can then generate clients and with the clients we can then talk to our program and then test them and things like that so an anchor program basically consists of three parts so its just a rust program with with like some little hooks and macros added to it which youll see in a minute right so we have a a program module that defines you know this is all the logic in the program and we have these things called accounts structs which is where all the accounts that are passed in are validated um and we have this thing called a declare id macro that stores the address of the program thats been deployed right so the actual program that um youre in we actually store the address of the the public key address of it in there um so that when the solana accounts get validated and stuff it knows who owns them and things like that um so heres just a basic example of an anchor program basically so all the bits in red are the anchor hooks or macros that are added in right so this is basically saying this program is located at this address here this is the public key address this little program macro basically says this is where all the logic of the program is so in this case we have a module called hello anchor and we have a function called initialize um and then in the account struct here we basically define a struct called initialize right so these are like the the anchor hooks or macros that you basically put into your program and well go through them in more detail right now so in terms of these accounts macros here basically this is where you define which accounts your instructional function call expects and and what constraints these accounts should follow right so uh in this example here we have um this set data function here and this with anchor programs you always have this thing called a context thats passed in and and you need to define in the context what the cons context is right so were saying the context for this function call is set data basically what that means is its going to look down here in the account structs and look for one called set data so it says okay when this function call gets called the accounts that were expecting to be passed in are going to be specified here in this set data struct here so in this case were saying were expecting one mutable account so mutable means it can be modified and were expecting one account to be passed in called my account and its of a type my account which hasnt been defined yet oh no sorry my account is here um so thats basically saying this is the account the work data were expecting and were also expecting uh unsigned integer 64-bit parameter here um and yeah over here in that account definition were saying were expecting this one account called my account its of type this so then in your account little macro here you can then define what this is you say public strike my account this is just a struct that has one um unsigned into just 64-bit uh called data right so thats how we can kind of combine the logic um the account that defines um what kind of how the data is stored and stuff and then the accounts that defines um what accounts we expect to be passed in within this context here um so the program module as i said before is where the business logic is defined um you can then call them from from off chain clients and things like that so theyre just kind of like where your functions go and as i said before each define endpoint takes a context type as an argument that provides access to the accounts of the executing program and the program id that we specified up here yeah so in this example here weve got this uh weve got this set data function that we define here and like i said earlier we where we in the context were saying were looking for a set data thing down here in this section here thats going to define what kind of accounts youre expecting and where and it can take one um input parameter here as well so just like earlier i said you need to serialize and deserialize when using solana when you use anchor you can actually take in input parameters directly on the function definitions just like i have here so that abstracts away all of that serializing and deserializing for you so thats one of the cool things about anchor yeah and the instruction data can be added by adding arguments to the function after the context argument um and anchor will automatically deserialize the instruction data so as i said earlier um you dont need to serialize things into bioarrays pass them in and then deserialize them back with anchor you can literally just pass in you know integers strings etc on your pro um function definitions here and then just deal with them directly and and anchor will automatically do all of the serializing and deserializing required um so the idl file is generated very similar to the uh abr file in um the solidity world and its basically used by clients to be able to interact with the deployed anchor programs right so it just defines you know what are all the function definitions what kind of um accounts are they expecting what kind of arguments are they expecting and things like that so heres just a simple example of one here cool lets do a quick demo now so um what well do is well just build a single simple anchor program that just takes in a string parameter like a name and and it can just basically say gm to that name right so you know something very simple so the first thing im going to do is bring out my vs code here um here we go so ive got my console here um what were going to do the first thing were going to do is were going to go so ive got anchor installed and um ive sent you guys the link to the docs there its got all the um info on how to install anchor so i got version .0242 installed so the first thing were going to do is were going to use the cli and go anchor a net m anchor its going to initialize a new project for us with some boilerplate code right and then were going to just build upon that that project give that a minute to complete um in this example im going to be deploying things and using things on a local anchor uh cluster so im going to start a local um anchor validator and were going to do everything locally also as you can see weve got a whole bunch of stuff thats been generated including some boilerplate rustcode here and yeah we can get going now so we have a function called initialize here that takes in that has a context of initialize here um and it just returns nothing right so the first thing that were going to do is were going to change this to execute and context as execute change that to execute as well and in this case were going to take a string parameter in name string um and then what are we going to do so we want to take the string thats passed in and just you know store it in an account thats passed in maybe right so were going to say let gm account equals mutable context accounts count right so what does this mean this is basically taking in um looking in this execute context for something called gm account right now but theres nothing in here yet so lets define that next so what we want to do is we want to specify uh using our anchor tags one account that were expecting to be passed in maybe a new account thats initialized um the person whos going to pay for that initialization of the account is going to be the person generating this transaction and the initial space were going to allocate for the account is eight plus 32 bytes so theres always like an eight-bit discriminator at the beginning um and then were just going to say were going to install 32 bytes worth of data that should be enough for a name so once weve specified this little um anchor hook here we can then define the account so pub gm account its of type account and beta that were going to be storing use of type greeting account oops and next were going to be expecting another account passed in which is the account thats um signing the transaction um and thats going to be the were going to call it user and theyre going to be whos signing the transaction i think thats syntax there um and then one more thing when you create accounts which is whats going to happen here you need to pass in the solana system program so we need to basically specify that to the system program is the 18 program into the protocol that does a whole bunch of protocol type things such as creating accounts and things like that this is all pretty standard boilerplate anchor type things theres nothing thats very different yet so once thats defined um the next thing we need to do is define what is this data look like that were storing this gm account so were going to have our account okay kind of hook here were going to create a struct called greeting account and were going to store a name here cool i think that is okay for now account info greeting account accounts lets see whats wrong here execute info there we go so basically were taking in um when this function gets called uh were saying from the context here um get this account here thats the create this account here which stores data using this kind of structure here um and then once weve done that all we want to do is say gm account dot name equals name which basically says grab this name thats passed in here and store it in this newly created account which is of this type psa store in this part here right and we might as well print it out to the program logs why not and then well end now are there anything else ah my anchor directory here so theres my anchor project were on anchor build start compiling my program now now this um program id here that i talked about before anchors a bit weird in that you you need to kind of specify the program id that youre gonna that gets deployed right um however you dont know what the program id is going to be until you actually build it for the first time because it generates it randomly so this is kind of double building thing that you just have to do in anchor for the time being until they find a solution so you need to then you need to build it and then you need to extract the generated program id which is stored in the idl file i think and then you can then paste that generated program id in here and then you actually need to build it again because youve changed the source code and once youve built it once it will reuse the same program id as long as you dont blow away your target folder here which contains all the metadata um so that you need to kind of build it get the program id paste it in there and then build it twice so its a bit weird like that so um to extract the address im going to run selena address from selena cli and we can kind of get it here im going to paste it in there and im going do anchor build one more time and it should be quicker this time cool now before we deploy im going to tell solana that im going to be using my local validator so solana config set and then in another terminal session im going to go to lana test to spin up my local solana instance and once thats running uh were nearly ready to go so first were going to generate a new wallet address using the solana qli its a line of cli sorry so im going to call it um id.json password so as you can see ive got an id dot json here um the first thing i want to do is just air drop some solano tokens to it so with salon you dont need to go to a faucet um you can use the airdrop program if youre on a test net um however theres no airdrop program for mainnet for obvious reasons and id.json lets try that oh we got to sell on our account um i think were ready to deploy now to deploy to our local cluster lets give it a shot um actually one more thing so anchor were gonna we need to specify an environment variable actually i think thats for the client lets try hit deploy to deploy it and we specified earlier that were working with a local cluster and its deployed and as you can see the program id here matches the one over there right so now that weve deployed it the next step is to kind of get a client going so just quickly though when using a client uh in this case were going to generate such a javascript script to run to simulate a front-end you need to export um this anchor wallet environment variable for because were going to be using the anco javascript library it uses it to know what wallet should be used to kind of generate transactions so in this case we want to specify the id.json public key or wallet that we generated here um so were going to basically say set that environment variable to that were doing double dots because im going to create my client file in this app folder here cool so lets go to the app folder and lets create a new file called client.js im going to open here now in the anchor in the anchor docs um there is a simple example that ive pasted in the chat um and i see theres a bunch of questions ill get to them at the end of this exercise um so were going to basically go to that minimal example and were going to start with the boilerplate code thats there right so im going to paste it in here um so basically the first thing it does is it grabs the generated idl file right because it needs it to interact with that deploy program were going to get our deployed program id which was this one here and were going to paste it in here to say this is the program id we want to interact with and basically all the anchorworkprepackage does is it gets connection to that deployed program using the idl and the program id and then you can go program.rpc.functionname right um so the first thing were going to do is go anchor equals require serum anchor use the anchor web3 library for javascript and provider is a way to get a connection to work in that case its the local network so were going to call that provider um and then were going to have everything in a main function right and then um all were going to do is call our main function and then just say done cool so we dont need that no we do need that lets fix the syntax issue here so lets see what in our uh program so in our case our idl generated idl file is um is going to be called audiel gm anchor dot json so were going to change this to gm anchor right and what were going to do next is we have a connection to our program id here so um we need to basically generate a new um account address to pass in as that account that we want to initialize so were going to say m account equals anchor.web3.keypair all right so its going to generate a new uh account address for us and now that under here and um now were ready to interact with our program so were going to say uh let transaction equals await program dot ipc dot execute because execute was our function name here and it takes in a string parameter here the context you dont need to specify um so were going to say and then were going to pass in a name oh we need to set the name actually so lets go um const name equals harry were going to part in a name and we also need to specify the accounts so accounts that we want to pass in the gm account is the gm account that we specified just further up um the user the person thats signing for the transaction is our id.json one that we generated just before which he gets from the provider because we set that environment variable and then finally the system program so system program anchor dot web3 file like this there we go um and then once we pass in the accounts i think you dont need to do this but im just going to say our starting point for for this instruction call is on all um confirmed transactions right and signers whos signing this transaction we also want to include the gm account um that we created just so that um it knows that we have access to that to basically store stuff in that okay so that should be it for that lets see ive got a name here we go uh accounts means a colon cool so once weve called that function call um then we basically um thats going to store that uh name in the account that were passing so we basically just need to double check that its been stored so we go hunts store name equals awaits program.accounts.greeting account dot fetch so were basically calling this um in our deployed uh program were saying get the greeting account which is this here dot fetch and we want to get the name right um so gm account dot public key and then were just going to go console.log store name dot name all right so its going to basically just for this gm account that we created here and passed into our call its going to basically look up the account data and fetch the green account dot name value okay i think thats it um so one other thing we just need to do quickly is set the anchor provider url so um when working off chain uh in these javascript libraries or typescript or whatever um anchor doesnt anchor needs to know uh you cant access the anchor cli to know that were working with a local host so we just need to specify it um using this environment variable here so im just going to set it to my local host and then were going to see up up were already in app sorry um so im just going to run node client.js to run it and we have an error lets see where were going uh we need to go back one extra folder because were in the context of the app folder here and lets see what the next issue is um value arguments system program not defined think its program.program id oh how are you done so um you did a console it basically with our name here it basically called this execute function it passed in this gm account to get initialized and we passed in the the string harry so the program executed it took the harry parameter it took the account that was passed in and created as a new account to store this type of data in it and it basically just stored the um it set the name here to the name that was passed in here and then off chain once the program completed all we did is just read the data from the account right so just a very simple example of using anchor how were doing for time weve got 15 minutes do you need to install do you need do you need curl to install rust and salina cli i think you can download pre-built binaries depending on what system you have a great question um but definitely check out the the celina docks which ill paste in the chat here and the um anchor docs which i pasted already i think but yeah great question now um i see a few other questions ill try to get to them at the end but for now i just want to go on to the the chaining stuff um because we are running uh a bit over time so lets go back to the presentation cool so now lets talk about changing price feeds so um chaining price feeds are live on the slanted devnet for anyone to use they will be available on mainnet for anyone to use very soon um but for now theyre live on devnet so if you want high quality uh accurate price data um celina price sorry chaining price feeds is the way to go so if you go to docs.chain.link theres a solana tab at the top here and and all the info about our price feeds is here so we have i think a few on devnet right now btc eath link soul and a couple stable coins um so if you need any uh if you need price data for your chaining hackathon submission and you want to build on solana uh this is where you go to basically to do that right and um what were going to do next is um we have a yeah were going to go straight into a demo so if you go to our github repository ill um in the chat once again we have this thing called a solana starter kit right so if you need to build something on solana that uses price feeds this is the one place to go so its pinned to our repo here selana starter kit and it is a pre-packaged repository that contains an anchor example program that uses chaining price feeds so you can just use it to kind of work out how to do it you can use it as a starting point for your project um you can use it um to just you know see how to do it basically so what were going to do is were just going to run this starter kit and ill just kind of walk everyone through it and then hopefully ill have time to answer some questions so im in my group folder here so were going to get clone im going to paste the url of the starter kit here and as you can see i have a whole bunch of stuff here now so salona cool so the first thing you want to do is just install all the npm stuff that needs to get installed while thats going ill ill basically walk everyone through everything so here is the the deploy program uh it uses anchor just like we we saw um not too much in here um we have a declared id we have we define the way in which were storing the price data here so this example program just literally takes in a price feed account uh address such as you know your sole usd account and basically looks up the latest price and then stores that data in another account thats passed in so theres a function for just formatting price data um and the thing to note here is were using the chaining solana anchor library uh channing salana library here sorry and then using that library we can call functions such as latest round data you know description is that soul usd link usd et cetera and decimals how many decimal places is there in the whats the precision of the price feed data so we can basically call those functions and all that its doing is its basically just calling those functions and its just setting the latest round data for a price feed into a variable and its basically storing it into an account thats passed in right so weve passed were taking in a new account to store the price data in this boilerplate code were taking the specified chaining feed which we grab from here on devnet theyre just accounts were taking the deploy chaining program so theres one deployed chaining program on devnet that has all the functions and everything that defines how to interact with price feeds so its a static value um and were passing the system program because were initializing accounts here so thats the um program lets see if we can get this built now so firstly im just gonna once again generate a new id.json wallet now the difference is this time were going to be dealing with devnet the public devnet network instead of the our local validator and as you can see im doing an airdrop here uh im doing it twice actually uh to our id.json generated wallet address and im specifying the uh devnet rpc endpoint here api dot devnet.cellana.com so im just going to kill my local validator here because we dont need it anymore um so were going to air drop ourselves some soul and then were going to try build the anchor program so while thats building ill go through the the client so we have a client called client.js here we actually have two clients we have client.js and readdata.ts so client.js is very similar to the example that we just went through um in our first workshop um in this case where we have the stored program id thats just a static value of the chaining program on on devnet uh we have a price feed specified here which i think is the sole usd thing is that w6 yep um but you can pass in another um feed address on the command line when youre on the script if you want and all its doing is its getting a connection to our deployed celina program um its generating a new account just like we did before and then its calling the execute function like we did before passing in all the account information so passing in the the new um account that we that were creating uh our id.json wallet address for signing the transaction paying for it the chaining price feed uh which were getting from here that we want to get the latest price for the chain program um is this one here that static value and then the system program because were going to be generating new new counts so once thats done weve built it once once again we need to run the we need to extract the the generated id for this program we need to go back to our anchor program and put it in the declare id section up and then do that build one more time to build it with that in place and once thats done we should be able to deploy to devnet so we say anchor deploy provider.cluster equals devnet here so that might on devnet it usually takes um a little bit of time maybe a minute or so uh hopefully not um so what ill do is uh ill go through the rest of the client so once we call that program uh it will basically store the latest price for the feed that we specify in that account and then were just printing out the the contents of the logs here and it looks like the end point is down that is not good using a free public um endpoint here so lets try to do that again um and once we uh once we have called that function um once again were just reading the value of that account that we passed in um to get that latest price information so very similar to our last um example that we ran now we also have this read data script as well that you can use so if youre building an app that you just want to use price feed data in your front end if youre building a cfl application or something um you dont need to generate transactions on solana if you want to read price data you dont need to pay sol and lan ports and things like that you can just read the price for data off chain as well and thats exactly what this read data script does is right we specify a chaining feed address and a program id and we basically just we get a connection to that uh deployed feed and it basically just looks at the logs for that feed and it just basically keeps printing the latest price so you can do this off chain in your web app or whatever it is you dont need to pay sold land ports or generate any transactions and you can use it just to read the price data off chain so thats what this read data script does as well so um hopefully we can deploy to devnet um ill just give it a minute to complete ill have a look at some questions while were waiting this anchor kind of like docker but for rust ankles kind of like more of like a hard hat sort of for for solano id say than the docker um yeah will the default celina ross template run with cargo run i think so i think it does yeah can we access system program idl files the system program thats baked into solana i dont know if its got an ideal file because i dont know if it was built using anchor can a program access data created by another in your account great question so you specify in when you specify your um accounts here you can specify uh you can specify who owns them and things like that um and in this case were saying um whoever pays for owns it so you need to basically have access to the account to be able to access it on chain right um so because this programs doing it here uh the program has access to it right however once again its just by data stored um so if you know the address of an account that you want to access from off chain and you know the structure of that data because you know the source code or something of the program that uses it you can theoretically off change it to read the by array and then like deserialize it into something meaningful um so theres nothing stopping anyone from doing that but yeah great question cool so thats deployed now uh the next thing we want to try and do is run the the client now so um so im just following the steps here in our solana starter kit repo which uh ill paste here again in case anyone hasnt seen it um so once again we need to set some environment variables so were saying the anchor provider url is the the local devnet rpc endpoint and the wallet that we want to generate uh account that we want to generate transactions with is our id.json that we created so once thats done we should be able to run our client script so um in this case we would say node climb.js uh the program were passing in dynamically using the chain link um cli but its essentially just going to return this program id here and the feed that were passing in is i think its the the eth usd feed so were going to see what the latest price for ethereum is so we run that client cool there we go so we see a bunch of um program log data um ethersd price there and then price is thats our client.js here um just reading the account info from off chain um and then basically just stripping out the value so so there you go we deployed a selana program that basically looked up price data on a chaining price feed the latest price for ethereum and then stored it in a passed in account right and then you can do stuff with that data in your hackathon submission so the last thing i want to show everyone is the read data script so once again its a great use case if youre building something where you just need high quality price data off chain and its actually really really easy to run really easy to run so you dont need to change the program id you just basically say what is the feed address you want to look up data for right in this case we have an eth usd as well and you basically just run npm run read data to just run the script and itll basically go in it will read the price data from the uh account it will look at the events generated and it will basically just um keep printing out the the latest price as it gets stored right so i think the um around time is set to one second or a couple seconds or something like that um so as you can see theres the price of ethereum and it basically just keeps printing it out so you can just use this as a means to kind of know how to do it and then you can basically just incorporate this into your off chain web app or front end or whatever it is youre building well so thats it really as you can see quite easy to use price feeds on solana theres a perfect boilerplate project to show you exactly how its done and then you can just use this as a starting point or just as a reference point to using your own submission so ill get to a couple more questions in a minute i just want to talk about where you can learn more about celina and chaining quickly so uh where you can learn more um a really good place to go is the salina cookbook i cant recommend this site enough and im going to paste all of these in the chat so its a really good developer resource its got tutorials and guides for doing all kinds of things on salina and its very popular with with salina developers so i highly recommend i check that out if youre interested another place is sol deaf this is like a content aggregator for solana so whenever people build published tutorials or blog posts or guides on how to do things um they usually end up in this install dev here so you can search for things really easily once again really great resource so the solana labs have a solana developers page as well with a bunch of more resources videos uh content uh starting how-to guides et cetera so i definitely recommend checking that out as well uh anchor anchors got this thing called the anchor book which is awesome um so if youre using anchor definitely recommend checking this out its got a reference information on how anchor works its got example projects like tic-tac-toe projects and stuff so you can follow along and just you know see how everything works uh we discussed the solana starter kit i pasted it in the chat earlier so thats our pre-packaged boilerplate repo for interacting with solana programs and um yeah docs so you go to docs.chain.link click on solana and its got information on how to use data feeds and and the reference information for the data feeds on our devnet and and soon to be mainnet as well cool um we are time so i just want to say thanks everyone for tuning in i will answer a couple questions now um but yeah really excited to see what everyone builds uh if you are building something for the hackathon on solana um awesome really happy to see cant wait to see how you use our price feeds um and i think yeah there might be some really interesting projects so once again thank you if you have any questions or issues hit us up in our disc in our discord um or if you have solana specific errors or issues um definitely recommend checking out the uh solana discord which is uh here as well and asking questions there theyre very active there as well but thank you for tuning in and looking forward to see what everyone builds i will spend a couple minutes just checking out a couple more questions here why there isnt why isnt there a bigger market blockchain cyber security im not sure um can we select versions of solidity and solana yeah so once again i dont think you can use solution yet however i do know that there are some people trying to bring evm compatibility to solana and but i havent played around with a um myself do you recommend us learning rust yes if youre gonna if youre if you want to spend time building on solana uh rust is definitely the way to go i think personally um its not hugely hard if youve if you know any other programming language you can pick up rust fairly easily um theres not a huge amount of rust used on solana as well its just like a subset of rust kind of like the basics um so yeah if you want to get in the salina ecosystem um getting up to speed on rust is the way to go and theres this thing called the rust book rust book which is a good online language uh reference that ill paste in the chat um however if you want to hide something a hard copy let me see if i got it here this is what i have this is what ive been using here ill see if i can throw it up here programming rust um this is a really great resource um for for learning rust so probably the first six or seven chapters is applicable for solana so i can highly recommend that one as well does celina have prizes in the hackathon um im not 100 sure i dont know if there is yet however um you can build on any chain with chaining and be applicable for any of the major prizes so if youre building a d5 um you can um build it on solana you can build on violent smart chain you can put it on ethereum and and youre still um applicable for you know the the main prices because as long as you use chain link in some way um so you can build on solana for the hackathon uh you can definitely get prizes with it im not sure if solana has a um has a sponsor prize at this stage though what is anchor so just yeah definitely watch the replay of this um workshop but anchor is basically a um a library for making building celina smart contracts a lot more pain-free definitely um okay but definitely over time here so i think im gonna end the stream but once again thanks to everyone for tuning in and really look forward to seeing what everyone builds um sorry just one more thing i want to plug my boot camp i forgot uh if you want to build more um if you want to learn more about solana if you go to chain.link uh forward slash boot camp we do have a celina bootcamp that we recently ran ill paste it in the chat uh you can sign up and do this boot camp on demand so it goes for about eight hours so you learn all about solana um and current building um selana programs and stuff like that um you can just do it by watching the pre-recorded sessions and i think its about five exercises so um if you want to get more into solana definitely recommend checking that out as well but for now i will stop sharing um and cool all right thank you everyone um yeah really looking forward to seeing what everyone builds and yes the bootcamp is free its its 100 free In this video, youll learn the basics of Anchor, a key framework for developers building on the Solana blockchain. Make sure you check out the Solana Starter Kit, a repo with boilerplate code to get your own project started: Chainlink is the industry standard for building, accessing, and selling oracle services needed to power hybrid smart contracts on any blockchain. Chainlink oracle networks provide smart contracts with a way to reliably connect to any external API and leverage secure off-chain computations for enabling feature-rich applications. Chainlink currently secures tens of billions of dollars across DeFi, insurance, gaming, and other major industries, and offers global enterprises and leading data providers a universal gateway to all blockchains. Learn more about Chainlink: Website: Docs: Twitter: Chainlink Anchor Solana Solana,Chainlink,Anchor,
cineberisso.com.ar