The Developer’s Guide to Hedera Hashgraph - Cooper Kunz
Ethereum Denver·Sat, Oct 9, 2021, 12:00 AM
This talk is from ETHDenver & ColoradoJam , the world’s largest Web3 BUIDLathon and Community Gathering. ETHDenver’s content is crypto and blockchain focused. Learn more: ethdenver.com Subscribe to our channel to learn more + connect on Twitter: https://twitter.com/EthereumDenver. Speaker: Cooper Kunz, Hedera Hashgraph This talk was recorded Sunday, February 7, 2021. ETHDenver 2021’s content themes included DeFi & Money Legos, NFTs & the Creator Economy, ColoradoJam & the Next Frontier of Statehood, Protocols & Interoperability, Open Source & Public Goods, The Ownership Economy & Digital Orgs, Usability Design & Adoption and Legal, Privacy & Identity. Industry experts also weighed in on topics like decentralization, privacy, identity, non-fungible tokens, scaling, governance, diversity, and arts and culture in blockchain technology. The 2021 event was February 5-12 and hosted virtually in 2021 with 5000+ blockchain enthusiasts, developers and community members from 80 countries and 50 U.S. states. 🔴 SUBSCRIBE ETHDenver’s YouTube https://www.youtube.com/channel/UCgz9NU06t_FkT0Py1Vadczw 💡 LEARN ETHDenver’s Official Website https://www.ethdenver.com/ 👋 CONNECT ETHDenver Twitter https://twitter.com/EthereumDenver 📖 READ ETHDenver News on Medium https://medium.com/ethdenver 🛍️ SHOP ETHDenver Official Merchandise bufficorn.com 💬 CHAT Telegram https://t.me/Ethdenver Discord https://discord.gg/AxFmNdCVnU 📱 FOLLOW LinkedIn https://www.linkedin.com/company/ethdenver Instagram https://www.instagram.com/ethdenver/ Facebook https://www.facebook.com/ETHDenver/
Transcript
this is cooper with hedera hashgraph he's going to go through uh really your developer's guide to their entire system so um take it away yeah hi everyone uh very happy to be here today um can i be more excited to be a part of eat denver and show you how to get started on hedera uh i'll probably start by sharing my screen a little bit awesome hopefully everyone can see this john or anyone uh please please yell at me if not okay cool so i have a few slides and then i'm going to walk you through how to create your account on hedera's test net how you can actually start uh setting up your environment and writing transactions against our test net environment so it should be really fun but this is just the developer's guide to hedera once again i'm cooper i'm a developer evangelist there and you can find me on twitter at cooper underscore coons um for those that don't know this is uh how hedera's kind of architecture looks at the very bottom of the technology stack you have that hashgraph consensus algorithm uh that's something super super unique to hedera it's really interesting technology and a little bit out of the scope for this workshop but if you're curious i highly recommend looking into it either with one of our white papers or on youtube on top of the hashgraph consensus algorithm we have our own version of our native cryptocurrency called hvar and we have two other primary network services so one of them is the consensus service which is a really cool ordering mechanism for public and private blockchains whether you're running hyperledger fabric or a fork of ethereum the consensus service is a really interesting api uh but what we're mostly going to talk today about is actually the service on the right the hedera token service which is the newest product offering for hedera and it is one of the easiest ways in the industry to mint and administer different types of tokens whether they're fungible or non-fungible and there's a lot of really interesting like implications of this for example because it inherits hashgraph speed you can actually run these tokens at tens of thousands of transactions a second for just a few uh fractions of a penny it's .001 cents right now to send any of these tokens and so yeah just to kind of give you the context of the hedera token service like i said it's really really scalable it's super fast you get actual proven finality within three seconds uh this isn't like a layer two or a side chain where you have to wait for it to eventually settle back onto the main chain it is operating at the [Music] same security model as our layer one uh again it's native it doesn't have a second layer solution there's no side chain there's no payment channels which is really nice if you're into different types of more regulated industries maybe you're doing security offerings uh being able to actually do kyc account management and being able to freeze or wipe people's accounts it could be super super important all of those compliance features are totally optional though so no no worries there if you're like i don't want to require any kyc and verification on my account it is entirely up to you as the developer we mostly just give you the options and similarly to the rest of hedera the token service and all the tokens issued on it are subject to the same kind of enterprise governance model that we have where the fee schedule our you know different api features are all kind of determined by the hedera governing council if you're not familiar with the hedera governing council hedera.com backslash counsel should probably tell you everything that you need to know and so that was kind of the end of me setting the stage just kind of wanted to remind people who aren't familiar what hashgraph is and what kind of our ecosystem or tech stack looks like the rest of this is going to be showing you how you can create your own test net account and set up your environment maybe even if we have enough time to try out a demo application but so these are all of the the resources that you're going to need today portal.hedera.com is the easiest way to get a testnet account hedera has language support in javascript java go.
net and maybe even a few others but today's tutorial and workshop is going to be in javascript if you have questions about the other sdks or apis that we have please feel free to reach out they're very similar in syntax and implementation so if you can follow along in javascript i'm sure that you can follow along in any of those other languages we also have a really great demo application for the hedera token service and a variety of other demo applications hopefully we'll have enough time to show you how you can set that up and what that looks like but if not please check out our github and then we also have a very active discord specifically related to hedera so tedera.com discord please feel free to join that and ask us any questions that we have we also have our own channel in the ethereum denver discord of course and you can ask us questions there as well so i will stop sharing my screen here and open up a few uh of the resources that we're going to be using today and once i have them open i will start sharing my screen again for anyone who's following along or hoping to follow along you can go to portal p-o-r-t-a-l dot hedera.com and register there it should just take a few seconds and that's actually what i'm doing right now in the background all right hopefully people can see this yep awesome i appreciate it so once you are signed into our portal uh you should be able to see a screen identical to what you're seeing right here uh again it's just portal.hedera.com and you have a drop down here to switch between any of the networks that hedera supports so our test net is obviously where you're going to be doing most of your development if you want access to like the latest latest features we have you know continuous deployment set up to preview net where every time that we make changes it'll go live on that network and then main that's obviously where all the fun stuff happens and when you're ready to go to production uh you can toggle between these because this is just the test network it'll just display your account id your public and private key uh here so this is actually all that you need after you have signed up to actually start uh setting up your development environment and writing transactions um for those that are you know obviously familiar with ethereum's test network process uh any account on the test net for hedera that is created through this portal will automatically be funded with 10 000 hbar our native cryptocurrency and topped up every 24 hours so you don't need to go request faucet funds or things like that if you signed up through here it'll just continuously replenish and kind of top you up and make sure that you never run out of tokens so what i'm going to do next is pull open a javascript development environment and i will start from from scratch here hopefully people can still see my screen all good okay awesome i appreciate uh the godlike voice confirming that i'm not crazy here um all right so what i'm gonna do first is just create a new file a new folder that'll house our project today uh for those that program in javascript and node this is pretty common stuff but i'll make a directory uh we'll call it each denver demo and we'll move into that also maybe make this a little bit bigger just so that people can actually see uh so within the denver hybera demo there's nothing in it so we'll use npm and knit to create a new node project and in this case since it's just a live demo here i don't really care about what the defaults are so i'm just going to push enter for all of these obviously you can populate this with you know details related to your project but now uh that this is okay we should have a new npm file or a package.
json file in our new folder so i will go and open that up denver hedera demo and you can see that we have a new package json here that is set up and configured to uh run in this folder so i'll open another terminal and you can see that it obviously dumps me back into that folder that we just created and if you type ls it'll give you your package json all right so now we have a new node project uh we need to install two dependencies for what we're trying to do the first of which is dot env this is just one of the default ways to manage your environment variables and node you can use different things like npm and vet env and you know any type of environment tools that you wish to use so that's kind of like an optional dependency but just makes it a little bit easier the other thing that we need to install is the hashgraph sdk and what we want to do is install this add a version greater than two so npm install with i and it's at hashgraph sdk and we want to be running anything above version two of the sdk so we'll do at greater than two and that should install all of the hashgraph dependencies and you know specific sdk code that we need uh to run our tutorials here and you can see in our list of dependencies we have you know version 2.0.16 and env cool and you can see our package.json has all of our dependencies and the hashgraph sdk is over here so next we're going to create a new env file that'll just manage our account credentials so this will take my account id it'll take my private key and you can name these whatever you want as long as they're unique strings but what i'm going to do next is i'll take my account id public private key from the hedera portal and i will paste those into here in plain text not in parentheses or anything like that so for my account i'll just type that in so you can get kind of a sense of what it'll look like and then you know public private key i'll stop sharing for a second and copy and paste that information in at the end of the day hedera also supports really nice and easy key rotation different things like that so if you do end up exposing your test net keys not not the end of the world uh you can just rotate them before hopefully someone steals your fake cryptocurrency cool and so i will come back and share my screen again and hopefully people can see this i assume they can awesome this uh this confirmation is great i wish they had that on all the live coding and live demos that i did uh i appreciate it you're welcome um all right great so now we have our entire environment set up we have all of our packages we have all all of our dependencies we have our environment variables with our private public keys and our account id so what we're going to do next is just create an index.js file [Music] and so within that index.
js file we're going to do all of our our coding for this kind of tutorial uh within here the first thing that we're going to do is not request animation frame but required.emv is and require it to be configured by default it'll just look for any file title.env within this folder and it'll give you access to all of those variables after that we're going to import specific modules or specific parts of hedera's sdk specifically you need a client connection you're going to need to import an account id type a private key type and in this case we're going to start with a token create transaction these are just kind of the first few apis or types in hedera that we're going to implement we'll add you know some more as we go um and then require from the hashgraph.hashgraph sdk cool and so again your client connection is just your connection to your your to the testnet uh your account id and private key will take these strings from your environment and populate them as a specific type and a token create transaction will be how we actually create a new token on the hedera token service so let's start implementing some of these apis now um we'll just call oops let's write a function i don't know why it's doing that so we have an asynchronous function just calling it main kind of like java does um and the first thing that we're going to do is configure our client so we'll take our operator id is a account id from the string and where we're getting that string from is our process.emp file and and within our env file we named it account id so we can grab that from there and we're gonna do the same thing with our operator key it's a private key from string and finally we can get our client which is a client for the test net and then set operator we're going to pass in our operator id and our operator key so hopefully this is somewhat somewhat easy to follow along we're creating a specific type for our account specific type for our private key and basically saying hedera we want to create a connection to the test network with this account id and this key from there we should have kind of all the client connection and configuration that we need hedera will basically do everything else behind the scenes within our sdk so i think the first thing that we can do here is just create a new token with hts or the hedera token service and how this works is hedera follows a transactional model where you create a transaction populate the details from the api send that to the network the network will come back with a response code whether or not it was successful or failed and from there you can determine um if you might need to resubmit the transaction if you need a higher fee payment something like that and then you can query and get get the receipt of that transaction to confirm its status so we'll start by writing a token create transaction and then maybe after that we'll do an account balance query so you can actually see how you would check if those tokens made it into a specific account so this is a create token transaction and all you do is write a wait because it's an asynchronous call to the hedera network and it's a new object so it's a new token create transaction and we're going to start setting kind of the api parameters that we want for our token so set token name um in this case i'm just going to throw out like wrap heath if you wanted to create a version of ethereum on hedera that you wanted to use for micropayments for example or any other tokens on hedera or tokens on ethereum that you'd like to bring to hedera i'll also set the token symbol here to graph e and because this is going to be a lot of fields i might break it onto another line just to make it a little easier to read it doesn't change anything about how it works you can also set the decimals in this case i'm just going to set it to 10 and set initial supply um this is a kind of funny um one because we can have a fixed supply we can have a dynamic supply it's up to us when we create the tokens um in this case i'll just set a thousand i'll change the decimals to one because i'm not actually gonna need that much space or that much memory and no one's gonna use these anyways and then the final thing is that when you create uh these tokens you have to define a treasury account whether this is your account or a consortium account that's managed by a threshold key you have to say you know hedera i want to create these tokens and i want them to end up here and so in this case i'm just going to put them in my operator id so that's in my personal testnet account so i have full control over these tokens after i create them and finally you're just going to execute this transaction with your client and what that says is i want to create a transaction id i want to pay the fees with this transaction out of my account balance and i want to sign this transaction with my private key so this is great this should be everything that we need here this is kind of like the minimum parameters for the token create api you can do a lot of different things like add an admin key add some compliance features but those are all optional uh so what we're gonna do next is get the create transaction receipt so this is after hedera has reached consensus and determined if this person has enough funds in their account or whatever is going on and again it's an asynchronous function from the token transaction you can get the receipt again you have to execute that with your client and if this transaction was successful it should return us a token id which is a unique identification for these tokens that we just created so i'll just say new token id is the create receipt create transaction receipt and if it exists it'll give me the token id here uh finally i'm just gonna log the receipt and the new token id because we should probably pause and run this and make sure that all of our code is working uh so i'll just say any token id [Music] is our new token id and we'll print it out as a string to make it a little bit easier to read awesome so i'm going to zoom back out so we can maybe see all of the code that we have here in one place everything looks good to me so far the only thing i'm noticing is that i actually don't call this main function within my script but now we should have everything that you need to configure your connection to hedera and create your first tokens so this is great i'm going to use nodeindex.
js we will run this and see if we were successful awesome you can see down here that our new token id is 0.0.30 52.72 you can notice it's the same format as your account id so the zero is what shard it's in the next zero is what realm it's in and then the last number is your address within that shard in that realm and so this means that we were able to successfully create our first tokens on hedera which is super super exciting i think the next thing that could be helpful is to show how queries work so actually checking the account balance and you know how many tokens am i holding and what that will be is adding a new module from our sdk it's an account balance query and we can go down here and [Music] and we can write this uh this query just like we did our create token trans uh transaction it's very very similar in syntax so we'll say account balance query is awaiting a new account balance query and again you just pass in whichever parameters that you would like to populate from the api so in this case the account id that i want to check is my operator id and i want to execute that with my client so again that'll sign it with my my private key and pay any fees that might be associated with this transaction [Music] and i'm just going to log my account balance here just to make sure that it's working and uh i know that the the wrap ether the tokens that we just created actually ended up in the correct treasury account that's an account balance query and you're searching for the tokens within that query and converting them to a string and so these two lines as well as the additional module import should be everything that we need to do to check which tokens are being held in my operator account so that's my account that's in my test net and acting as a treasury so if i run node index.js we should see a new token id which is great and we should see all of the tokens in my account balance and so if i expand this a little bit you can see one of the token ids that we just created is this one oops i tried command and you can see so it's 30 50 272.
uh the last two tokens that are in here 0.0.32 or 30 50 to 72. uh there are a thousand of that unique token uh in my account balance we ran the same script again which gave us a new token id so it ends in a three and you can see that that was also successfully added to my account and i have a thousand tokens in there as well so this is really fun it shows us how we can actually create tokens we can create different types of tokens we can easily configure them with hedera's apis and pass in you know different parameters this whole demo is 32 lines of code including white space and some comments there so within uh you know just a few lines of code you're able to get on board into hedera get your environment set up and do all of those fun things that you might want to do with tokens i only have five minutes left here so i do want to walk through a few things other resources or you know things that we have available for people to use um so in terms of demo applications if you're looking for like a wallet solution my hbar wallet here is a great javascript based wallet it implements all those same apis that we just kind of talked about uh and it does have support for hedera token service so if you're thinking about these apis and want to see what a wallet looks like you can do that or just go straight to myhrwallet.com and see how see how that process works we also have this really great hedera token service demo application so this is if i had a little bit more time i would probably show uh how to set this up and and run it locally but it showcases how you can do fungible tokens uh non-fungible tokens and also implement marketplaces and so matching transactions one of the nice things about hedera is that we support trans transfers between all different types of tokens so any token id can be atomically swapped for any other token as well as for hbar you know the native uh token on hedera and so it should just take you a few minutes to set this up it's uh pretty easy with docker or yarn so i would check that out as well and finally uh hedera's documentation website is really really great uh we have a few tutorials and you know concepts that might be helpful to you but if you just want to dive straight into you know kind of the interesting parts you can go to sdks and the token service and see everything from transferring to creating tokens um and see you know one for one the almost exact code that we walked through uh earlier today trying to think if there's any other resources that might be helpful to share with anyone who is watching this either live or recorded um i believe we also have we have one demo application that already implements a a bridge between hedera and ethereum so i'm wondering where that is um it could be this one or this could be for nfts uh there is a demo application on our github that does showcase uh how you can implement like a custodial bridge between hedera and ethereum so that's something that's relevant to our challenge uh again hedera is giving away three thousand dollars to the best team that either implements the hedera token service that we just talked about uses one of the versions of wrapped hbar that is available on the ethereum mainnet or testnet uh if you have any details or need the contract address or anything about our wrapped hbar please let us know and we can send you that over discord or email or anything and then finally the third kind of option for our challenge is the best usage of interoperability so anything that connects hedera to ethereum in a meaningful way we're really excited to see what everyone builds um and with that i will stop uh sharing my screen and just let everyone know that i'm available on discord for questions thanks everyone
Automatic transcript — names and jargon may be misspelled.