Loading video player...
Hey guys, welcome back to the channel.
Today we're going to be building our
very own ERC20 token from scratch in
2025. This is an updated version of my
earlier ERC20 tutorial from a couple of
years ago, refreshed for the latest hard
hat and solidity tooling, as well as
using the latest Ethereum test net. As
you guys probably know, ERC20 is the
gold standard for creating
cryptocurrency tokens and powers
thousands of tokens on the Ethereum
blockchain. We'll be using hard hat,
Typescript, and Open Zeppelin to create
a simple fixed supply token with permit
support. We'll deploy it to the Sapoleia
testnet, verify it on Etherscan, and
test it using our MetaMask wallet. So,
by the end of this video, you'll have
your own token running on the Ethereum
blockchain. The full repo with code and
complete setup instructions will be
linked below. So, let's dive in. All
right, prerequisites. So before we
start, I want to make sure that you've
got NodeJS installed version 22, which
is what Hard Hat requires. So I you can
either um download that straight from
the Node.js website or I highly
recommend you install Node version
manager or if you're on Windows NVM
Windows uh which just makes it really
easy to switch between different
versions of Node. You can have several
different versions of Node installed at
once and pretty easily switch between
them if you need to for different
projects. Uh so once you've got that
installed you can run the following
commands to install version 22 and just
verify that that it's working and then
npm that stands for node package manager
which is included with node. So if you
install node you'll have that as well.
All right with that let's move on to the
build.
Okay guys let's get started with the
build. So for our token build I've got
this starter repo in my GitHub right
here. And we're still going to build the
token from scratch in this empty token
build folder. Um, however, in the
interest of saving a little bit of time
and keeping the video length reasonable,
um, we've got this completed sample
token here, and we're going to take a
couple of key files, uh, and copy and
paste them into our token build and then
edit them, uh, according to our needs.
All right, so let's start by cloning the
repo. So, I'm going to go over here and
just grab the repo URL. Then I'm going
to open up my uh code editor of choice,
which in my case is Visual Code. And I'm
going to go ahead and open it into my
workspace. And then what I want to do is
get clone and then paste that repo URL.
And that'll give me the uh the cloned
repository. So now I'm just going to cd
into the main directory here, which is
ERC20-ken-
[Music]
2025.
Okay. And if we expand that top folder,
we see we've got two subfolders. Um, as
I mentioned, token complete. That's just
an example of a fully completed working
token. Uh, it's my token. That's what
it's called, my token. And then token
build is where we're going to build our
new token. So, let's go ahead and cd
into token build.
And then what we're going to do is we're
going to use hard hat uh which is web3
tooling infrastructure to scaffold our
project to basically create an empty
project um from which we can write unit
tests. We could have our source code of
course for the token and also do
deployment. So, it's a very helpful tool
to kind of have a fullyfledged
professional project as opposed to just
writing the Solidity script for the
token on Remix or something, which you
can totally do as well. But, um, this is
sort of the full-fledged way to do it.
So, what I want to do uh to get that
process started is npx
hard hat-in.
And that'll bring us through the uh sort
of wizard to scaffold our project.
Okay, so let's go ahead and walk through
the scaffolding process using hard hat.
So I'm going to do npx
hard hat-in
to initialize a new project.
Okay, let's go ahead and use hard hat
version 3. Um, go ahead and use the
default for the absolute path. And then
what we want to do is uh select
TypeScript with Mocha and ethers.
Um, yes, we do want to override this git
ignore.
And then we want to install all the
dependencies that it's suggesting here.
And that'll pretty much give us all the
dependencies that we need to create our
token. Well, there's two more things
we'll install right after this.
Okay. So, once that install is complete,
we can expand the token build folder and
see that hard hat has scaffolded a new
project for us. It's created a bunch of
um files and folders right here. And so
what we want to do now is uh install two
more things that we'll need. The first
one uh is the Open Zeppelin contracts
library. So Open Zeppelin um you know
these contracts will pretty much form
the basis of our uh of our token. And
then the next thing we want to install
is npm. You can do I short for
install.env.
And that's just a small library that
will help us um be able to read
environment variables from our env file,
which will come in really handy for this
project. By the way, um all the steps in
this entire project, as well as all the
commands are documented right here in
this top level read. So in case you ever
need to reference that, um if you ever
feel like going through the steps here,
uh or copy and pasting anything, you can
find pretty much everything that we're
doing right here. So just for your
knowledge.
Okay. So the next step uh what we want
to do is go into token build and create
a new file
env. Okay. So this is going to be a file
that holds our environment variables.
Now if we go under token complete and
expand that there's a ENV example. And
if you open up that file, you can copy
and paste all the environment variables
names into the oops into the new env
file that you created.
All right. Now, um, what do we have
here? The the Solia URL. That's
basically the URL that we're going to
use to connect to the Solia test net
when we go to deploy our token. So, what
you want to do here, there are a bunch
of um different options, third party
services such as Infura or what I now
I'm suggesting um, Alchemy. And what you
need to do is create an account with one
of these services. Um, I would show you,
but I don't want to kind of expose my my
secrets and my API keys. But if you log
into Alchemy, um, click on your project
name, you'll create a project for this
token. Or it doesn't have to be token
specific. Like I have block explorer
project that I'm going to use for a
bunch of different projects. Anyway, you
click on your project and in the lefth
hand menu there is a um,
what is it called? Endpoints. So click
on endpoints. From there, there's a
dropown. You want to select Sapoleia and
then you copy and paste the entire uh
Sapoleia endpoint URL right here. Okay.
Private key that's coming from your
MetaMask wallet. So, if you click on the
top right hand side of your wallet and
click on accounts and then click on
private key and it'll let you copy and
paste your private key. Um, Etherscan
API key. We're going to use this to to
validate our contract in Etherscan. This
is an optional step, but really good
practice. So it it's kind of similar to
Sepia. You want to go out to Ether Scan,
create an account, and then find your
API key in your account settings and
copy and paste that right here. So word
of caution, um especially with your
private key, you never want to share
that publicly or expose it in any way.
Um you don't want to commit it to your
code repository. So, if you look in the
git ignore,
I've got to fix this actually, but you
want to make sure that you've got env
Oh, I know why it's
Yeah, I I've I've got it in the
completed token, but in the new token,
you've got to add it yourself at the
very top. So we can say, you know,
environment variables. And so as long as
you have this uh envisted here, that'll
ensure that you never accidentally check
it into your uh your remote repository.
Okay. So let's go ahead and copy over
the other key files that we'll need from
token complete. Uh let's start with the
hard hat config. So if you open that up,
copy it, and we can just paste it
directly into our hard hat config from
our new token project,
right? Go ahead and save that.
And then let's copy over our actual
token contract. So it's under token
complete contracts, my token. So go
ahead and copy that. Now, if we go back
up to token build contracts, you see
that there's a couple of contracts here
already. counter. Those are just example
kind of hello world um smart contracts
that hard hat scaffolded for us. So
let's let's create a new file. And you
want to name this whatever you want your
token to be called. So just to uh
continue from my last video a couple of
years ago, we'll stick with ocean token
and the extension is going to be so.
All right. And go ahead and copy that
in.
Oops.
I lost that. But yeah, select all, copy
and paste that in here. All right, so
let's take a look at the a quick look at
the contract here. Um, now ERC20, this
is inherited from Open Zeppelin. This
kind of forms the base of our token
contract. Uh, and our contract also
includes a ERC20 permit. Now, we won't
dive too deeply into this in this video,
but suffice to say that uh what permit
does is it allows it allows a user to um
sign transaction approvals rather than
pay gas for approval transactions. So,
it just makes it a little bit more user
friendly. And also, we we've just
included it to futureproof our token as
much as possible since a lot of like
DeFi protocols sort of are expecting
that these days. All right. So, uh, you
don't really need to change, well, yeah,
you do need to change something. U, this
one's called my token. So, change this
to whatever you're going to call your
new token. And you can do a find and
replace or you can just kind of do it
like I'm doing ad hoc here and hope I
catch all the spots. Now, this is your
ticker symbol. So, update this as well.
So, I'll say OCT.
Go ahead and save that. And so, this is
a very basic uh token. And what it's
going to do here is uh we'll pass in our
initial supply. That is how many of the
tokens you want to be available. That's
a fixed supply. And what this line in
the constructor is doing here, it's
going to mint that many tokens and send
it to you. Send it to the wallet of
whoever is deploying this token.
All right, let's go ahead and copy over
our test. By the way, you can delete
these counter files here
just to keep it clean. We won't need
these. Same in the test folder. Just go
ahead and delete that.
Now, we'll create a new test file.
Also, call it whatever your token name
is. Ocean token. This time, the
extension is going to be TS for
TypeScript.
All right. Now, let's go to our token
complete test
and we can copy this contents back into
our new test file.
And again, just um find and replace
my token with whatever your token name
is.
Oops. To do all There we go. Go ahead
and save that. Now, we just have one
test here. It's very basic. um it's
going to create a token with um a
million
uh
denominations and it's going to just
basically deploy the token and then
we're testing to make sure the balance
of of your wallet or the wallet who
deployed the token is equal to the the
same as the initial amount 1 million. So
just a basic sanity test to make sure
that basically we're testing the
deployment.
Um, okay. Let's see what else. Scripts.
Uh, we're going to add a deploy script.
So, let's do new file. deploy.ts.
Um, and again, we can grab that script
from token complete. So, go into
scripts deploy
and we'll go back and paste it into our
new file.
And again, copy and replace.
Save that. Okay, we'll come back to that
in a little while. And then the final
file. Um, did we do config yet?
Yeah, we already did that. Okay. Yeah,
that's it. Okay. So, the next thing we
can do is go ahead and run our unit
tests just to make sure everything is
good. So, I believe that's npx hard hat
test. I think it's without the dash
dash, but let's see. Okay. I have no
idea why it's taking so long.
There we go. Finally.
All right, that looks good. Our one test
is passing, which means we are now able
to deploy our contract to Ethereum test
net to Sapoleia. So, let's go ahead and
do that.
Okay, so before we deploy, let's take a
look at our deployment script. So, if
you go into token build contract scripts
deploy,
there's some important parameters here
that we want to take a look at. So,
first of all, this is the script we're
going to call. it's going to deploy our
contract. Um, initial, this is the
initial balance or the total balance of
your of your token contract. So,
basically, this is what's going to be
passed into
here as initial supply. Okay? So, you're
setting that in the deploy script right
here. Now, it's defaulted to 1 million
tokens. Um, and we do the times 18
because of the 18 decimals, which is
standard for an Ethereum token. Um, so
it'll really be a million plus 18 zeros,
but it'll be displayed in wallets for
all intents and purposes as 1 million.
So anyway, if you want to um if you want
to tweak the number of of supply, you
would just need to adjust this first
number here and leave the rest as is. So
say you want 10 million, change it like
that. You want 21 million like Bitcoin,
update it like that. Right? So I'll just
leave mine as 1 million for now. Uh, go
ahead and save that. And then in the
terminal, let's issue our deployment
command. So we want to do npx
hard hat run and then give it the
location relative to to the root of
token build. So
scripts dash
deploy.ts.
Oops. TS. Then we want to do hyphen
network. And here's where we specify
what network we're deploying to.
Sapoleia. So if you wanted, you know, if
this was your actual um deployment to
mainet, you would have mainet here
instead of supposed like this.
Okay.
All right. Go ahead and hit enter.
By the way, if it fails at this point,
um it could be you want to make sure you
have I should have mentioned this
earlier, but um you want to make sure
that you've got enough ether in your
wallet to uh to cover the deployment and
it's going to be much less on the test
net rather than mainet. Okay, there we
go. So, our token has been deployed.
What I like to do typically is just copy
that's the contract address of our token
on Seolia. So, so what I like to do is
just copy that into Notepad for future
reference.
Okay. So, next up, let's go ahead and
verify that that full initial supply has
been correctly deposited into our
wallet. So, I'm going to grab I'm going
to grab the contract address and head
over to the browser and uh let's pop
open MetaMask here. All right. So, what
I want to do is make sure we've got
Seapoleia selected and let's go to
import tokens again. and select Sapoleia
and go ahead and paste the contract
address in there. And you can see it's
recognizing our token. Let's go ahead
and click next and import.
Perfect. So now we can see that our
wallet does indeed have 1 million OCT or
whatever the name of your token is. Um
now let's go ahead and test a uh token
transfer. So I'm going to go ahead and
select my account number eight address.
Right. Go back to seven.
And let's go ahead and do a send.
And we need to select
the right token.
Oops, it's right here. OCT. There we go.
All right. And
let's go ahead and send um 5,000.
Okay.
And we'll confirm that.
Okay. Of course, it's going to take a
little while for that to go through um
once it has the the correct amount of
confirmations, but in the meantime,
let's go ahead and switch over to
account 8. And it should show up here in
just a few seconds.
Okay. And again, we'll have to import
that token in our destination wallet the
same way we just did it before. So, I'll
add the token address. Whoops.
There we go.
And perfect. It looks like our uh
transaction has gone through. So, this
wallet now holds 5,000 and our um
deployer account, account number seven
has 1 million minus 5,000. And those are
both correctly reflected. So, looks like
our token is working. It's deployed to
Sapoleia and we're able to interact with
it and send tokens just we as we would
normally expect to.
Now, another way that we can confirm
that our token is live and deployed is
to head on over to
seapoleia.etherscan.io
io and enter in our token address right
here. And this should find our token.
There it is, ocean token. And um we can
see it was deployed 17 minutes ago from
this address to this address. And we can
see all the details. Uh I think if we
click in here, yeah, we can see the
total max supply, number of holders,
total transfers, and that all lines up
with um the verification step that we
just did. Okay. So now the last step is
to verify the contract on Etherscan.
This is an optional step, but it will
give the public a lot more confidence in
in your token. Um, so I definitely
recommend it. And basically what this
does is it uploads the source code and
construct your arguments and then once
it's verified, everyone can see the code
publicly, check the functions, and even
interact with the contract directly from
the explorer.
So, if we head on over to the readme
around line 93, um, we can copy and
paste this command. And then what we
have to do is add our, uh, replace this
with the actual deployed address. So,
I'll just dump that into Notepad and
oops, place that here. Um, and now this
last argument is the initial supply. So,
it should be 1 million plus the 18
decimal zeros. All right. So now let's
copy this whole command and go back into
Visual Code and let's go ahead and run
it.
And it looks like we've got an error
with our verification. So no hard hat
config file found. I think I know what's
happening. So we have a config file. So
that's a little bit misleading. But um
what's happening is we don't have the
actual verify plugin in place. Um I
thought I added it but I guess not. So,
let's head on over to hard hat and see
if we can get this added real quick.
Okay.
So, I'm going to go to documentation
hard hat 3.
Um, verifying contracts. And this should
tell us, yeah, we need to install this
plugin here. So, let's do that first.
All right. So, I want to let's see.
Oops, I'm not in the right folder
anymore. ERC20.
And then I want to go into token build.
And then I want to go ahead and install
this.
And I will update the repo so you guys
don't have to actually go through this.
Um I'll make sure that's updated before
this goes out. But just to show you kind
of how to set this up real quick. Okay.
And then add to the list of plugins.
Direction verify.
All right. So, under
user config, I want to have this plugins
array here. So, let's do that first.
Okay, we have Okay, we've got the That's
good. Okay, so we've got that array. So,
we just need to add hard hat verify.
Okay,
let's do a commaepparated list. There we
go. Oh, and we need to add the import
statement.
this line right here.
I'll put that right right there. Okay.
Now, there should be one more step left
to configure it.
So, we want to grab this whole block
right here. And then we'll point this to
our uh env file value for the ether scan
key.
And I'm just making sure. Okay. Verify
that goes right under
I think that goes here if I'm not
mistaken. And then
we'll just use the same syntax that you
know we're using elsewhere here.
There we go. And then this is going to
be
all right. Let's go back to our example.
Ether scan API key is what we want.
Okay, great. Let's try it again now. I
think that's all we need.
We go. I'm going to run the verify
script again. Oh, that that was not the
right one. Need to go back further.
There we go. That's what we want.
That same script we ran a few minutes
ago. Let's see if it works now.
Okay, that looks promising.
Definitely further along than we got
last time.
Okay, it's already verified. H.
I wonder why that is.
Okay. Well, I don't think that's
correct. Um because this is the first
time I've run the script. So, let's try
it again. Maybe this is a hard hat bug.
Let's see what happens if we just run it
again.
Oh,
yep. Totally. That was weird. Okay, so
work the second time. So I guess file
that mental note away that um hard hat
can be a little bit buggy sometimes. So
now it is verified and it's giving us
the URL that we can follow and hopefully
verify the verification
open.
Okay, there we go. This contract has
been verified using block scout by code
database.
So we can see our contract is
successfully verified. And notice now we
can see the source code um that's
publicly available for everyone to
inspect. So yeah, it's just great
practice. It gives a lot more confidence
um for people who potentially would want
to trade your token or purchase your
token. So uh definitely a highly
recommended step. All right, guys. So uh
the final step would be to deploy your
token to mainet. Uh once you're happy
with everything, how everything's
working out on the test net, then um
again like I mentioned before, the only
difference you would need to do here is
replace with main net here on your uh
your console command. And again, this
can be found in the readme. This is on
line 84 right now. That may change, but
um step nine anyway. So, yep. And then
you would just run that command again
targeting mainet. And then all the other
steps uh in terms of verification and
ether scan verification would be the
same. Uh just anywhere where there's
like a network um specifying sepoleia,
you'd want to update that to mainet. So,
yep. So, that'll be it guys. Um yeah.
So, thanks for watching and um I know
it's been a while, but hopefully I'm
going to get back to making videos a
little more regularly. So, uh if there's
anything you guys would like to see on
the channel, please let me know in the
comments. All right, guys. Well, happy
coding and take care. Bye.
In this updated ERC-20 token tutorial, youlll learn how to create your own cryptocurrency token on Ethereum in 2025 using the latest tools. We'll walk through the entire process — from project setup to testing, deployment, and Etherscan verification. You’ll see how to: Set up a Hardhat + TypeScript project with Node.js Use OpenZeppelin Contracts to build a secure ERC-20 with fixed supply + Permit (EIP-2612) Run automated tests in Hardhat Deploy your token to the Sepolia testnet Verify the contract on Etherscan Import your token into MetaMask By the end, you’ll have a fully working ERC-20 token project you can build on, and you’ll understand the modern Ethereum development workflow in 2025. Full code and instructions are available in the GitHub repo linked below. https://github.com/jspruance/erc20-token-2025/blob/main/README.md Project repo on GitHub: https://github.com/jspruance/erc20-token-2025 Ethereum ERC20 Standard: https://ethereum.org/en/developers/docs/standards/tokens/erc-20/ Open Zeppelin ERC20 Documentation: https://docs.openzeppelin.com/contracts/5.x/erc20