How Alchemy Can Help You Build and Scale Your Dapps - Albert Hu

web3con 2022 · 6 Mar 2022 · 21:03

Albert Hu, a developer advocate at Alchemy, shows how to build and scale blockchain applications with node infrastructure and developer tools. After an overview of Supernode, monitoring dashboards, Notify webhooks and enhanced APIs including the NFT API, a live walkthrough builds a generative ERC-721 collection of 888 word-list hackers with Hardhat and ethers, adds a minting front end, and explains how to move to higher usage tiers as an app grows.

Speakers

Topics

From web3con 2022, hosted by Developer DAO.

Transcript

this talk is sponsored by polygon polygon is a leading platform for ethereum scaling and infrastructure development its growing suite of products enables developers to build scalable user-friendly dapps with low transaction fees without ever sacrificing on security learn more at polygon.technology all right what's up web3con developer dow anyone else who's watching this in the future on the internet anywhere uh super excited to be here today to talk about how to build and scale your blockchain applications using alchemy um so real quick introduction i'm albert i go by that guy in tech on all social media the metaverse ens domain whatever if you look it up it's probably me um i

worked at a couple of different sas companies as a software engineer before joining alchemy and web3 full-time so companies like salesforce magoosh and samsara as you can tell i love building tools and helping make sure that developers and users have a great time using whatever the service is and so before i went full time into developer advocacy i had worked on an nft project with my girlfriend and a couple of friends we built the chibi shinobi project and for people who don't know chibi shinobi stands for cute ninjas it means cute ninjas in japanese and this was inspired by naruto one of the most famous popular japanese animes uh in the world and so i had written the smart contract side i had worked with uh worked on nft art generation with my girlfriend who was the artist and a couple of other artists that we brought

on board and we created this project and i thought it was amazing just to see like this entire flow um and it seems cute uh it seems like oh cool like whatever um you know collectible nfts we've been there done that for a while now but it really opened my eyes to this entire process anyways in my free time whenever i do have free time which is rare now i do like to do some wraps as well so if you're interested in this wrap i'm not going to show it here go to my twitter profile it's a pin video and you can watch it there but this actually kind of kick-started my whole career it tells the story of how i got into crypto and how i ultimately ended up where i am today um awesome so now my role is a developer advocate at alchemy and my job is to

empower developers to build on the blockchain i love learning and then sharing my learnings and enabling others to build so super excited to be here now real quick a quick overview of the uh of alchemy as a company our whole mission is to empower builders to bring the magic of blockchain to the entire world uh and the way we think about doing that is we think about how do we make blockchain as technology grow and mature and we do this by uh going through this product life cycle where ultimately we want users to benefit from this technology whether it's a new financial system new digital assets and ownership and identity all this stuff we want people to benefit from that but in order for that to happen we have to have really good products in order for really good products to be made we need developers

who can piece together all the bits and like the low-level technologies and the new information that are coming into the space to build those products but when that happens we create this virtuous cycle where developers are making good products good products are incentivizing new users to join and the more users there are the more developers want to build and can't afford to build and all this stuff so the pain point though is that it can be difficult to build products and new technologies because you know think about running your own node think about like developing things when there are no libraries or sdks or apis um and you have to kind of do everything bit by bit it's like pretty hard and so that's where alchemy's focus is we want to shorten that gap so that we can increase this velocity of the cycle and then bring blockchain to as

many people as possible so we've been doing pretty well so far it's you know whatever we've been doing has been working uh we power a majority of the top applications in the space whether it's web3 companies or you know web 2.5 companies that are bridging the gap uh we also power a majority of all nft platforms uh so you know openc makers plays super rare axiomfinity blah blah and uh the question is how do we actually do this we actually have a whole suite of tools we're not just an inferior alternative um we have a whole bunch of things that are going on that i'm going to walk you through so what tools does alchemy provide we have the first thing that you know and love is super node it's basically the connection to the blockchain so anytime you want to read or write data

to the blockchain you're probably going to be using our supernode product um basically what we've been able to do and that's being depicted in this complex diagram here all you really need to remember is that we've figured out how to run a bunch of nodes and create this engine that solves the problem of reliability scalability and data consistency so that whenever you want to read and write information to the blockchain to and from the blockchain we'll get it to you asap and you know a lot of people talk about decentralization and oh wow you created this thing but now everybody depends on it it you can use another service provider you can run your own nodes but we've just figured out a way to make sure that information can scale as you're building websites and applications and deploying your smart contracts and is data consistent so that

