New Ethereum talks, every Monday. The week's conference uploads by event, in your inbox.

Loading player…

API3 🛠️ An Introduction to API3

ETHGlobalWed, Oct 9, 2024, 12:00 AM

Join us for an API3 introduction workshop! From November 17-19 2023, ETHGlobal is welcoming builders from around the globe to help shape the future of Ethereum at ETHGlobal Istanbul. $500,000 USD in prizes are up for grabs at the prestige ICC Istanbul Congress Center... you're not going to want to miss this! ----------------- Follow us: https://x.com/ETHGlobal?s=20 Check us out: https://ethglobal.com/ Email us at: hello@ethglobal.com

Transcript

[Music] welcome to the API 3 Workshop where we will be showing you the products that we offer we currently offer three services chain API which is the ability to bring any offchain API onchain using our air node system qrng allows you to receive true random numbers on chain with no token required and our newest product dapi prize feeds on chain that is constantly live updated no token required as well let's get into it our dapi SDK only requires one Library import and only requires two functions to get started right away you can see that we have our iy. library import and then with that we have our two functions here a set proxy address that selects us choose which price feed we want to use and a red dat function to read the price feed all we do is set our proxy address which we'll grab in in just a minute and the ability to read you can see that it returns two items the price or the value of the asset that we're looking for and the timestamp of the last time the price was updated on chain we can head over to API 3.org and check the data feeds and look at the market place here we're going to go ahead and look for ethusd and we are across multiple chains for this example we're going to use sepolia test net you see that the onchain value is currently live on test Nets we only have self-funded on mainnet we also have managed feeds for now we're just going to go ahead and grab the proxy address right here so that way we can set our price feed and so we're going to go ahead and deploy this contract we're going to go down and set our proxy feed we're going to go ahead and set our proxy address we're sending it to the eth US USD on sepolia and once we have confirmed it we can go ahead and read our data feed function and it'll return us a price feed and a time stamp and you'll see that we have $1,615 and 1 cent with trailing decimals and the time stamp available of when this was last updated to verify that we can go onto the market feed $1,615 with 1 cent and trailing zeros and the last time stamp that was updated fairly easy to use so then you can get started with your price feed for what whatever you need a Perpetual borrow lending or whatever you need that price feed and time stamp for our qrng random number generator only requires one import it is the RRP requester v0 and the request contract setup only requires three functions one to set the original parameters depending on the chain that we choose to deploy on and the type of requests we want one to to make the request for the random number and then three what we do when we receive our random number here we have events to allow the contract to emit the requests and response we have a few public variables to help set up our request parameters depending on our chains we have a public array so we can see the numbers we get and return and we have a mapping to keep track of our requests and a response our Constructor requires our air node depending on the chain that we Deploy on let's look at the function in the set request parameters we have to request the ER node the endpoint array and the sponsor wallet the air node endpoint array are all set up in the docs sponsor wallet is generated depending on our deployed contract we'll touch on that in a second here our make request array a lot of this is boilerplate code you don't have to modify this much at all it is making the request for our numbers and is asking for the amount how many numbers we want in return do we want one number two numbers three numbers on and on and it will return that many different numbers here once we get the request it will have to respond back to our contract and it'll respond with our fulfillment it'll return the numbers to us here we have this public variable set so it'll decode the data that we get back and give us the array of numbers that we have so then we can display It On remix once you have your numbers then you can import your logic here whether this is an nft project or a game project or some kind of attack or level up with those numbers you can do whatever logic you want in here to import your contract data let's go ahead and deploy this and we're going to go over to our docs to get our air node RP so we're going to go over to API 3.org and we're going to go into the resources and we're going to go to the docs we're going to head over to qrng and we're going to look at our chains Aus is for main net for our ined purposes we're going to go ahead and use test net so we're going to scroll B this and go to our test Nets here we have test net AIA so we can go ahead and grab our air node RRP v0 address which is this address here we're going to go to remix and we're going to go and paste this down and deploy it to sapoia now we're going to go ahead and set up our parameters let's go ahead and minimize this to make this just a little bit cleaner right now what we're going to do is we're going to set our request parameters in which we need the air node endpoint array and our sponsor wallet so if we go to set request parameters we need to input all these settings in our documents we're going to go to Providers we're going to scroll down remember a andu is for main net so we want to scroll down to our test net random numbers we're going to go ahead and grab our air node copy that in we want our Endo un 256 array this is for a single number request this is for an array of numbers so so we're going to grab our array and now we need a sponsor wallet in our docs you can see that we can generate a sponsor wallet I've already preset this for time to have our general to generate our sponsor wallet it is it requires an air note extended public address our air note address and the sponsor address let's go ahead and cover those one by one the air note extended public address is the xub so we're going to go ahead and grab that put that back in here and paste it it's going to want our air note address which is the air node and it's going to want the sponsor address which is our deployed smart contract address so if we head back over to remix let me move this to the side we're going to go ahead and look at our deployed contract because this is the address we want to sponsor we're going to go ahead and paste that down and we're going to copy the entire thing we're going to open a command prompt or terminal and we're going to paste it in and it will generate a new sponsor wallet for us our sponsor wallet will be generated we'll go ahead and grab this address and then you can check on zolia test net that this address has been generated and you see that we have a contract address ready to go what we must do is fund this wallet because this is the wallet that will pay for the gas transaction for the request of random numbers so we'll go ahead and fund it with a little bit of gas and you see that we have updated our balance for a sponsor wallet with 0.1 eth we can go ahead and put this away for just a little bit we'll go ahead and input our sponsor wallet address which is the address we just generated and and then update our smart contract okay now that our smart contract has been updated what we're going to do is we're going to make a request so again none of this really has to be changed we're just requesting the amount of what we want we're going to go ahead and make the request I'm going to go ahead and make a request for three random numbers and we're going to go ahead and send that transaction now there's a two transaction system the first transaction is to make the request to the node system that we have in place and then we have to wait for a response so we have now set the request and so now we will wait for the airor node to respond back to our smart contract and call this function once we get a response you'll see that we have an array of numbers it has been a few moments so we're going to check our results if we go to our array we're going to go ahead and pick array position zero and get our number number and you'll see that we get a very very large decimal number we can modular that on the decoding so we can put a modular 100 so if you want to do something like a uh out of 100 you can definitely modular that if we look at position one we should get a totally different number and we have an exactly exactly what we requested a different number and if we go to position three we should have our third number there we go so you can see once you get your number you can add any logic you want whether that that's minting an nft with these random numbers or doing an attack with these random numbers or sending out a payment with these random numbers or a loot box um the choice is yours API 3 bounty prizes we are looking for the best use of dapi price feeds utilizing crypto Commodities equities or Forex data by activating your feed through API 3's Market project ideas could be pay masters using account abstraction Perpetual swaps Oracle protected swaps or lending protocols best use of API 3 qrng random numbers add unpredictable Dynamics to your application with random numbers using API 3's qrng project ideas could be like randomized airdrops Loop box nft mints or light strategy games and finally API 3 Runners up either use qrng or dapi Price feeds in your dap to qualify as an API 3 runner up to have your share of the three-way split thank you and good luck in the hackathon

Automatic transcript — names and jargon may be misspelled.