Solana Developer Bootcamp 2024 - Learn Blockchain and Full Stack Web3 Development - Projects 1-9 - Ep44

[java] Time: 2025-07-11 11:42:18 Source: AIHackNode Author: web3 Click: 122 times
we'resimply going to get our list of accountstogether um and ai tutorial for beginnersthen send thattransactionoff program methods. makeoffer um with our options the accountswe want and our signer is Aliceafterwards we're going to check thebalance of the Vault and we're going tocheck the offer account has the datathat we expect second test is prettysimple it it's program methods. takeoffer confirms the transaction um andchecks Bob's accounts after uh runningthe testum uh also we could add a test to makesure that the vault is closed I don'tthink we are here but I'll add I can addone in a moment um you'll also note Irun do slow um and then uh I have avariable set to I think it's 60 secondsum because anchor tests connect to ourlocal validator uh by default uh anchorshows them as slow because mochaactually shows them as slow because theytake anything that takes more than Ithink uhhalf of 30 seconds is shown as slow soif I set my slow threshold to 60 secondsanything that takes half of 60 secondsum will uh be shown as slow our testsonly take 15 seconds so they won't beshown as slow um you didn't really haveto worry about that too much it's just ame thing I hate my tests being shown asslow I like to establish a um bit of abaseline for how long a test should takeso yeah pretty simple we just have uhone describ block and a test that goesand checks make offer and another checktest that checks take offer if we runthose and you can import them into yourownprogram you can get them from our thelink that we will add to this uh to thispresentation you can actually call yourtake offer and make offer and check thatthey work as expected give it a sec as Isaid these tests take about I don't knowmaybe 15 16 seconds eachand then we can see the first test isfinished which is puts the to the tokensAlice offers into the Vault when Alicemakes an offer and in a moment oursecond test should hopefully finish aswell there we go uh puts the tokens fromThe Vault into Bob's accounts and givesAlice Bob's tokens when Bob takes theoffer so this program is a great exampleof the benefits of defi Alice had someof one token and wanted another tokenshe didn't know Bob Bob at some point inthe future came along took that o offerthat Alice made exchanged his tokens forAlice'stokens and each side got 100% of whatthe other person was offering withoutanyone in between taking a portion ofanything um also the other useful thingabout this program is that it shows youhow to uh handle tokens in your ownprogram to how to hold tokens and how tosign to transfer those tokens out ofplaces where um they're stored usingcpis um so I'll see you in the nextlesson imagine a company that wants toreward its employees with tokensensuring they remain motivated andcommitted to the projects this processis known as token vesting token vestingis a mechanism used by cryptocurrencyprojects to distribute tokens over timeto certain stakeholders like employeesadvisers or investors instead ofgranting the tokens immediately vestingrestricts access to the tokens over aset schedule this aligns incentives andprevents stakeholders from selling alltheir Holdings at once potentiallydestabilizing the tokens value in theupcoming tutorial we'll write our ownvesting contract our contract will havethe following user experience a companywill be able to come to the daab toinitialize their own vesting contractand specify the mint address and totalsupply of the lock tokens next thecompany will be able to add employeeswith their individual ual vestingdetails which includes the total amountof tokens allocated to the employee thevesting duration and the cliff the cliffis the initial period where no tokens atall can be claimed say the cliff is 6months then for the first 6 months theemployee will have zero unlock tokensafter the cliff expires unlocking beginsaccording to the monthly scheduleemployees can also use this D app toview the status of their vested tokensand claim any unlocked tokens thisproject enables transparent automatedvesting on salana companies can setcustomized vesting schedules for any SPLtokens and employees can clearly tracktheir vesting progress so in summarytoken vesting aligns incentives forprojects Distributing tokens over timeour smart contract brings to cureonchain token vesting to salana by theend of this tutorial we'll accomplishwriting the smart contract code runningtest creating a front end and connectingthe smart contract to the front endcreating a fully functioningdecentralized application let's getstartedall right so let's create the vesting Dapp we're going to be using the MPXcreate Salon D app scaffold because itconnects both a front end and a back endin one workspace and makes it a loteasier when you're making a fulldecentralized application so let's getstarted by setting up the scaffold we'regoing to navigate to our terminal andjust type in npx create salana D appand now we're going to enter the projectname we'll do tokenvesting we'll select the preset fornextjs tailwind and then the anchorcounter program and this is creating anew workspace with npm so it's going totake a second to load we'll wait foreverything to generate and then we'regoing to open this workspace in vs codeand getstarted okay so this creates a newfolder inside the directory that you ranthe command so we're just going to CDinto thatfolder and then we're going to open nvscode okay and just to get everyonefamiliar with this scaffold how it setsup the workspace for you you have yourweb folder that has everything for thefront end of the application and you cansee the app the components and all ofthe needed configurations we're going towork with this later so we're going tostart out with our anchor smart contractso in the anchor folder you can see ithas everything set up for the back endof the application we have our programsand then you go into source and this iswhere the main smart contract lives inyour Li RS now we also have a few otherfolders generated that we're going touse later on in this application butlet's just first start with our lib RSum so you can see this is just a basiccounter that was generated if

(Editor in charge: go)

Related content
Wonderful recommendations
Popular Clicks
Friendly links