you don't have like all these uncle blocks and dropped you know reorgs and stuff like that going on that affect your your development workflow and so that's this is the bread and butter we'll see this later in code demo the other things that we have though are nice dashboards so we have our build product where you can search historical requests you can see requests per second you can see success rate you can visualize your mempool a bunch of these like dashboard features which are super nice and then if you're more on the business and analytics uh side or like you're in that mood to optimize those things we track these uh performance and user insights for you so you can actually know where your requests are coming from whether it's you know the united states or some other country in the world um and then also within you

know the countries which area is is it coming from so that way you can maybe optimize your product or optimize your latencies or whatever it is and we'll give you usage analytics application health alerts and a lot more and then notify is another really important product with notify something that's really cool is that we can actually push information from the blockchain to you to your servers via web hooks and this is actually something that's pretty hard to do with blockchain because as data is coming in if you wanted to track you know a certain transfer a certain sale um a token swap whatever it is you normally would have to pull the blockchain and keep asking hey is that information update did anything happen yet did anything happen yet and then like index those events and then maybe serve it on your website or your application but we can actually we

already do that so we can you know like just let you know hey you know your user uh who's tried to swap a token they're trying their transaction completed so you should let them know so you know we track things like transaction status address updates and gas price changes and i'll show you the interface for this later as well so and then uh we have enhanced apis and these are super crucial to most people especially for you know maybe like a hackathon or you're trying to like build stuff really fast we have these higher level abstractions called enhanced apis that are that can you know let you query for things like transaction history token information um connect to websockets things like this and our nft api that we just launched falls under this kind of category of enhanced apis where you know you don't have to filter

through all these events and figure out nft stuff for yourself we've actually done that for you and you can just query you know who which address owns which nfts and things like that and then finally this is not like a technical product but this is equally as important especially in the crypto space where you're trying to build community you're trying to market when you are ready to launch your project alchemy amplify is there for you you can offload your go-to market strategy or a portion of it to us you can add the certified info infrastructure alliance badge to your website to um give it more legitimacy and then we can spotlight your project in our newsletter our social media linkedin twitter wherever it is that you want to spotlight it we have a big audience there so we can help you with that awesome so uh that's enough

overview of these products let's actually see these tools in action i kind of want to show you you know what a workflow is like from an indie developer perspective perspective when i'm creating a new project and then eventually how do i use um enhanced apis and amplify and stuff like that to bolster it so let's see these tools in action what we're going to do and this looks super shabby on the slide um but i've basically forked projects like uh loot and developer dao shout out to nader for uh who created developer dao and you know made content about this type of code but we're gonna make a generative nft collection and i'll show you how alchemy plugs into this developer workflow through the entire project we're gonna develop a smart contract to deploy this nft and it's gonna be a collection of 888 of these

randomly generated word lists that describe you as a web 3 hacker and then we're also going to build a really really basic front-end website that helps you mint that nft and visualize those nft using alchemy's enhanced apis and nft api so um and just to show you if you're not familiar the developer dow tokens uh collection on openc is about right now it's about 8 000 items just under and this is what they look like you know a list of words and people have been training them and this gives you access to developer dao discord and so you know maybe we can do something like that or we can partner with developer dao and then we have loot this is the og project by dehoff he created loot for adventures and the whole idea with this is like hey let's make a bottoms-up nft project right where it's not art it's

not an art collection um it's actually something that the community can build on top of and make you know apps and visualizations and battles and all this other stuff so it's a fun idea so that's what we're going to build today now let's exit out of this and i will actually show you so the first thing is if you want to follow along there's actually code for the smart contract in this repo so it's that guy in text slash hackers dash nft github.com hackers nft and the frontend website is hackers nft dap okay so we have two separate repos here now in this first refill for hackers nft what i want to highlight here is let's go in here we have obviously the contract this is the first thing that's really important um it's the contract that we're going to be working with is a it's called hacker and

it's an implementation of the er 721 standard so it's called web3 hackers the token is called hacker there's going to be 888 of them and then i've created these you know word lists uh that describe like what's your hacker type and there's all these different types like full stack developer backend architect funding genius block engineer blah blah you get the idea um and then there's also these moods so what mood are you in usually uh while you're hacking and then here are some chains that you like to hack on um and then what's your myers-briggs this was totally random but i thought it was fun because i like myers-briggs uh things and then there's all these other word lists so if you want to look at this go to the repo but this is the contract so this is the contract file and the important thing is

