Live Coding with Frol - NEAR.AI Agents and Contracts
Nothing is loaded from YouTube until you press play, and then without tracking cookies.
About this video
Live Coding NEAR Smart Contracts in Python โ One Trillion Agents Hackathon
๐ฅ In this special live coding session, we explore how to write, deploy, and interact with NEAR smart contracts using Python!
๐ฅ What Youโll Learn: โ๏ธ How to write a NEAR smart contract in Python (yes, Python!) โ๏ธ How to create an AI agent that interacts with the blockchain โ๏ธ How to verify developer participation using DevPost API scraping โ๏ธ How to fund wallets with a NEAR faucet contract โ๏ธ How to use NEAR SDKs & tools like neari & near-py โ๏ธ Debugging and troubleshooting smart contract calls live
๐ ๏ธ Technologies Used: โข NEAR Protocol (Blockchain & Smart Contracts) โข Python & NEAR-Py SDK โข NEAR.AI Agents โข Live API Scraping & Data Validation
๐ฏ About This Project: We built a Python-based AI agent that verifies One Trillion Agents Hackathon participants and funds them with NEAR tokens. The agent: 1๏ธโฃ Checks if a user has registered for the hackathon 2๏ธโฃ Verifies if they have added NEAR AI skills to their profile 3๏ธโฃ Calls a faucet smart contract to send them NEAR tokens
๐ Resources & Links: ๐ One Trillion Agents Hackathon: onetrillionagents.com ๐ NEAR AI Agents Docs: docs.near.org ๐ฆ NEAR-Py Python SDK: github.com/near/near-py ๐ฌ NEAR Developer Chat: near.chat ๐ฆ Follow NEAR DevHub on X (Twitter): @NEARDevHub
๐ก Got questions? Drop them in the comments or join the NEAR Dev communities!
๐ฅ Like & Subscribe for more live coding sessions and Web3 tutorials! ๐
#NEARProtocol #Python #SmartContracts #AI #Blockchain #Web3 #NearAI #Hackathon
Transcript
9,367 wordsCaptions as YouTube publishes them, usually machine-generated, so product and people names can be misheard.
- 0:21
hello hello welcome to this live episode it is great to not hold on I have a here so it was uh long time since the last time we've uh we've had these episodes on Fridays uh today is not Friday but we have the episode I really wanted to um to share it all with you as soon as possible given the tide schedule for the hackathon that is already happening uh one trillion agent hackathon um I think
- 1:01
deadline is end of this month and there is also East Denver a lot of other events happening uh around the clock so um yeah I I couldn't wait and I also wanted to so today uh we will be talking about neari near smart contracts and we will do it all in Python um so it will be live coding session and I'm encouraging you to ask any questions in the live stream uh that you are hopefully watching and uh
- 1:49
we yeah hopefully we'll cover a lot of uh small Niche topics for developers so if you are developing you know python that is perfect you don't know python you will learn python I'm pretty sure uh I've been doing some courses for students in Python back in 2014 and most of the folks figured it out in during the first 20 minutes so python is not the requirement if you are not familiar with it just yet
- 2:26
um so let's see um let's see this set up this set up questions where is the question section wait what the orange thing yeah I have to I have to confess today I'm not going to use rust and that is why my uh rust crab is helping me today to um to watch and um be a bit jealous about how easy things could be done in Python but I have to make the um ex exceptions when I want to be quick
- 3:13
at prototyping so let me start and find and try to share share the screen let's see yeah I hope rest will not uh you know ban me after this live stream so we'll start today with neari and specifically with the research Hub um where should we start though so let's start uh with actually drawing some um drawing something that will help us to understand where we are heading and what we want to achieve today count
- 4:18
on um so I want us to have so yeah as as I mentioned we have the one trillion agents haathon happening today and the one of the common questions I see in the chats that people not necessarily are familiar with near and they not necessarily have wallets and I want them to be able to experiment with near Tech 100% And do not bother with um going uh to test net and trying to stop things in the harder way I strongly
- 5:15
believe that fees on year are so low that you shouldn't really care when you interact with the apps about the cost of the fees uh but you still need to get some near to to be able to interact with uh with the blockchain you don't need the near to to stop a new account on neari you don't need near to um deploy your agent but you still need um near tokens uh for if if you want to build some
- 5:53
blockchain integration right so I came up with this idea of uh let's build the uh near agent that will serve the qu uh basically uh asking if the user is developer uh are you developing on one TR learn agents hack prove it and uh the agent will verify the proof we'll talk about it in a bit and then we will um if okay then we will call the the faucet account which holds some near tokens uh from near AI
- 7:00
from near from the agent and uh the smart contract will um basically well we also need to collect the the wallet what is your near wallet account ID or near account ID yeah and the contract will send let's say five near to the wallet that's it so the this part will be um neari agent in Python and this part will be uh near protocol contuct in python as
- 8:05
well yeah uh let me check the stream cool I think that's reasonable and what do we have uh so where should we start where should we start we should we should discuss this verify the proof how do we prove so the proof was fairly simple uh I believe we should go to the one three agents Dev post uh let's log in or let's not log in first let's check all the participants oh I need to log in first to see you
- 9:05
this is my profile and we have dams users okay and by the way I haven't prepared anything here so I will figure out as we go so what we have we currently have 1700 participants registered in the Pakistan um we cannot so how how do we prove that they are hacking on here so I don't know how to prove that but how I think what we can do is to freeze this uh list of participants somehow and uh then if you're coming from
- 9:56
the um to the agent and your profile is um on the list then we can send the tokens so let's let's uh let's write it down um if the provided profile is in the list of Agents haathon that's one of the requirements but but um look that's not enough because I can I can provide the profile or someone else and send my wallet not good so we need some something else and I think we can leverage the
- 10:45
skills this is something that I actually think thought through so I think using the skills is something that we can um rely on that people do not have at this point in time so the users would need to add add uh neari skill uh to their profile and that would basically mean that they are going through this process once they add it to the skill then they will be able to talk to they will go to the agent and claim uh is in the
- 11:19
profile okay um sounds reasonable so let's do that so let's um oh let let's let's first think how we can pull the list of uh participants though list of participants does Dev post have API okay it's uh infinite loader let's maybe that would be faster um loading participants participants page four
- 12:20
um wow so it actually sends me um HTML the pre-formatted HTML instead of Jason okay can we copy URL and uh and check what's going to happen if we just request it so now plug
- 13:25
in so actually I think that it's it does block me from hold on how did that happen yeah it's actually blocks me from watching the uh specific page without authentication without the um cookies um but well what else what else um not really okay let's uh let's copy that scl I will make sure I use the set the cookies externally so I'm not sharing my account live
- 14:33
one second I'm doing it off screen okay ready
- 15:37
I do read the comments sometimes uh so if uh it would be great if uh Joe or someone wants to join the the call and uh help me with the just talking through the questions thanks Jo so there's a few questions here some of them are not quite exactly what you're doing but we can kind of talk through some of them uh one of the questions came up was you know in your planning is there a
- 16:27
way to perhaps have the agent create the wallet ahead of time and prefunding can do now agent create a wallet and prund it agent can do anything on chain actually it's a it uses the Pioneer package and it can uh um it can interact with any external service through API through um request response uh to RPC it can prepare transaction so only the only thing that you need is the access key um
- 17:04
for the account so I will be um providing the access key from the faucet account as a secret to the agent and that will be used for funding oh I hope that answers the question so there some Technic questions and I'm going to refer people over to I'll share in the chat to some of the support channels for more specific support people have that as well we we we'll put that on the screen
- 17:55
here so where is the um maybe I missed the question so participants where is this this this doesn't make sense um um
- 19:06
where is the name where is the name interests achievements followers full St over here we go okay user profile link uh username let's see how many of these on the page more than necessary let check this way 20 yeah I believe that is about right so we can use this now grab by this thing out of page four cool so what's left is to
- 20:10
um yeah another question that came up as you're going to about the access Keys um will the access key you're using only have permission to call a smart contract function on the faucet account yes so it will be a limited access key only doing this one thing that will be allowed to do yeah a bit of uh so we have uh 1,700 so 18 that should be enough two done and we save it to we actually don't need to save it into individual individual pages I think
- 21:09
that should be it oops so okay we are getting the list of all discip this way and we'll grab through um grab through it while it does that let's go and build the um the agent the agent here we go so access research Hub uh where should we start let's start this research Hub sign in so I'm already signed in here um but I still need to walk you through so we do sign in we fork or and
- 22:04
deploy and we build with near I usually go to view dos uh I go to agents and I follow the quick start so near I I already installed it locally uh there is a takeaway the minimum supported version seems to be 3.10 or something thing uh but also the currently 3 12 or 3.13 doesn't is not supported so this is the very safe way to to go with 3.11 if if anything actually actually no uh I remember the trick I have on on on
- 22:48
Mac I I I have 3.9 right yes and the trick is to actually go and install a newer version of pip first so you install pip and then you install near then it uh does the dependency resolution correctly I already did near AI login uh I already did all of this um but I yeah we we're creating new agent so uh new agent create that's what I'm looking for then to this tab so maybe actually I can walk you through how to do this stab
- 23:34
so what I did Python 3 minus M the N I do not install packages globally I prefer clean vual environments so activate I pip install and upgrade pip that's what I just told you uh and and then I do CP install CO neari version It's V amazing so let's go agent create uh agent name one
- 24:35
trillion um agents um fund me um if your Dev come to me for near tokens um provide your um Dev post profile link yes nice so it created the um agent in this folder in this uh hidden folder. neari I don't like it that way to be honest uh that's why I usually move it so let's go to um experiments I will do MV this one
- 25:37
into want agents fundme want agents fund me and the the folder is pretty simple here so fairly simple setup one function run it will receive environment uh and that environment has uh some handy functions it also has uh a method to get the list of messages and it has ADD reply and also request user input um so all a bunch of useful things it does the some initial setup for agent to be able to interact with the AI
- 26:30
model we don't necessarily need that um but uh let's see let's see uh provide your the post link uh and then yeah and in metadata we only have like version naming so nothing that we need actually right now let's start with even simpler thing Let's ignore anything that user says and just uh response with respond with something uh and check that it actually works so neari agent upload Dot
- 27:29
Avil commands uh registry upad hold on registry upload current folder okay it's there let's check let's check it out uh what is this uh that's a dog but I need uh near Hub Hub one trillion agents fund me Source cool run test
- 28:31
yeah well feels like Ai No AI I mean technically I I VI neari Hub is this um serverless infrastructure for chat Bots and it's very handy very easy to set up as you just saw um I just needed to put the code there uh specifically handling the user input nothing else and uh it just works um so let's um what else uh let's say uh we want to check the last message uh last message it should be here in uh
- 29:19
last get last message um let's do the pink Pond here uh you said message uh yeah actually it's in content there and we format the stream um each time I update the code and want to publish it I go this way there is also local version let's also check that out so we not not need to upload every single version to the um to there but I really love the UI so hey hey T okay hey T so my expectation you said he T nice very nice chatbot
- 30:18
um not necessarily an agent not necessarily A handy one though well talks to me that's already good uh um so how's the status with our previous hack um hold on I lost the window I lost the window not this one here we go okay uh let's check pages doesn't seem like there were any errors so let's check grab and uh
- 31:19
count not necessarily everyone is on the list uh did I miss the first page where did I start they start with page zero uh or page one page one is there page zero um a Zer uh let's check okay okay page zero okay so we had
- 32:21
175 right what's on the on here 1730 H well some of you may have not be on the list but I will figure out it off the screen to find the missing couple of people overall looks good to me so okay let's uh let's get back to to the agent so the idea was to
- 33:30
need this one so the the user will talk to us okay that's part is kind of done we checked that it's possible uh if the user is on the list of Agents okay we will sort it out soon and we need to check the neari as a skill and if okay call a faet account from agent um okay so let's I I'm pretty confident that I will be able to check the um the profile page uh using requests uh but I'm not really confident that I will be able to call a contract
- 34:17
um so let's set up a new account uh like a faucet account will be n do set near and it uh it will go with uh um 20 agent fund f in here and we need the the private access key uh to be able to call something and we will do faucet account call on the same account and we will do um fund and we will pass the
- 35:18
arguments account ID uh always only f for we'll figure out how to parse the message and extract the actually let's account ID uh Target account ID Target account ID it's going to be my account for now the fun okay seems so far reasonable to me so any call to the every interaction with the bot will trigger will create will set up the account connection and they will will make a function call to the uh onchain
- 36:12
contract uh maybe not that fast maybe let's have at least some protection so let's say if uh um last message text and if last message text is uh fund me only uh if it's not then return okay and also what I like to do I usually uh rra it all in try except exception is eror and a call add reply oops something went wrong with the error message otherwise it's very hard to debug it this way and I will see it in the chat that
- 37:10
something in this python code was not okay um okay private access key account we don't have the account we don't have the private access ke let's go and create one so near account so it's near CI to create a new account on near blockchain uh find myself uh my uh what's new account ID new account ID should be this uh I want to check if it doesn't exist yet yes um it doesn't nice I love to deploy something
- 38:02
like let's give it 10 year from the go um save it to keychain yes um save it it's main net yes uh hold on oh yeah and I will be finding it myself correct uh sign whis chain amazing so the counted there let's check cool yeah our fresh account so it's a sub account of mine just for testing anyway and and what we also need we also need the access key we I don't want to send the full access key of this account
- 39:05
to the agent so what I will do I'll go to account add key uh get a function called access key um it's not going to actually use that much of a for the fees um the account that it can call the contract it will be calling is itself um which functions will it be allowed to call um fund that's the one that we will use here and uh yes we want to generate a new key pair and I want it to be stored I will store it in the in the
- 40:06
keychain yeah I'm thinking how to not to leak it to this audience right now so uh let's see uh I will sign this kchain as well and uh send so I just send the transaction um that is adding the new access key that was autogenerated on this here in this setup and now that access key can only call the fun uh function on this on on itself so let's check it out so view list keys of one the agent fun main net
- 40:47
now yes so this access key can only do uh fun function calls on this contract and it it's allowed to spend 025 near on fees okay that's nice and uh let's go ahead and uh uh set up the secret so and and and then execute the the the the bot so to add Secrets I use this uh button it is a bit confusing uh that's something that I want to call out uh today I hope the team will be addressing it very soon it's already in the discussion that if you are the owner
- 41:38
of the agent then the like any secret that you put here will be accessible by the agent uh even if the users interacting other user other users are interacting with it so so in other words in this case this is what I intend to to make I want the access key that I will put right now in the in the bot I want it to be available to anyone who is interacting with my bot but sometimes I want to just check and maybe set the secrets for
- 42:22
myself um so that is a bit uh unfortunate that there is no way to do that except by creating a separate account on on the near Hub and then interact with it and then the secrets would put here with the with the edit will be local to only your user but in this case that's what something that I want to do private access key and I want to put the value here but I don't want you to see the value so I
- 42:54
will uh move it to a different screen for for a moment and I will do near account export account you don't see it uh but that's um so the secret is here and if I if I upload the bot upload the bot save it check it once again yes so right now there is no contract there but we will see that it will attempt to to to make the call and will still it will be still recorded on chain which is
- 43:56
totally fine for us so uh we go back and upload it oh we need to change the metadata to version three you can rewatch The Stream on YouTube Twitter twitch it will be recorded uh and available immediately after the call unless I will share some Secrets over the stream um so the it's there and the the bot the bot let me talk to it so I should say fundme fund
- 45:03
me you said fund me okay and I forgot to add any visual indication that actually something has happened h no transaction what's going on here um you said so let's check that we are talking to a newer version of the bottom also and youed Target account private access key yeah by the way you're reading the the secrets from the N bars so it's always like all the environment variables that you put inside
- 46:09
metadata uh environment variables that you configure as a user and secrets are all available through n vars variable and users when they interact with your agent they can override the NS so to be aware off as well um what's going on PL uh so there is a question in the chat uh is that my private key or your from my fr. account no that is the private key that I created for this new account so I created a totally new account I uh
- 46:57
addit a new access key to it uh where is it where is the window um so I created the new account and I put 10 year in it so you can see it here and then I added a new access key that is limited access key limited access key uh that is only permitted to call fun methods on itself and this is the private key that I put inside the agent so that agent cannot transfer tokens it can only initiate transactions on behalf of this account
- 47:38
this new account uh it can only call a single function so it can only sign transactions um that are calling a smart contract on on on this account the the contract is not is not here yet um and it can it can only call the fund method nothing else so that is yeah uh let's check once again Source you said to yeah that's the second ver the latest version so I'm uh fund me you funded okay but that's not
- 48:45
true call Discount fund okay let's let's try to do it from the terminal interesting so near contract call as transaction this account um what's the name of the function fund uh Jason RX account doesn't matter really 100 ter should be fine um zero near attached to the call I'm signing by itself I'm sending to main net and I'm let's sign it also with the keychain it doesn't it shouldn't matter um and
- 49:53
send okay code does not exist that is exact what I was expected to see uh expecting to see okay and that is this is exactly what I was was expecting to see um the record on chain that the attempt was made to to sign it and to to send it what did I do wrong um let me check in let me do exactly the same command but I will sign it with the limited access key that I just put there
- 50:40
I will do it on a different screen sorry guys you shouldn't see it so I'll be signing not with the key chain but with the um with a private key that I will just it it's a public is asking okay um and question of day I want to copy it from here I wouldn't be able to
- 51:43
um it's totally unnecessary actually but um C still asks for it GX signature is not valid what um
- 53:06
I'm fairly confused um f screen for a moment let me know when to pull back yeah thanks so we have um
- 54:21
I copied some different private key somehow maybe that's the problem let's check it okay um can you bring me back to screenshotting amazing thank you Joe um so just uh confirmed that the hold on where is the account account account this transaction was actually signed with the limited access key so I just need to update the uh private key here one sec I think there is some bug in near C IRS exporting the private Keys which is
- 55:24
unfortunate so fund me okay no way let's see at least what it returns um live recording as usual
- 56:50
so there is a question in the chat why my near counts have more than one full access key yeah I was just gonna just gonna bring that up for you because I think the question around Keys has become a Hot Topic in the chat here so might be good to just talk a little about how new keys actually work yeah absolutely so the it's totally normal to have multiple access Keys um it's totally normal to have multiple full access Keys as well the however it
- 57:22
is something to to take a note of because those are the keys that can um basically sign a transaction on behalf of your account to remove itself to transfer any tokens whatnot and the um but the reason why it happens is that whenever you sign in into myor wallet I can't talk about other wallets uh if they follow the same approach approach but when you put the uh seat phrase your recovery phrase into
- 58:02
it it doesn't want to store that private key in the in the storage uh but it needs to store the full access key it needs to have the full access key to your account um so what it does it creates a new it generates a new uh full access key and when you sign in when you recover your account um that is the process that it goes and adds a new access key and when you confirm yes I want to sign in it
- 58:37
uh uses the old the the the seat phrase that you that you put there uh it generates the key keyer from your account hopefully your account and it creates a new transaction to add a new access key and uh that new transaction with the access key is some the access key pair that was generated right in the browser and was stored in the uh local storage yeah I hope that makes sense let's see if this makes
- 59:16
sense um so I upload it I with see result um Source run find me another scam oh nice a wait um there are several ways to do it um so you you you need a a s and then you can either make the run function a sync or you can uh run the specific calls that require a sync uh in the uh this run okay good to know
- 1:00:30
yeah so and what what I love about the live chats and live um screen shares is that we talk and we uncover something that you were like it's it's very hard to find unless you really into it oh now we we see the delay yeah okay transaction result is there it does I don't care about transaction result object I care about yes a few seconds ago the the agent was able to call the fund um methods nice so we are almost there
- 1:01:09
almost there uh so what's left we need the contract we need the contract um where should they put it um fund me let's put it here so we'll create agent folder and move agent by and metadata into agent folder and we will use near Pi tool no I don't have installed here nearby tool this is the Very Fresh very new uh very undocumented um is future python dek for near contracts but I really love it for Rapid prototypes so nearby to
- 1:02:12
new uh contract and now we have the contract contract contract uh we only need a single method uh fund uh we need to parse the user input uh so it's Json loads um the input um so we call it function PRS um or arcs we call them arcs arcs on the sending side let's put them in uh gon gon and um I assume you don't have it so there is a question I assume you don't have it because you create a newn right so yeah
- 1:03:16
I I'm installing the pi like all the python tooling always only in BNS and this one was installed in a different one so I just installed it again um in arcs what we care about is the target account account ID uh and what we want to do is when we know the target account ID we do near uh dot um I need to know the low level API for um promise promise badge transfer this what I need so
- 1:04:12
promise badge create uh to the let's see cross contract call that does promise badge action transfer promise uh hold on near dot um action transfer um to this promise and how much five near we said so five and 10 to the power 24 nice and we need to return the promise uh oh we can't return the promise this is lowlevel API there is no return or parameters there yet and so we have to
- 1:05:09
say promise return right promise create promise return Yes uh near do promise return promise so this will indicate to the runtime that uh the result of my function should be delegated to the basically will be defined by the result of the um promise execution the promise is a transfer so if transfer succeeds then the the transaction will also succeed or like rather the the function that is here will also succeed um we may not add it and then it
- 1:05:50
would mean that the we don't we don't care if the transfer fails the the fund function still would be like would return the success status C but for completeness let's do do um so we par the arguments we have the target account ID uh that's validated if Target account ID is not then just return uh yeah let's return that way return so the just FY so the the current the low level API and how it works in in any language in uh that is
- 1:06:44
integrated with near the functions do not expect any parameters and return and should return nothing so that is the um the low level AP by um convention that is um defined on the vasm level and then nearest the ks for example adds this piece of code at the beginning and translates the return value into near dot uh value return um kind of call uh if if you return the value so in our case we return the promise so we use this instead of return
- 1:07:30
value and these are the host functions that are called and this is how we interact with the host uh environment that near core provides on the near protocol okay uh that is all we don't need this JM near yeah um we don't need the dependencies um five year F we guarded it okay um so contract and nearby to build uh install them script no uh well you can but I don't want to I have uh I use NY and I have it installed I just need to import it and
- 1:08:33
also um you may see another error um well only when you use immutable package managers like um NYX and I will need to set the invironment variable uh so it will fail the compilation now at certain point I believe but I want to walk you through so if you ever see the error like the following oh there is a question in the chat how do I use NYX on Mac so there are plenty of actually uh tools but I use NYX daring
- 1:09:19
project and it has a pretty nice uh setup here and and then and then I use NX n basically with I have an LS this and NS is the Alis I handcrafted okay oh there is a debate about uh well the first of all people recognize that python uh smart contract looks not that bad at all um and I agree um there was a another argument in the comment that uh the people also had High Hopes about GS SDK um I would I I was also on the edge with
- 1:10:18
JavaScript as a backand always actually no GS is something that I shouldn't exist Maybe um but uh hell yes we have bunch of options why not people are playing with it so cach uh this is something that I that I cannot um use as a cach folder so for that I have to uh set em cache and I just point it to TMP folder uh to override the cach folder and then compilation will succeed so contra hold on build contract
- 1:10:59
basm I have this pretty nice uh 400 kiloby B file with micropython and my code buled together ready to be deployed so near uh contract deploy um this new account the file build contract RM no un need call is um is needed and yes signing sending amazing it's there so let's check count oh um we can do near contract inspect um this new account now yes cool yeah exactly the same size as we expected there is one full access key as
- 1:12:00
we know the one that I created with and one function call access key that I just added and there is this one fund method I'll clean this up uh from the output there are not useful uh okay so so we are ready right where is he window so fund me yes yes coming funded is that true let's check it out yes and it did success and uh let's see the execution plan yes so we called the function fund and it actually transfer the tokens to fr.
- 1:13:09
near all the pieces are in place uh we have the list of participants we have uh hold on let's go back we have the list of participants to serve and answer the proof we have the faucet ET and the contract on it and we can call the that that faucet from the agent congrats um overall not that bad uh what it took us uh a little bit over the hour I guess that's fairly good result um and I it's very hard to talk and qu
- 1:13:48
at the same time so my apologies for taking it so long um this was great I think we had some great questions um I think it was great to see the python contract in in in use uh I don't think any most people haven't seen that yet so that was really cool to see too yeah amazing and I um so there's a question about do you know ald door. near no I don't um I think I will be finishing this up today uh I can I can I can do it over the call Joe
- 1:14:32
I guess uh you have other uh ideas how to spend this evening uh so feel free to you know uh focus on something else but for those who want to stay on the call and uh uh follow how I will thread the rest of the pieces together you're welcome to keep going but this is a major son I would say uh showcasing various pieces and um the it's the only thing that is left us to um just polishing for sure and I want to highlight to people who are watching
- 1:15:12
that I mean all of this was done from scratch in about an hour and so it is doable to jump into whether it's a hackathon try something new spend an hour or two and you can have not just a work agent but actually contract all that stuff easily done here um so you don't have to even set aside that much time to really dive into it so I think that was really awesome to see too yep I see more questions coming in the
- 1:15:42
chat um python versus rust uh what would you choose um so I used to be I I used to be a python fan and I I I just I did everything in Python until I'm at rust um the do doing projects in Rust are a bit longer to bootstrap but as as as soon as you you you get your first uh you know first version out of the door um in in pi in Python you you have like endless years ahead of you to fix all the bugs in Rust I just need to grab for unwrap and expect and once I figure out
- 1:16:37
how to properly handle those errors I can totally trust my code uh ever since so I I pick rust um 99% of the time except these live sessions when I have to Showcase other Technologies and uh they are also amazing and also neari um tooling for us is not there yet so that's unfortunate part so I have to use Python yeah I I love the also sentiment in the chat like it's not the question
- 1:17:14
it's indeed it's not it's just yeah it's a choice you live as uh okay keep going so what's uh so we need to then bring these three pieces together uh how will I do it so I need the agent I need to check if uh requests so something that is to be aware of is the dependencies inside agents so you do not Define them they are provided by kind of this environment I I actually didn't dive deep enough to um to find the way how to switch between
- 1:18:08
environments or whether there is even an option right now but the the by Design there there is a way to uh specify which environment you want to run it with in and recently in the chats people were asking uh for some specific dependencies they want to have so that is something to look after I I believe requests is always there because at least like the set near behind the scenes actually uses uh
- 1:18:43
Pioneer uh so Pioneer is definitely there I checked it um and I believe pioneer use requests so requests is uh something that I would expect to see here uh let's uh let's also use some AI capabilities finally right um so need this uh we learned how to do the um I actually do not know I would need to learn more about this request user input I don't understand necessarily um what it does
- 1:19:25
uh why it needs to be called explicitly uh add reply we already know this is a nice way to Shell out back the kind of our print L kind of thing um and the prompt so let's go ahead and use the model to extract some information for us um so I'm not really um an expert in building the chatbots advanced ones with the context and the list of messages in fortunately in our case we don't need to be uh we basically need to treat each message as
- 1:20:20
a separate one and uh um I think we um we basically need to instruct the a model to help us to par the user input and extract the important pieces for us so I would say um The Prompt to the eii should be to uh um analiz the user input and uh uh extract the um Dev post link and the Wallet account um the
- 1:21:25
near near Wallet account ID um uh from it to uh and uh and print and uh um write those down on individual lines let's give this a try um and the result will be I'm trying to remember the result what was the result completion let's check completion return is uh string okay so we put the all the list of user uh user messages and this initial prompt together and and
- 1:22:30
uh let's hope that uh let's let's see and if uh uh those are provided uh right or right um Dev tails and the dev post link and the account ID on the
- 1:23:35
individual lines let's try that and then we need to par the result if uh uh if not in the results then what then then we need to say something nice to the user Dev post link Dev post profile link and the uh near Wallet account ID uh to receive uh five near uh Dev post profile link if you are
- 1:24:42
one trillion agents hackathon participant okay and then what uh message so we don't need last message we don't need this anymore but let's keep it in the code since I don't use get here um so the hope is that result split by lines will be something that we don't need the dev post
- 1:25:51
L and near wallet account near account ID or other Target account ID we don't need this either and now we can what Dev post profiling uh so to do uh verify the dev post link but otherwise we are ready to fund it so let's give it a try so the right now it's only the contract that is guarding us against finding some other accounts so as soon as I will deploy this uh agent it will fund anyone who will be interacting with
- 1:26:44
it but the contract will be on guard so I'll be only spending the fees for the transaction itself um there is a suggestion in the chat to use Json format uh with specific Keys maybe that's also a good idea to ask the a model to Shell out the Json in my experience it's also not PR very stable so let's let's start with this one hopefully like you can also rewrite the the prompt to to get what you want any a
- 1:27:25
way um I feel like new lines is a bit easier for um models for language models to operate within structur Json files Json formats but uh anyway not that big of a trouble so new version is coming and before we do that let's maybe have some G right
- 1:28:30
this going to be one trillion agents and me Agent public yes nice so at least we can have some starting point and I can start removing some of the code and not only pushing and uh keeping the comments destructing us um near registry upload
- 1:29:38
so it's good yeah hey okay that's we we are talking here we are talking here um my Dev post profile shouldn't be enough and uh wallet uh Min wallet is for near not bad at all let's see let's
- 1:30:42
see fund failed well for sure there is no no no near left there what are we talking about uh index uh exceed the account balance yes but that is the call that is actually doing exactly what we want cool um so what's left what's left uh now we need to validate the dev Dev post links um and skills so when I open this page so let's do the let's do the coral um
- 1:32:01
let's see what returns to to me uh and I'm searching for skills is this the only place oh no it's more than that blockchain portfolio taxs no bullet well let's uh let's say it is enough let's say that this portfolio tags is something that we can parse out and that will be just fine uh or maybe we can maybe we
- 1:33:07
can ask llm to par it I I I don't really like this idea actually I prefer grab um so verify the def post link so uh Dev post profile HTML requests get Dev post link. text and then that's a good point maybe we want to check the title software portfolio is
- 1:34:12
this is this only on my profile this way so I'm hackathons let's open some participants I see we have two more participants maybe actually we saw more people registering while I was scrapping the um I didn't get that could you try again AI is trying to speak to me where is the usource pro title software portfolio I think this is a good indicator or maybe now how about other Pages let's go to the main page or
- 1:35:16
hackathon page check okay what's the title here okay it's pretty different sounds good so very first thing is to then verify if not in Dev post provide link is not Dev post profile link and otherwise the skills oh and we just need to check if oh so we actually need to check this thing I guess yeah I guess this is enough if
- 1:36:29
and not in profile Pro does not contain near um does not have uh does not have near eii skill tag please add it to your profile um actually I forgot that we need to make a binding between the Prof Dev the post profile so we do not find the same Dev post profile not the we don't care about if we F the same um near profile for several people that's kind of fine or maybe not but it's less of a problem more of a problem is
- 1:37:30
the profile link and the profile link actually we also can easily parse it right it's just a it's in a name it's participants and the individual participant is on the dev post.com and this um is there any other hackathons yeah okay should be fine uh so we can also check profiling uh if uh Dev post uh we actually can do it before even call into it if Dev post profile link starts with if not starts with
- 1:38:34
this then another profile link uh and if so we believe that the profile your name is Def Plus profile link there is a nice method for that in rest obviously um but not here so we cut it off we have the profile username um nice um so
- 1:39:38
profile username something we need to provide provide to the contract we need to provide where to fund the um tokens okay okay well looks reasonable to me one thing that I forgot to do is to guard the execution of this method to be only available to be called from the contract itself otherwise anyone can just call my contract and pretend that they are finding the new profiles right then the dev post profile
- 1:40:35
link SX uh we actually don't need to par the the usern name I mean we can we we could have just used the URL the link the link itself let's be nice uh Dev post profile username and here Dev post username and we want to check that it is unique we want to check that uh we haven't funded such uh Dev post profile before
- 1:41:44
um and for that there is also low level um contract uh contract um API to to have to store it uh In Storage storage right and storage read so we would put storage right key and value we can put a key would be the account the the the profile the post profile and the value will be the where we fed it it's not we could even P put the empty string really there doesn't matter but let's uh
- 1:42:23
let's keep the um connection there so the connection is uh near storage right uh hold on first we check um if near storage H key or what um storage H key storage has key uh Dev post profile username then we we we exit with the Panic um that it's already funded if it's not then we need to storage
- 1:43:27
right to devpost profile username we can put empty string let's put the target account ID just because we can um let's keep my account is a safeguard for now here and uh promise B create Target account everything else should be but yeah right s key ah I think it should be fine so we we guard it and we found it we don't find the same profile twice should be good let me know in the
- 1:44:33
comments if I missed something um so we need to update the the agent and we need to recompile and redeploy so agent near registry upload um and the contract um and build what um hold on I already installed in a different environment
- 1:46:05
and we need to uplo deploy it here agent is updated and the contract is rebuilt and the redeployed and by the way redeployment on here doesn't only updates the source code so if we would have something in the storage uh in the state already saved then it will remain the same and it could cause some problems or it could be very handy depending on how you use it um oh no no no okay
- 1:46:59
yeah um I need to talk with a new agent new agent let's see hey my Dev post link profile is and uh my near wallet and near account is from with okay very promising we're almost there I guess okay a few seconds ago that's exactly what we want um exceed account balance that's right um yeah but we
- 1:48:03
recorded that this account is kind of funded I mean that's suboptimal but I think I think that's um that's a topic for a different uh call because it would involve the error handling from the transaction failure which will need we will need to set up a call back uh to the um promise to the transfer promise um so on the second try sorry so let's let's try again it should say so in this case it tried to send tokens to me but oh actually it f no it didn't
- 1:49:06
fail the function so now it should say that it's already funded what did I miss contract storage right profile name key already funded right should have been said already funded let's uh let's inspect it quickly contract view storage empty storage why did that happen uh storage right actually I didn't test the storage right apis in Python ISD K maybe it's not working yet
- 1:50:11
um that would be suboptimal but has key works at least it returns false all the time I think I will have to leave you guys at this because uh we are starting the another call uh with an F in a couple minutes unless I will find the quick like reason for this thing happening here storage right let's let's very quickly check the near by Tool implementation not that quickly though uh where is
- 1:51:06
the where did I tweeted about um nearby tool and we need to search for storage right
- 1:52:09
where is this mod near sorry I have to have bucket here storage key key pointer near storage Right Storage Right Storage right string of byes string of byes lens key value
- 1:53:11
storage right what returns bullan uh if another key value existed then returns true otherwise false not very handy right now or actually it is it is kind of Handy but not for this specific no actually it's not anyy we don't want to override it I thinking to replace the has key call H Dev post profile username Target account ID let's try to call it directly call call function this transaction uh
- 1:54:08
fund um Dev post profile username L with the account ID here exceed the account balance exed account balance oh that's right that's right it it didn't pass through it didn't it it failed the function call itself we we couldn't send the the transfer that exceeds our balance so there is only one receipt yes yeah yeah it's not the transfer that failed there is a use case when transfer will failed
- 1:55:03
if I if I would use the uh another um uh an account that doesn't exist then the transfer will fail and will be returned back to the um funding uh contract but uh it will be marked as uh kind of funded in this case it never actually was uh uh the the the followup receipt was not been able to like it wasn't created it failed the function call and uh that's why the storage changes were not applied um so we need to find the
- 1:55:42
account account um here tokens uh for uh send near uh to this new account uh 10 near myet yes sign okay and now back to the this guy let's see nice I was funed let's check yes I was uh let's also check the
- 1:56:51
state can we see the state here cont contract info not here unfortunately but we can do it from CLI uh near contract view storage all keys s text no yes exactly so we see in the storage Restore for all L is the key and the value is folded here so next time I will try to call this method it should fail with an error that uh it has been already funded before yeah we'll need to handle other messages
- 1:58:07
better what's going on it's stopped collaborating with us so I think I will leave it at this um thanks everyone for watching it was a amazing stream and uh if you have any questions uh go to to Discord near. chat um it's a short link in the browser or to telegram near Dev or to Reddit near protocol or any other communities you will find near system um
- 1:59:08
you can go to near dodev website and find all other communities and uh support channels and uh yeah build your build your smart contracts build your uh AI agents um that's um there is a lot of fun and uh I hope you enjoyed the video and uh we're saying bye to Python and back to rust see you