Deploying a Decentralized Website with ENS

ENS Talks · 17:22

A step-by-step screen recording on publishing a decentralised website under an ENS name. It starts with dragging a static index.html into Filecoin Pin, setting the IPFS content hash in the ENS manager and viewing it through .limo gateways. It then automates a Next.js static export with Omnipin in GitHub Actions, pays Filecoin operators to pin the files and proposes the content hash update to a Safe multisig.

Topics

From ENS Talks; community: ENS.

Transcript

In this video, I'm going to show you how to set up a decentralized website on your ENS name. We're going to walk through manually uploading a single index.html file and then automating the process and building an X.js project, uploading that to IPFS, and automatically proposing that as a transaction to a multisig to update the content hash of your ENS name. Let's get started. Okay, so over here I have a cursor project with two directories. One with an X.js JS project and one with a static index.html file. Let's start with this. We're going to locate this file in Finder right here. And the easiest way to upload files to IPFS is via Filecoin pin. I'm simply going to drag and drop

this index.html file. For context, Filecoin is basically an incentivization layer on top of IPFS so that Filecoin onchain cloud operators pin your files to IPFS. Great. So now we have an IPFS CD for our very basic website. And a CI is just a deterministic content hash for a given piece of content. Now I'm going to go to the ENS manager app for this name gest. And we're going to attach that IPFS content hash to my name by going to the IPFS section and typing IPFS slash and pasting that hash that we just got from Filecoin PIN. I'm going to save this which requires an onchain

transaction. Cool. And once that's done, we will be able to access the contents of our decentralized website through a number of gateways. The easiest to remember is gest.eth.limo. We simply add the limo extension to the end of the ensame and this makes it easily accessible in any browser. Now the cool thing here is that there are a number of different gateways which can be independently operated and all have their own kind of um infrastructure. So e.link is another one or eth.sucks is a funny one. And the cool thing is here, you can even run this locally to have fully decentralized access to basically

decentralized websites. Although I'm going to consider that out of the scope for this video because we're mainly talking about publishing here instead of reading. But so now you might be thinking that was super simple, right? It was just drag and drop, copy, paste, and we're done. So yes, it was. But also that was a very basic project. Usually you'll be working in something bigger that has build steps and just more moving pieces. So I have a Nex.js project here and I'm going to walk you through how you'll basically accomplish the same thing but using a tool called Omnipin. Omnipin is a CLI that helps you easily upload a bigger package of files to IPFS and pay the Filecoin launching

cloud operators and basically do everything that we want to do in one file swoop. So, the easiest way to do this is by using OmniPin as part of your GitHub CI/CD. And luckily, they have really great docs for this. So, we're going to go ahead and open the docs and navigate to the CI/CD section and simply copy this GitHub actions template. We're going to go ahead and create the GitHub workflow in our project. So that's just githubworkflows slash omnipin.yaml and paste. Then I'll add some spaces so that it's easier to read.

Cool. And what's happening here is that we are setting up bun, which this repo uses bun to install dependencies and run commands. We're going to install the Omnipin CLI and we want to make sure we get the latest version which at the time of recording is 1.7.0 and then we are going to build the website and deploy the website. Now GitHub workflows run from the root of a project and over here we want to actually build the next.js project. So cursor guessed it we first want to navigate to the next directory before installing dependencies and building the project and then next.js JS will export that to a static out folder um within the Nex.js directory as well.

Before we go ahead and enter the environment variables, I'm going to delete everything for now. Um I want to point out that Nex.js by default uses server rendering which is not supported by IPFS. So the key change that we have to make is by going into our next config file and adding this output export option. This is what will make the static out folder over here. And so just to show you that I'm going to open the terminal, go into my next directory and then do run build. And over here we will see in just a second that I get an out directory with my HTML files. And this is the static website that IPFS knows

how to handle perfectly. Cool. So we have the beginning of our GitHub workflow set up. But you'll notice one thing when I want to upload with Filecoin pin, this is using their test net. And so data doesn't actually stay pinned for a long period of time. But we want to use mainet in a production workflow. So we need to actually add different tokens to a wallet and add the private key to our omni pin config so that it knows how to pay the filecoin onchain cloud operators. Let's see how to do that.

So these docs are actually a little bit behind. The only environment variable we need is this omni pin filecoin token. So, I have thisinvview file set up already with a private key that only has a dollar on it. It's okay if you guys steal it. Um, and this is what's going to actually pay the Filecoin onchain cloud operators to pin my content for a long period of time. I'm going to show you that I've already added one USDFC and a tiny amount of Filecoin tokens to this wallet so that it can pay for these things. The easiest way to do that is by using Squid Router you can find linked

from the Omnipin docs and they allow easy bridging from you know USDC on base to Phil tokens on Filecoin or to USDFC on Filecoin. So your wallet will need a little bit of both. It will need less than one fill and say one USDFC to have you running for a little bit of time and you can kind of top up as needed. So in order to give omni pin access to that we have to set it as an environment variable and really we want to set it as a GitHub secret.

So now this will give omni pin access to this and the last step is that we need to actually enter it securely in our repo. So this is a repo I have set up for this demo. And if I navigate to settings secrets and variables actions I can see repository secrets. I'm going to add the secret for omni pin filecoin token and I'm going to paste the value of my private key. Remember, this should be a brand new private key that you haven't used for anything else. It should be fresh and have no more than a few dollars in it. My favorite way to create new private keys is by using Foundaries cast CLI. So, you can just do cast wallet new. And this is a brand new