where does alchemy come in we have this hard hat configuration right now in this project i'm using hard hat and ethers but you could be using python you could be using some other sdk some other development environment and the key thing here is that alchemy for super node when you're communicating with the blockchain all it is is this all it is is this uh url endpoint and right now for good practice i'm putting it in my end file and normally you don't want to show this end file to people but for the purposes of demo i can show you this it's like faker information um but i've set up you know an alchemy rink b url with an api key and then an alchemy robsten test net url with an api key and then a mainnet one with an api key and then i have my

you know private keys but these are these are fake um and then in the hard hat config you can see i'm actually loading the ranking url throwing through private key the ring option url or option private key mainnet url main a private key and so when i uh want to actually deploy to a test net or deploy to a mainnet it's as simple as running this script so i actually already have some of these loaded here um but you can see here this is like rink b so npx hard hat run i have a deploy script which i can show you it's a the script right here super simple it comes out of the box with hard hat you know depending on what like developer environment you have it'll probably be different but uh we're just getting the contract um factory we're deploying it we're waiting for this deploy

transaction to finish and then we log the address that comes out so i've already run through these but this is what the script looks like and so when you call this uh command for example with the ring me network flag it will access the alchemy rank url and then after after you uh do this deployment i can show you on our dashboard i have a bunch of apps these are all the apps that i've been developing with but i have one for the web3 hackers smart contract but on robsten so if we click into this dashboard for this application you can see i have a lot of requests here because i was doing a lot of test deployments and mints and all this other stuff but the beauty of having this dashboard is that you can see all the requests that are coming through you can

see how many requests are actually succeeding or failing because we have these different tabs as well so out of the all the requests in the past 24 hours there was point one percent that were invalid and you can see there was one uh what it was it was actually get nft's api call to alchemy um but you can see at a glance like the most recent requests you can see the rate of request or the number of requests over time uh and then here's the monitor dashboard we can see since it's just me acquiring it and i'm in california all the requests are coming from california so that's what's happening here and then i can deploy it i can interact with it on the test net and um and you also get this nice mempool overview so right now this is all apps but if i

wanted to filter down to just my web3 hackers robson testnet one you can see these are all the transactions that were successfully mined and everything in one view in the memory and then pool watcher so let's say i'm ready to deploy to mainnet it's as simple as going over here let's clear this i'll just look up the command because i've already done it once i don't want to do it again um it's it's just switching a flag if i'm using something like hard hat and then what's going on under the config is i'm just using a different alchemy api url endpoint which i've stored here ethmainet.com.apio and um you can see in our dashboard this is where i actually pulled from i should have showed you this earlier and we go to apps uh and to my mainnet app that i've created just for this you

can click this view key button and this is where you get your api key your rpc url endpoint and then if you wanted to do websockets we have that as well um so yeah that's that's how you would connect and deploy and you can see here also we have our most recent requests um you know we deployed it we got the transaction receipt we have no invalid requests so far life is good so that is deploying the smart contract and then we have the front end website as well so on the front side of things we have a separate repo and if you want to follow in on the front-end side of uh or you know fork your for this repo to make your own front-end website your own mentor your own display this is uh the repo so it's github.com that guy in tech slash

hackers nft dap okay i already showed you this um and so in this repo how are we using alchemy so it's very similar except we're not deploying a smart contract but this time we're using providers um and actually i should show you the website so this is the website if you go to hackerdow.com it's live you can actually visit this you can connect your metamask and so i'll just do a demo real quick so let's connect my metamask it'll pop up this window and uh yep this is the account that i want to connect with and then it'll show you boom uh you have an ens name you have your address that's connected this is the network that you're connected on via metamask we don't have support for wallet connect or anything like that but i can add that later and then here's like a warning you

should be connected maintenance and view your hackers um and then there's two tabs and this is my really janky navigation here but on the first tab if you click on mint this is the mentor page and you can see this is the contract on production that we've pointed to that we're currently like about to interact with um so if you wanted to verify it for yourself oh i should verify this contract i'll do that later um that's the contract and then if you wanted to mint uh you can click that button it would issue a request and then metamask will ask you to sign um it it's free to mint uh you just have to pay gas fees but i'm not gonna do that right now and then it also shows you how many tokens are remaining uh available for for mint then over here

on this other tab we can view the hackers so right now on this address i have minted one hacker uh token hacker down token and so this is my word list and so if i minted multiple it would show multiple but yeah this is like a pretty bare bones obviously uh website for what a lot of people may be doing right and let me show you how alchemy helps with all that so in our application we have um our app.js this is kind of the entry point that's the homepage and over here i am using the wag me library which is super nice shout out to the wagner library this is their documentation page you should look this up it's like a bunch of react hooks that makes development pretty easy and so i have this wagner provider that wraps it and i'm connecting to the blockchain not

