Pulling the Data you Deserve - ETHGlobal Bangkok 2024
ETHGlobal·Thu, Oct 9, 2025, 12:00 AM
Join us for a workshop with Aditya Arora from Pyth Network titled, "Pulling the Data you Deserve." This workshop will guide you to consume price data and random numbers from Pyth oracles. ETHGlobal Bangkok 2024 was a 3-day hackathon that took place November 15 to 17, 2024, and brought together the most skilled web3 developers, designers and product builders from all around the globe for a weekend-long adventure to advance the Ethereum ecosystem! ----------------- Follow us: https://x.com/ethglobal Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com
Transcript
[Music] okay uh guys uh this is Spitz workshop and uh I will be covering I'll try to cover two products that we have bounties for and please ask questions anytime there's no AMA afterwards because I'm very hot limit on time 30 minutes so I won't spend a lot of time explaining what pth is this will be more of a Hands-On Workshop so you can see see how to use it because it doesn't take more than 5 minutes to use Implement pth in your dap so pth and Oracle we Supply price data we Supply random numbers two things so price data can be crypto assets indexes Metals uh Redemption rates meme coins also sometimes now we have some meme coins as well and gold silver all Comm Comm sorry Commodities as well and how is different from other Oracle it's a pull based Oracle the difference between a push Oracle and a pull Oracle is in any push Oracle what do you have you go to blockchain and tell bro I need e USD price you're like okay go and read the data on the state that's how any blockchain or any Oracle work but in this case you have to pull the prices so I'll explain you what do you mean by pull the prices it's fine okay so let's get directly started with the code so you don't have to understand everything and just do things I'll do it in front of you at in remix okay so this is the exact code that yeah I'll Zoom it sorry okay this is the exact code that you will see in the documentation I will Traverse the documentation in front of you so that when you are building you can you can see what I did and you will remember with that so if you go to documentation and this is the landing page you go to documentation if you're building price feeds I will recommend you to use the guides here and click here in evm contracts and we have a code an example code so if you see here what things are there there is one construct that in which you have to pass the pth contract what's that pth contract how can you get that I will tell you afterwards that's the first thing you need second thing you need which prices do you want to read depends on application if you want e USD price or BTC USD price you need to know the idea of that that you want to fetch that's a second requirement third requirement the last requirement is you have to pull the prices so three things one you need the pet contract address of that chain second you need the price feed ID that you want to fetch and third you have to pull the prices that's all you things that's all the things you need so this is the main chunk or three lines of code that you will write in your code to F the price this is an example method if you see we have one the most important line which will make you eligible for Bounty a lot of people who tries to use spit they do the same thing like other oracles go get price get price no older than or get price and they say I'm getting an error I'm not able to get the price reason is you have to update the price feeds by yourself the reason is we can't give you prices every second on the Chain so whenever you need the prices you update at that moment so by using this you can get prices every 400 milliseconds that's how fast p is yes yes yes so exactly so get price no older than means you enter the price Fe ID and you have seconds so if you say 60 seconds so if the price that is updated on the chain is older than 60 seconds it will give you stale price simple and if you update the price that means means on that chain that price feed is updated so anybody can read the price for everyone simple as that one way that's all so one every price update causes like gas cost plus one way and even this price update if you see there's an argument that you have to pass it this is a price update that you will F the third requirement I told you can send 100 prices together in one hour argument and that's why we have one line which is like get update fee which will see how many prices that you're passing in this bytes and will tell you how much fees it will incur so if you're sending one price update one way sorry so you do get update fee you get the fee you send that value fee and the price update you f the price you're good to go that's that's all you have to do to get eligible for Bounty forget about Bounty that's all you have to do to fetch the price we have one question yeah yeah I'm pretty sure the we have 540 price feeds and in one time you can update up to 200 or 250 250 way I don't think anybody is high for anyone yes no no no so this price update will have the price this update will verify the price that you brought is right or not that's the first thing and second it will update the state on the Chain this will already have the price but when you are this you have to F from offchain that's the next part I will show so when you fetch from offchain I have to make sure that you're not changing the price in between before send in the contract yes yes till now everybody is okay three requirements one we have to find the contract address second which price feed ID that I have to fetch third the pull the prices now that's the trickier part where people don't realize that they have to do it in pet how to F the prices so there are three ways to do it like we have our apis we have sdks or you can stream the prices so if you see in this document on the left side we have fetch price updates a whole page so we you can directly fetch from a curl API which will give you like a data like this I'll show you in practice as well a data which you will pass okay or you can uh stream the price or I'll suggest use this SDK in your app because you will write a front end code in every application you will build just write this SDK call this hermis is the web2 API which will help you to fetch this price update you send the price IDs get me price feeds up to you this is get latest price updates send these price IDs you have the price updates that's it so I'll show you how it will work so the same contract that I showed you I'll run it in remix this the same contract nothing has changed I'm using eusd I'm hardcoded the price feed ID but I don't need to I am zooming out because it is difficult for me to do it like that okay let's compile this compile okay uh which chain do you think I should run it let me see how much I have this is sepolia so I'll run it on sepolia okay now I have to pass P contract this address how will you fetch it if you see in our documentation we have in reference material we have contract addresses this is here you go to evm and these are all the chains that we support on Main net and these are all the chains that we support on test net so I believe we cover everything that you want in especially nium space you won't have that complaint so let's find sepolia here yeah we have so many how many suppers now yeah here it is so I just copy this and pass it with in My remix here because I need to deploy it along the Constructor ask this so I pass this pth contract address deploy it transact not payable sorry what's I think I'm doing a wrong one I think this yes oh I've selected the wrong one yes yes so I'll add it here I don't know something wrong my metam mask is not taking the sepolia one so you just pass that contract address and you deploy it now after that you will go to hermis that why either API or SDK up to you and we have a Swagger file also so it will look something like this so for example you want e USD price and I'm passing it so that you can see when you execute it you will get this bunch of binary data this is the price update that you will have to pass in that method that I show you example method this is the thing main thing exactly this is the call data just remember because in solidity every string is represented by 0x just add 0x here we have built we have not added 0x here because we support stocket Solana every thing so it will create a lot of confusion so just add 0x and there'll be no errors after that just pass this and run your contract and don't forget that method has to be payable so you have to pass the some fees so that's how normal price feed work wow I'm fast so I we have a lot of time I'm being very fast so let's five minutes we'll talk about price feed if you have any questions and then I'll move to the next bounty yeah this you will get the price in this variable and you want to use up to up to you yeah so it is already updated here the option data you passed that binary data I showed everyone you passed here you update the data here the pth contract onchain is already updated now you just have to read it by here so offchain Oracle is not fitting directly you are fetching from offchain Oracle from her that I show so I I'll try to run it on remix yeah uh I think my question is like because like the smart contract on chain cannot call the offchain Oracle right so how can it pull data from the offchain Oracle you are pulling the data from Price update how we have verifying the data I believe that you're asking yeah like how to verify the offchain Oracle so we it's not okay the offchain Oracle we send Merle proofs of every price via Wormhole you don't have to worry about it we verify the prices on the back end via Wormhole yeah I I would just wonder how that works it's just Wormhole is a bridge it's a cross Chain Bridge oh you just send like a message yeah we send the proofs of prices that you are not you guys are not changing the price between the way that's how it works I can explain the architecture afterwards okay yeah okay okay let let's go to the if this is clear I believe to everyone okay so three things you need the contract addresses you will find the contract addresses from here second you need the price feed IDs all the price feed IDs are here in this page this is a price feed catalog ID it will look something like this so you can find everything and third you need to pull prices how you can pull prices the whole guide is is written here three things that's all now coming to the random number generator the product we have called P entropy using that you can Generate random numbers and how that works it's very straightforward for example you need a random number you come to pit and say bro I need a random number and what I will say it's like a commit reveal protocol what's a commit reveal protocol I'll say you submit a random number by yourself could be anything and I have will submit a random number by myself and we'll submit the hash of the random number on the chain and we'll commit it once anything is committed on blockchain you cannot change it agree in the next block I will ask you now show me your random number and I will also show my random number and we will verify each of the random numbers using that hash once that is true the final random number will be hash of both that's how it works in the back end but what you have to do is the contract will look something like this simple two methods that's all you have to call only one method so you you want to request random number what I told you you have to submit one random number it could be anything you submit that you submit your random number in the argument it's default provider use that the the provider is the one who will send the random number to you and this is the thing you have to call request with call back when you request with call back get the fees just like price feed that we did the entropy provider address it's in the guide I'll show you and your random number it will send back a sequence number that you store up with you and you have to implement this method in your contract which will be called by the provider like a call back we have in 1155 721s a call back method so our provider will call your contract by this method so you have to implement this method entropy with call back we will the like pit provider will call that with the random number final random number that's it so you have to just do this and in the next block or the reveal time for every chain is different we will send you the random number for every test net we send you in the next block only that's it you have to call this we'll call that and you can Generate random number with any JavaScript library like crypto web3 e ether even VM no VM doesn't have random number now but every Library have that any questions yep um and yeah just about like the bite code that we can put inside the entropy call box are we limited like I mean it will be Pi that going to call our call back right so we we just we in in term of of bite codes that could be executed um we are limited I mean or should we I mean about the design should we store the random nness and then do the process we need to with this number afterwards or we can do it directly inside the call function you you have to do it in the call back function and the limit for that call back function is 500k gas limit because we will call that method so we are paying the fees for that okay so we have to put a limit so I would always suggest this is because since this method will be called in the same transaction you want to implement your logic because if if that transaction happens people will know what's the random number is in the next transaction so I will Implement Implement a call back logic here or your random number that how you want to use any other questions I'm very going very fast I know that because last time every time I've done this Workshop I go very slow a lot of questions come and I skip the entropy part so we have time you can ask questions if you want me to repeat anything slowly I can do that yes no it's not like price feed this is completely different we are not getting the random numbers from the same Oracle service that we have the flow is also not same no no it's no it's it's completely different don't confuse with price feeds price feeds is pulling the data this is like I need random number just send me that no Oracle doesn't post the data you pull the data that's the difference between push and pull Oracle when you when I showed that you have to go fetch price updates like this remember when you call this API the see the data you see here which is highlighted is the update data the call data and the price will look something like this but when you submit this here I'm using my left hand sorry that highlighted binary data call data you have to submit here it will it is it already contains the price but you have to verify the price if you're using it on chain and that's where it just happens so you have to pull the price that's a very that's a catch if you see in the bounties that I have mentioned I've mentioned many times if you don't pull the prices you won't be eligible for Bounty you have to pull the price but if you are building something and you have you want to integrate many oracles together and the interface would be different for every Oracle you can run a bot which will keep updating the price we also have that bot it's in sh it's another document I'll share that so you can also do that so I'll check every each and every code how you are updating the price so you have to update the price this is the crucial part you have to fetch the price update the price consume the price three steps and three things that require the contract address of on any chain that like if a deploying on blast you search on blast what's the address put there which feed do you want you f the update data for that consume it it's it's up yeah it's storing and verifying two things are happening in the back end when you run this it's of first it verifies that okay you face the data from an offchain service the ethereum price is $3,500 you change to $33,700 and you tell p update the price it will it is wrong so here that update checks that have you changed the price or not how it's like every time you face a price from offchain we send a Merkle proof of that price onchain not the whole thing just a proof and we check Computing the mle proof here and here if they're same that means you have not change anything that's clear so it's like when we call that get the price yes so you like the user will get the price from one pass and then the will submit the merco tra through another submitted all the time okay gotcha so in the then in the contract it will verify like compare this to okay exactly so it will first verify and update the state so you're just reading the state here simple and you can combine 150 or 170 prices together in one update so you don't have to call transaction again and again so that's how you can fix it like have multiple price feed ID yes like this if you see in this in the same in the same API I can add many like right now it's replicating the same one but you can add many if you execute it will give you one data a bit longer of course but you pass this only so right now if you see I have passed how many five and if I go here so if I pass that five uh price feed data the fee here will be even know um but does that rely on the execution of this uh transaction and the meracle proof are submitted in the some same have to be in the same like block no what if like this logic is uh executed at block one but the Merkle proof uh so mer proof is not submitted like that when you update the price feeds the our contract will fetch it from the hole so don't worry about the Merkle proof from your end we will verify it we fetch it Merle proof from the Wormhole at that point of time we verify it so everything happens in one transaction so with the with the vrfs is it the with r yeah uh so with vrfs do you why do you need callback to specify uh upon like in the first transaction that you send when you request request for call back and you send your own random number we commit it if we we can't send this uh random number same transaction andless you commit your random number like what if you change the random number so that's why call back happens in the next transaction and we send you the random number that's why the call call back mechanism is there so in the next transaction you'll call my function in my smart contract that I uh specified in the uh call back yes so it has to be the same interface like uh revealed with call back I'll open it again yes entropy call back so our provider will call this method on your contract and with the random number and you will Implement logic inside this method only only to to work with that uh random number yeah if you want to use random number it's coming in the argument so that you can use in the same method well I can just store it in the storage right okay then right yes if you store it and then call another method in the same transaction then it's fine but by the next time everybody can see the random number so what's the use of that Rand oh yeah yeah yeah it has to be used immediately in the scope right okay any other questions you have time I can okay I'll show you some other things so that it's easier for you when you're building it in the documentation if you see for the inoy we are only available on these chains but for Price fees I showed we had a big list these are all the main Nets and uh we have test Nets as well I'm pretty sure you'll be using test Nets these are all the test Nets and this is the provider address that you will send it to the contract wait that's for Randomness yes that's for Randomness I'm talking aboutand romness right now and the fees varies for like these are the fees so you don't have to copy the fees from here you will use the onchain method to fetch the fees which is written already here get fee so the fees for Price feeds and the fees for entropy is not same for Price feeds it's one way per update for entropy it changes as per the chain so you can generate thousands of random numbers in one transaction can you guess how well like that uh array of like the same you said you ask for Randomness right yeah Randomness like I gave you one random number you can generate thousand random numbers out of that oh they like hashing yeah you can hash it you can use a c to Hash it or anything so that's right so we in if you see we have something like reference material best practices so you can generate multiple random numbers in single transaction so with a call back you can just encode pack uh hash it and have multiple random numbers with one transaction so you don't have to pay for 10 or thousands of random numbers just hash it with different seats that's what AI encode packed with K 256 so I'll recommend everyone to use the guides they are short they're crisp and they contains everything how up to date are they I updated it don't worry today so we have not changed anything in past few months okay but I keep updated some reference materials and all the contract add updated one I'm just putting an update if I'll Pro I'm pretty sure it will go by to like in two hours but if you go to Price feed IDs page these are the price feed IDs for price prices even though you're using main net or test net don't get confused by evm bet or stable don't look at this these are all the price feed Ides you need for Litecoin I don't know why it came to my mind yeah so the price feed ID always stays the same acrosss and uh Every Chain Every Chain irrespective of evm non evm or whatever you want price F will remain unchanged so then like when I switch chains I only look uh to to switch the address of the Oracle exactly okay and the price update that you fetch from Hermes is CH chain agnostic doesn't care about chain so you just have to change the Constructor P contract address that's all so when you switch the chains you have to change this that's all I have 30 more seconds and I've spoken a lot for Price feeds right now anything any think of any use case where you need a lot of prices together or very frequent prices trading any like almost every per out there users or D5 applications are switching to pit because we can send you every data every 400 milliseconds and for any random number gaming Lottery anything like that where you need random numbers you can use it exactly it's cheap it's all permissionless you don't have to contact me dude I need random numbers yeah yeah it's doable so you can make this Oracle as a push just answering the last question sorry can we please go to there to continue this we have to continue with the next talk thank you so much [Music]
Automatic transcript — names and jargon may be misspelled.