Why You Should Write dApps in Go - Lav Leon Hudak | gno.land
ETH Belgrade Community·Tue, Oct 7, 2025, 12:00 AM
Why You Should Write dApps in Go - Lav Leon Hudak | gno.land
Transcript
Hey everyone, it's uh nice to see everybody uh uh join this presentation. I'm very uh glad to be hosting you here and talking about why you should write uh DAPs and Go. Uh my name is Leon and I'm a developer relations engineer at Noland. Uh I've been in web 3 for about four years and um I've been writing DAPs in Go for for for the last bit and I want to talk to you about it. So um essentially this is going to be the agenda.
It's going to be kind of short and this is a bit of a joke obviously but uh we're going to talk about what is Go um how we can write an app in Go. U then something in between and then we're going to have a complete app. Uh and essentially uh first of all what we need to get started with is uh what is Go and like why should we care about Go as a language. Um essentially Go is a general purpose uh compiled language and it is uh been around since around uh 2009. It was open source in 2009 but uh Google built it in around 2007.
Uh it's kind of like a successor to C. Some people call it uh the C of the of the 21st century and it's statically typed. So um it's a hard type language and uh essentially the question is why again should we care about go? Go is used to build backend services. It's used to build protocols.
For example, some of you may know about GU. It's a go Ethereum. It's a Ethereum client that's building Go. Uh it has a great standard library and also uh an amazing set of tools to work with. And uh but most importantly I think one of the biggest reasons about you know why we should care about go itself is that it's uh super easy to learn right uh it has a very straightforward uh very easy learning curve and uh it has lots of battle tested libraries as well as resources by a large dev community right it's been around for what 16 17 years right so it's so easy to learn actually that I'll actually show you and I'll let you learn a little bit about go uh right now.
So, we're going to do a little bit of live coding uh where I'll just kind of give you the really really big basics on what Go is and how it works. So, here I created a very simple folder. It doesn't have anything special except this post.go file. Let's actually remove that.
Uh let's do this and do touch main.go. Um and then we're going to define a package called main in which we'll have funk main. And I'm assuming most of you guys understand this. So it's uh relatively relatively simple uh syntax.
It's quite familiar, right? Anybody who's written any sort of uh general purpose language will understand this. And then we'll do fnt dot print uh line and we'll say hello bellgrade, right? So I guess most of you guys uh know what this is. And uh here we basically say like uh we're using this fmt package which is format.
It's used for formatting stuff. Um, and we're going to print a line uh saying hello world. And again, go is compiled. So, we have this go uh binary. If we do go version, it's going to plop out that it has that it exists and it's it's 1.
24. Uh, and what we can do is we can do go build and we give it the current folder. And then we get a executable file. Uh, and we can do this and run it. So, that's one way of doing it obviously with a with a binary.
Uh, but another way of doing it is doing go run main.go go which is just like a basically a a uh a command that integrates two things. So it builds and runs your uh library and there we go we get hello bellgrade. Okay cool. So I defined something here at the top uh called the package right and package is basically a um organizational unit of code for go.
So let's create another package. Let's try to do something else. So let's do make there um social. Let's call it social. And in this social uh folder, we're going to make another uh file.
Let's call it uh social.go. Uh and then up top here, we're going to uh do go mod init. And this is going to be a um this is a way of tracking dependencies essentially in Go. And uh we'll you'll see why why we did this go mod in it soon.
but in this uh new package that we're doing. So imagine that this is something that you'll be able to share around and uh and um and uh basically reuse as a as as a piece of code modular modular piece of code. So package uh social. Okay, let's do this. And now uh let's imagine that we want to make a um a very simple social media application.
Okay, so let's talk a little bit about like how you would do it in Go and then what are some of the ways some of the things you would need to do and define. So let's just say like we have this very basic uh strct called post and then uh we'll be able to save these posts and also view them and then uh create new ones etc. So for example the way we would start with this is we would do uh type we can define a new type called post and it's type strruct right so it contains some things inside of it and it has like a text right uh then it has like an author author oops that's an automatic import never mind so an author let's make it a string and also has like a created at like when it was created right um and this is time so this is a built-in uh or one of the one of the standard library packages for Go. So, uh this is a quite quite a familiar thing if you if you know any Go. Um okay.
And then uh let's actually export these. So the way it works in Go is uh when you have a capital letter at at a definition of a variable or a function. Essentially what what happens is um that thing that has a capital letter, it's named with a capital letter um is exported outside of the package. It's visible outside the package. It's public, right?
Uh so we have this post and it has some some data inside. Okay. Um and then let's say we can do like funk uh create post or new post. Let's call it new post. No, let's call it create post.
Uh create post. And let's make it return a pointer to a post. Okay. So it's just returning a piece of data uh that's going to be packed in with the with these, right? So let's say that it takes some text uh and it takes an author.
Okay. and let's just return the pointer to a new post. Okay, so we're creating a new post in memory and we're going to say okay, the text of the post is the text that we pass in. Uh oops. All right, bit clumsy there.
Uh so text equals text and then author let's say author. So whatever is passed in and then time or created at is going to be time.now. So um what this does is basically gets the the execution environment right and it checks what the time is at the point of calling this function and then it just writes it down right so so this is a this is quite simple syntax okay so let's let's do that uh then let's go back to this main file and let's say that we want to actually like use this package in some way so what we can do is we can do social dot and then we can do create post and you see it's going to automatically import this um uh uh social package which we have uh oops right here right um and the logic is that uh by doing this packaging right you can organize code better right and you can have it imported on one one place and exported another place etc so this is kind of the way we do things in go okay and let's say um uh what we can do in go as well is we can say uh var so we're defining a variable post uh and we can say social post so this is getting the type right from the other package from here Um, and then let's actually make it a pointer because that's what we did over there. And then what we can do is we can do post equals uh post uh social.
create post and then give it um my first post, right? And then we also need to give it a author. Uh so let's say Leon for example. And then what we can do is we can do fmt.print line post dot for example text.
Right? So, so we're making some memory and then we're just printing out printing printing it out to the to the standard output. And also, um the editor here is saying like, hey, you can actually um do something else here. You don't have to do that. You can just infer the type because go knows that when you call this function, it knows it's return type.
So, it's hard type statically typed and it knows that this here variable is actually uh of type post, right? Or pointer to a post. So let's try to run this uh go run main go and there we go like we actually got something right. We can also do uh we can also do something else like for example showing that um we can actually do the address of this and it's going to print out an address for anybody who who knows what pointers are right. So this is some basic go.
Okay. Uh let's add one more thing here and that's going to be like a way to view posts. Okay. So let's call it view posts or view. Yeah view posts.
um and then um here for example we'll be able to pass in um a list of posts let's say post post and then it's going to return like a string or something right so like we want to actually be able to um get get some slice that has data and then just print it out to the user okay so let's say okay let's have some out uh which is going to be like posts And then let's add some new lines here. Uh and then let's actually go through this posts. Uh so P in range posts. And we also need an I. So we're going to iterate through this slice or array as it's called in in Go a slice.
And what we can do here, we can just do um um out plus equals. So we're concatenating strings. Uh let's say string uh let's actually do fmt. So um fmt allows you to do um string formatting. So sprint f is a function that you can use.
And we can say okay. So we're going to have the post um number. So post number something, right? And then let's do a new line. Uh and then let's do text.
Oops. Text. And it's going to be a string, right? And then let's say here I and then let's do P do text. And then let's add the rest.
So this is going to be the author and then this is the author. And then this is the created or let's say date. Yeah, that's easier. P.author and then P dot uh created at.
But this is a time dot time. So what we need to do is we need to actually do a format on it and let's say um um 02 01. So 2nd of January 2006. This is a standard way of doing it in go. Uh okay.
And then we do return out right. So we're we're passing in some some slice a list of posts, right? And then we're we're actually like just printing them out to the user. So this is a way of displaying what's happening in our application, right? Um so let's let's try to do this.
So let's actually do a couple of these. Let's do one uh post one uh 012. Uh let's say this is my second post. This is my first post by Alice, let's say. And then what you can do is you can say um var or let's say posts column equals and this is going to be a slice.
So we're making a slice of uh of pointers to post. So this is going to be social.post post and we can say post one like this. Post one, post zero, post one, post two. Okay.
And then what we can do is we can say okay um so from the social package we can do social dot view posts and we can pass it the posts and then we do fnt.print line like this and then let's actually run this and see what happens. And there we go. We actually get uh we actually get these posts, right? But the issue is well, what's the issue?
The issue is that everything that that's happening here in this application, right, is it's just ephemeral. It's not saved anywhere. It's just in memory. When I run it, it happens and it's gone, right? Um so but okay, so we we've kind of made something, right?
We've made a a very small social media application. Not really, right? But uh it's kind of something. It's kind of looking like something. So imagine that like we now want to make u actually like make a business from this right we want to we want to do an actual social media application um the thing is that um there's actually a bunch of steps in between this and actually launching an application a full application uh for example u think about okay well uh first of all we don't have a place to store our data right where do we store our data that means we need a database okay so let's let's make a database let's take let's make a model for a database right let's run the database somewhere let's push it to some server, right?
Or or some cloud. Let's put it somewhere. So, that's step one. Step two is then, okay, well, then we need to define an API, right? Okay.
Well, what's what's the API going to look like? Blah blah blah blah blah, right? You get the point. It's kind of complicated to do these things. Even though, of course, there's shortcuts and you can you can use pre-built stuff and everything, but overall, when you look at the tech underneath, it's it's relatively complex.
You have to do a bunch of stuff, a bunch of different stuff, and you have to diverge from writing this simple language called Go. On top of this, for example, at one point you'll want to write a front end, right? And then you you got to do usually you got to usually do that in uh in JavaScript or TypeScript. So it's not the most fun experience. Uh but okay.
Um so I kind of showed you just a little bit about Go and how it works. You kind of got the gist of it. Uh so let me now go back to the presentation and uh yeah. Well, let's say okay, so what if we had automatic persistence? What if we had language- based app features?
So instead of having to make this thing called an API and have instead of having to you know run a server and exposing endpoints and doing this and doing that what if you can just have exported functions be the API right or the methods right be the API okay what if you can just have top level variables so defining a a variable at the top uh which is going to represent uh a database for you or like the state of the application right so you don't have to care about creating all these separate systems are going to have to interconnect them and then you have something like an app an app. It's it's a bunch of different things, right? In this case, it's just one. Uh it also has built-in security. And obviously, like we're we're talking about blockchains here.
So, um built-in security, decentralization, they come together, you know, they they come as a as a as a as a bonus. Uh and then also, well, this is kind of a really nice thing. You can have an easy to make front end. Um and then one CLI command to publish uh the app, right? So just imagine how much more simple that is uh compared to all of the things that we talked about previously.
Having to deploy all of these services, having to make sure that everything is secure, having to make sure that uh the design is good, etc., etc. And then also having to pay for uh for the hosting for all these services, etc., etc., right?
So well, basically all of this, well, we uh kind of have it with something called GNO. Uh and uh essentially this is GNO. And you kind of see that it kind of looks like what we just wrote in Go U or basically identical, right? So here on the left we have uh a package called Alice. Let's say Alice made this package.
And on the top she defined a variable called X and uh it's an int and then she defined a getter and a setter, right? So nothing special, very very simple. Um and then on the right here we have Bob who's saying, okay, well Alice made an application and she exposed some functions. So she exposed the getter and the setter and um that means that I can access it because we said that exported functions by by the virtue of the language right are APIs. So we import the package called Alice and then we can just do hey Alice.
get which is that and then we do Alice set and then we set it right so that's kind of the logic. Okay that's interesting. Uh, a little bit more about GNO. Uh, so it's modeled after Go 118. So it's a little bit of an older version of Go, not like super old or anything, but it's, uh, it's it's not the most up-to-date one.
Uh, it's interpreted instead of compiled, and there's a reason for this. And it does not support all of the features that Go has. Uh, for example, generics and Go routines. Uh, for those of you who know, um, go routines are are a way of doing, uh, things concurrently, which doesn't really make too much sense at this point in blockchain systems. And uh all apps everything that's deployed to this uh blockchain network called Noland is uh is ided by something called a package path.
So it's kind of like the place where your application lives. Okay. So this is kind of like a very very simplistic way of saying what a what a package path is. There's a there's a namespace. So for example my name or like imagine GitHub right?
You have a you have a namespace and then um and then you have repos under it. Uh and then you have the app, right? the the way you identify the specific app within your namespace. And then on the left there, there's some other stuff, but it doesn't matter really uh too much uh right now. And uh basically why I'm telling you about these package paths is that uh okay, so who knows here uh about how you deploy stuff on Ethereum.
Okay, good. Great. Okay, nice. Uh yeah, so basically when you deploy you get a random address where your application lives, right? So it's randomly generated.
you can kind of play around with it in some weird methods, but essentially for all intents and purposes um when you deploy something to Ethereum, you get a random address where your application lives. Uh in this case, it's not like that. Uh it's uh you can define a specific name essentially for your application, a specific path for your application, kind of like a file system, right? Kind of like an organizational system. Um and why this is important, it's because we have this thing called GNOIB.
And this is like a very special tool that we built. Um, and it's essentially the universal front end for Noland, for the blockchain, for any app on the Nolan blockchain. Anybody can run it because it's open source and uh and it's super easy to run. And it uses a pre-built query that's built in, you know, it's built in into the into the um uh into the app. And it basically says, hey, like when you browse for this app, you do a specific query and then you get the state of the app.
This is why you don't actually need to write any JavaScript or TypeScript. you can just write no code and you'll see that in just a sec. So this is a very basic diagram of like how this essentially works. So I'm the user over there. I'm looking for this Leon/ app application.
Uh and I ask nob hey like can you fetch me this application uh via a search bar essentially I'll show it to you later. And then gobb says hey can you query app.render and then the network says yeah sure here's the state and then uh gobb because it's a front end displays it to the user. That's a very basic way of doing it. Um, so like this talk is named uh writing DAPs in Go.
But like where is this DAP? I haven't seen it yet. Uh, so so this DAP is uh right here. Actually, we kind of wrote it already. Uh, what we're going to do is we're going to delete this.
We're going to delete this and then we're going to do uh cd social uh mod init. So previously we did go mod init. We're doing go init. So this is the the the GNO version. Let's call it uh Leon Mini Social.
So, this is the thing on the on the left that I mentioned, but it's not really important uh at this point. And we get this GNO mod file. And then what we all we also can do is let's rename this. Where is the rename? Rename.
There we go. And let's just do GNO. Okay. Awesome. So, we have GNO code.
And this kind of works already, but what we're going to do is we're going to change this to uh render, which is what GNOB is actually expecting. We're going to do underscore string here. We just don't need this variable, but the signature needs to be like that. And then another thing that we mentioned previously is that uh these top level variables, right? They're specifically used for um being able to state uh to to store state of your application.
So what we're going to do here at the top, we're we're going to say var uh posts and it's going to be a slice of posts just like previously, right? Uh of posts. Yeah. And then one more thing that we need to do is we don't have fmt. We have u fmt here which is a replacement.
And here it's it's automatically imported because the the the editor actually knows uh how all this works. Um and then finally one thing that we're going to do here is because essentially when you call this it kind of returns a pointer to you but where does that pointer go? It doesn't go anywhere right? Like the memory is just like poof. It just goes away right?
So what we're going to do here is we're going to do P which is going to be the the the post and we're actually going to do posts equals append. This is the way you actually save something in a slice in go and we just append it here. So instead of like returning the pointer what we're going to do is we're actually just going to save it to this slice that we defined up top. Okay. So and look look this is essentially the app.
That's it. There's nothing else like we don't have to do anything else. Uh and how we're going to run this is I'm going to use a tool called Gnudv which is really really cool. Uh for everybody who knows you know Ethereum you kind of have these local environments where you can create a local blockchain. You can publish to it.
You can play around with it mock stuff. Uh in this case we have a tool called GNODV again which is a very very cool tool because it's a it's a um essentially it's not an all-in-one tool. It's a development solution stack. That's a better way of naming it. It contains a couple of things.
So here you see it contains Gnow web which we just talked about and it contains the node right the local blockchain node um and it essentially what it does it's also really really cool it like auto deploys stuff for you so uh you can click on this uh listener here for no web and you can actually open it and this is our app like it's it it browsed for our app and it found this at this location on the local blockchain right so let's kind of make this a little bit nicer the really cool thing about this is that also has a hot reload feature So what you can do here is you can do like hashtag and by the way you might have noticed that this is markdown. So what you're doing is you write markdown and then you just it just kind of pops up right. Um so let's say for example here let's say if posts.len uh equals z um out plus equals no posts yet and we're sad about it. Right.
Okay. Okay. And then return out. It's going to reload, right? And then there you go.
Right. So we're literally writing a front end in. Okay. So we don't really need to write anything else except this. It's really really cool because you know when you look at it uh compared to a traditional application um you would have to write all of these services and deploy everything and make sure everything is tightly tightly you know working tightly together and and it's secure and everything.
With this you just write no code poof publish it and it's it's right there. It works and it's great. Um, so yeah. Uh, okay. What else?
What else should we add? So let's let's add something else. Let's do like a funk. Uh, this is a cool thing in Go. You can define uh methods on top of strruct.
So um we can say like let's let's make a string uh um function or method for um for our post, right? So instead of having to do this, right, we can just take this and we can do P dot uh string, right? Just making it a little nicer. Uh outpring and then before that uh what we're going to do is we're going to do out plus equals uh post number whatever, right? Uh plus string uh com dot okay of i.
Uh, and then let's do some new lines right here just because that's the way markdown works. And then we just slap this on. And then here we can post this. We can do uh return uh return. Okay.
And then let's just remove this part here. So this is basically rendering the the the the post, right? And we kind of modularize it this way. Um, and let's see what's happening here. Unknown.
Did I make a No, I just need to import it. Okay. I don't know why it's complaining. Looks good. Okay.
And now let's actually do something really cool like let's actually publish something. Okay. So, let me call So, here on GN Webb, this is also another really cool thing. Um, apart from GNO web itself, we have a tool called Gnooki, which is kind of like a um it's not kind of, it is the wallet that we use in GNO. And here we can like post in uh for example uh the text uh my first post and then call it Leon.
And let me actually just post this. So it gives you a pre-built command that you can just slap into your terminal and um and run it. And we get an okay. And then we go back to the app and we see hey there's something here, right? That's pretty cool.
Uh let's let's make it a little nicer. The also another really really cool thing is that even though nodev like does a hot reload, it actually saves the state of the blockchain before it does it. So it's like super super nice to actually work with because you can do this. So let me do another new line here and here and here. Okay.
And then let's do like for example a triple dash which is going to give us like a not that this. It's going to give us like a like a like a I don't know how you call it like like a bar. Um, and let's do like H3 here for example. Okay. And then it looks a little nicer, right?
And then let's do another one. Uh, let's do another post. Uh, let me change this here. Let's do my uh my second post. Yep.
And there we go. It's right there. Okay. So that's that's this is kind of like the thing is this is actually like a full social media application. Not really full, but like this is the basic concept like it's a PC and anybody can copy it and this is what like it's not even like 50 lines of code.
It's like super nice to to do this. Um and there's a command that you can do with Ginoi uh which would be uh make tx add package uh add pkg which is basically just publish the package to a blockchain. Right? So that that's what I meant when I said um this is the only uh the only the only one command that you need to publish natural application instead of having to spin up all of these services. Um I want to do one more thing here and that is you see here we're kind of passing in the author but uh that's not really realistic especially on blockchains you know you would want to get whoever made the transaction right so let's do that let's just change this and here we actually have something uh we have a package called std which is a super important package uh for go uh and then we can do previous realm uh address uh and we don't need to convert it to string maybe we do string okay all All right, that's perfect.
So these are transactions failing because we changed the the um the number of um arguments in the in the function. Uh let's go back here. Okay, so there's no post now. And then let's say create post. Hello.
And then we can copy this, paste it here, run it. And there we go. Like the author is me. So this is the no address that I use. And uh yeah, that's that's kind of the gist, you know, like like you we just made a we just made a basically a very basic application that anybody can use and publish.
Uh and it's like 50 lines of code. We didn't need to write any other language or anything. We just published this and people can actually use it as a decentralized application for for um um like a Twitter, right? So I think that's really really cool. Um but I'll let you guys be the judge of that.
Um, what do you think about this? You like this? I mean, is does it look cool? Does it look simple? Yeah.
Okay, that's cool. Uh, very nice. Uh, there's also a bunch of other things I could show you, of course, but uh let's not do that right now. Uh, what I want to do is finish this presentation here. So, let's just jump back in here and let's just talk a little bit about what the tooling what the tooling what tooling we have and the ecosystem that we have currently.
Uh, so we have Gino, which I just showed you. It's the wallet, the CLI wallet that we use. Uh we also have a web extension wallet of course uh that's called Adena. We'll talk about that in a little bit. Uh we have GNODV uh which I showed you um uh previously as well.
It's used to uh basically run a local blockchain node. It does a bunch of really cool things. One one thing that I didn't mention is that you know like every uh every um every transaction needs some gas, right? So the idea is that um how did I get gas on this local network for my specific address? Well, godev is really really smart and actually gets the key base that you use uh in your um in your Gnooki wallet and it premines things to it.
So, it's it's uh it's super practical. Uh and it has obviously a directory watcher with uh with automatic code reloading. Um we have something called the TX indexer. This is a this is a blockchain indexer which uh has a GraphQL API and it's super super fast and practical. We actually like did a did a 10x on its speed some time ago.
It's like super nice. Um, we have the no playground. If you want to test out no, um, just play around with it, do some stuff, deploy through, uh, the web. Uh, you can just go to play dog.no.
land and then actually, well, do this, right? Um, well, you can actually deploy the whole application through uh through through uh the playground, which is really cool. Uh, and then this is kind of our ecosystem. We have some more things coming in obviously, but uh there's Adena, which is the the um um the uh the browser extension wallet. We have Gnoscan which is the the blockchain scanner.
Uh we have the native kit. Uh we have gnos swap. We have uh javascript and typescript client. Uh we have territory which are partners and they have um built a couple of applications on top of the go and blockchain. We have lupando uh and obviously more of them.
Um we we actually have we have uh well yeah the native kit is really really cool. for example, it's it's a way of doing uh GNO but on um as React Native, right? So so um as um mobile applications uh and then here's some opportunities here. Um what we want to do is like we we're actually inviting people to be uh the first or you can read it as early right uh to build useful applications uh and work also on the protocol level problems that we have. Uh so you can actually make a very big impact on the future of no end.
Whoops. Sorry about that. Still good. Yeah. Okay.
Awesome. Um and obviously if you're um looking to start a regional community or like a local community, do meetups for uh please reach out to us. This is a link tree. It has a bunch of links. So if if you do want to take a picture of this and uh we can stay in touch.
Uh this is me. If if you need my X or GitHub, it's just Lo and then triple H and then N. It's the same on GitHub. Uh, and I'll give you something else. Oh, are you taking a picture of that or?
Yeah. Okay. Yeah, no problem. Yeah, I have a nice face. Um, if uh one thing that I really want to ask you guys is please take two minutes to just scan this and uh and just give a little bit of feedback about uh today's presentation.
So, I'll just leave that up. But uh before that, before we end the presentation, uh what do you guys think? Uh what are what are thoughts? Do you guys like this? Was it too hard?
Was it not too hard? Uh, do you have any questions about it, please? I'm listening. Okay. Okay.
So, everything goes crystal clear, right? Great. Awesome. Uh, well, thank you so much for coming. I'll uh we're about 30 minutes in, which is perfect.
That's exactly what I wanted since it's uh it's almost 7 p.m. And uh thank you guys for coming and hope to catch you somewhere else.
Automatic transcript — names and jargon may be misspelled.