using the default provider but using an alchemy provider and i'm instantiating that just like this it's like literally two lines of code with my api key and with mainnet and that allows me when i am uh as a user you know talking to trying to connect trying to mint whatever i'm using the alchemy connection to make sure that the process is as smooth as possible there's no drop transactions there no there are no hiccups so uh that's the connection there and then the enhanced api feature is the nfd api so over here we have uh under the source utils files uh library or uh repo uh we have this file called alchemy entity api and this is where i've implemented a utility function called get nfts and this actually hits the enhanced api endpoint um get nfts right here so i pass in my api key i get nfts

and then this is the contract address in production that i want to filter on and then over here i return a bunch of data so i want to return the name of the nft token the image url and then the token id and then over here in the nfts.jsx routes you can open that up i'm actually calling the get nfts function see that and then i'm passing in the address that is connected to the website this is another wag me function so after i've connected this is the address that's passed into the call and then once i get a response using this use effect hook i actually load it on the page and that's how we see this information right here be my hackers so that's pretty cool right uh like all this stuff alchemy can help you build um and so a couple other things uh sorry brain

part a couple other things i want to show you here so before we wrap up um there are a bunch of other enhanced apis i just showed you a couple and uh oh we have notify let's go through notify real quick so on notify um there's this is basically the web box where we're pushing information to you so we have address activity drop transaction notifications mine transaction notifications and gas price for when you want to you know get notified for when gas price drops below a certain point to like do something um and then what's cool is like you know we can push information to you so i'm tracking the crypto coven nft project and i'm using this for crypto common sales bot app which is pretty nice um and then for enhanced apis i just showed you one endpoint on the nft api but we have all these other endpoints

for trace uh debug token metadata transfers token balance you know whether you're building a wallet application an exchange whatever it is we're we're going to build nft apis or we're going to build apis for you uh and then finally we have alchemy amplify and i touched on this a little bit earlier but this is you know our way to help you market your project once you're ready to go um and so you know there are a lot of projects that are already part of the alchemy amplify partnership and uh one thing that you can do oops let's uh zoom out there is join the certified infrastructure alliance this is a badge you can add to your website to add legitimacy to your website because basically this says you are using alchemy infrastructure and alchemy infrastructure is the best in the industry we have a supercharged newsletter uh

that has tons of tens of thousands of readers every single week so we can feature your project when it comes out and then of course we can hype you up on all of our social accounts that already has a huge following um and some examples of logos or companies that already use the certified infrastructure alliance and have been uh benefited from amplify diversify is a decentralized exchange you can see boom they have their uh badge down here uh we have the full send meta card this was an nfc project that had minted out like sold out in like a minute or two uh 20 million dollars plus i think on just the mint and we helped make sure that their mint process was super smooth no hiccups everybody who submitted a transaction was able to get it through and they weren't blocked on the node provider

aspect um so they have a badge variable's another one too um so awesome and then the other thing about scaling is once you've built out your entire you know you've gone through this workflow of building your project and you are you know getting some users you want to make sure that all the transactions going on on your website are smooth um we have actually this growth here so we go into settings here billing you can turn yourself onto growth tier and what this does is it gives you more requests it gives you higher rate limits it has it gives you more applications and then also if you uh submit you know um payment information then you can turn on auto scale so with auto scale if you were to go above this request limit and you needed more support basically we can do that automatically for you so

interruption there would no there would be no service interruptions and then if you need anything beyond this you need custom rate limits uh you need unlimited applications or you want like custom 24 7 support and a bunch of other things you can contact us for enterprise plan so that's you know we take our customer support really seriously because that is one of the ways that we can make sure that this entire industry uh evolves in a positive way so yeah um hopefully that was super useful for for everybody out here um if you want to uh get a free nft uh from from this website so if you don't want to make one for yourself but you want to get a free hacker down nft uh what i want you to do is screenshot your favorite feature or moment from this um presentation and

then tweet at me so i'm at that guy in tech and also include alchemy platform in your tweet and then tell me in that tweet what was the most useful and this is a great way for me to get feedback too on what's standing out to people and if you have any questions about alchemy or anything that you want me to make a further tutorial on i'm happy to do that just include that in your tweet the first five people to include that uh to issue that tweet to publish a tweet i will airdrop an nft too so yeah hopefully that was useful happy hacking hope you all are building great things out there and we're excited to keep supporting all the developers in the space um my name is albert and yeah that's it i'll see you later bye