key pair that um I used to generate this just this morning before I added a dollar to it. Cool. I'm going to go ahead and save this secret and then we can push our changes. So add omni pin workflow. Let's commit and push to GitHub. Great. Now if we go over to the repo, we will see that a workflow should start running in just a second here. There we go.

And this workflow is going to set up a bun, install Omnipin, build the website, and then eventually deploy it to Filecoin using Omnipin. Let's see if it works. Great. It looks like that uploaded successfully and our file was deployed to IPFS and operators were incentivized to pin it so that it stays around. Now, one more step. We have this hash over here. And this should bring us to our Next.js project. Sweet. Now we have our Next.js static project deployed to IPFS and accessible through a number of gateways. We have the CD and instead of manually going back to gesteth

and manually updating the content hash, which we certainly could do, we are going to have Omnipin automate that part of the process as well. Let's look at the Omnipin docs to figure out how to do this. So under CLI reference, let's go to deploy. And we'll see some of these settings for setting an ENS name with a safe. And the ENS name is basically the name that we will be updating the content hash for. In our case, gesteth. And the safe is the address or name of the safe that owns the name. Because what will happen is omni pin will propose a transaction to the safe to

update the content hash and then the signers of the safe will go ahead and execute that transaction. So actually before we set this up let's transfer gesteth to a safe and the safe that we're going to use is the enslabs devril safe. So I'm going to go ahead and transfer gest to devril.en enslabs because we like to name our wallets. I'm not going to reset the profile just for simplicity. And let's go ahead and transfer this name.

Great. So now the owner of gesteth is devrell.labs. And then one other step is to enable the ability for our private key that we generated before to propose transactions to the safe. And the way we do that is by going to settings, scrolling down, and we have this proposers section. Now, because we already deploy the ENS docs to docs.ns, um, I already have an omni pin roll, but that's obviously a different private key. So, let's go ahead and add the one that I've been using for this demo so far.

temporary demo signer. Ah, whoops. I pasted the private key instead of the public address. Rookie mistake. Okay, I'm going to confirm that. Great. And so now we have a new proposer to the safe. So let's go ahead and just finish the CLI setup. Omnipin deploy and there are two new arguments the ENS name will be gest and the safe will be devrell.nslabs and we now have to give omnipin access

to one more environment variable which is omnipin_pk. This is the private key of the wallet that will be proposing transactions to the safe. So the private key to the public address that we just added over here. In our case, we're going to use the same one as the omnipin filecoin token just for simplicity. So I'm going to copy this key here. Omnipin p key. Go back to GitHub and add another Whoops. And add another secret like we did before. This time omni p key. And the value is the same.

Great. And now if I go back to look at our GitHub diff, the only diff is that we have an ENS name and a safe. And then on the safe, we added the private key as a proposer. And in the GitHub repo, we added the private key as a secret. So putting all these things together, let's say add ENS deployment commit and push to GitHub. Now if we go back to GitHub and refresh, we should have a workflow running again.

This time the deploy the site task will upload it to IPFS but it will also propose a transaction to the safe and we are getting an error saying omnipin PK is missing. Ah, okay. So, I made a mistake and actually didn't give omniin access to the secret that it needs. Um, which is, you know, my mistake. And so, now I've added this here and we can say update omni pin workflow and push those changes to GitHub.

Now, if we go back and let this run once more over here, it should finally work. Great. So, our files were uploaded successfully to IPFS and then it looks like there was an issue preparing the transaction to our Devril safe. Ah, okay. So, I'm keeping these errors in just to show you the reality of um you know fixing these. So, I think what happened is that the name resolution for devrell.labs is not working correctly. So, I'm going

to replace that with the full address. And hopefully this will be fixed by the time you actually go and implement this. Um fix safe address. Cool. And now let's go back to our actions one last time. Nice. Okay, so it looks like everything worked successfully. The content was uploaded to IPFS and then a transaction was proposed to our safe where we got a nice link. And over here, great. I can see a proposal from less

than a minute ago to set the content hash of this name, which should be the real name for gest. Let's see if that worked by confirming the transaction. In a production environment, this would probably be a multisig with, you know, a two of three or a three of five serer depending on the seriousness of the project that you're working on. But for this it is just a one of n and so I can go ahead and execute the transaction directly.

One thing I'll note while this is processing is that I currently have this configured to run on every push to main. This might not be the best way to use it in your project and instead I would encourage you to check out different push triggers. So there's a manual trigger, there is a cron trigger and then there is branches and pull requests. So depending on however your team works from a workflow perspective, you might find different success. But great um it looks like that transaction succeeded setting the content hash of the name. And so if I go back to gesteth, then you will see it has a content hash.

And now if I go to gest.e.limmo, limo. Instead of seeing the old basic website, I should see the create next app. And it looks like that worked successfully. So, brag.eth.link should show the same. gest.sucks. I guess it is cached for a little while. Oh, there we go. A hard refresh gives me the same result. And here we are. So that is an end-to-end walkthrough of automating the deployment process of a static website to IPFS and securely updating the content hash of your ENS name. I hope you enjoyed this walkthrough and let us know if you have any questions. We're excited to see you

on the decentralized

Related talks