HELLO
BASE
by
Welcome!
If you're a developer and you've never touched a blockchain or know very little about them, you're in the right place. In just a few short minutes you'll learn the fundementals and see how you can start building on Base, a blockchain designed to bring the next generation of developers onchain.
You don't need anything to start this tutorial, we'll take care of everything for you. Just start scrolling!
What is a Blockchain?
In short, a blockchain is an immutable digital ledger that lives on multiple computers. They use cryptography to link blocks of transactions together to form a history. They differ in form, but all blockchains have a consensus mechanism to make sure all the nodes (aka computers) are on the same page and keep the same history.
These blockchain networks allow you to create an account with a cryptographic public and private key-pair. You can think of it like a PO Box where anyone can send you mail (public key address) but only you can open the box to see the mail (private key).
Bitcoin is perhaps the most popular blockchain example, where transaction blocks are simply transfers of the digitial currency from one account to another.
Enter Ethereum
Ethereum saw the potential of going beyond a simple financial transfer and built a virtual machine that could run compiled byte-code. The Ethereum Virtual Machine was born, or "EVM" for short. Programs are built by writing smart contracts in Solidity that dictate what the code does on the EVM.
Once a program or smart contract is deployed it can be interacted with by other accounts on the network, either user accounts (Externally Owned Accounts) or other smart contract accounts. Interactions with these programs are still recorded as transactions on the blockchain, giving you an immutable ledger of software being run.
This leads to a foundation of trustless software execution, which is perfect for financial and governance applications, and beyond!
The Problem with Ethereum
While Ethereum was an exciting advancement in distributed computers, it had a few problems that have kept it from being adopted by the masses. As it grew so did it's cryptographic operations, and this caused a scaling issue.
All transactions onchain cost gas to keep the node operators running, and when the network is congested with high traffic, the fees become higher as well. This gets to a point where doing a simple transfer could cost dozens if not hundreds of dollars.
There have been multiple improvements and upgrades made to Ethereum over the years, but not enough to keep up with the demand of blockchain developers and consumers.
Rollups as a Solution
Layer 2 (L2) blockchains have emerged as a popular solution to Ethereum's scaling challenges. These networks process transactions independently using their own nodes, but instead of settling each transaction individually on Ethereum (Layer 1), they bundle multiple transactions together and process them as a single batch. This batching approach makes L2 transactions significantly faster and more cost-effective than direct Ethereum transactions.
Another large benefit to these rollups is they stay EVM compatible, which means the code you wrote for Ethereum can be deployed to an L2 without any extra work. This also assists with making tools and infrastructure interoperable.
Introducing Base
Base is an Optimistic Rollup incubated by Coinbase, and aims to bring the world onchain. It provides fast and cheap transactions, almost all of them being under $0.01. Base is open sourced, trusted, and has become one of the most popular blockchains to date.
Now that you have some fundamental understandings around blockchains and Base, let's cook.
Create a Wallet
To get started on Base you'll need an account. The easiest way to do that is through a wallet, which is a piece of software that makes it easy to manage a blockchain account.
We've simplified the process of making a wallet, so all you have to do is click the button that says "Create Wallet." Everything we'll do is on a testnet so there won't be any real funds being used here. Always test on dev first ;)
Deploy a Smart Contract
You're a developer, so we're gonna speak your language: "Hello World," but in our case "Hello Base" onchain. In this simple smart contract we have the following:
- A state variable to hold our greeting
- A function to set the state
- A function to read the state
With that, click the "Deploy" button below the code. This will prompt a transaction to your new wallet, making this your first smart contract deployed onchain!
Create your wallet first!
Write to the Contract
Congrats!! Your contract is deployed 🎉
Now we can interact with it by calling some of the functions. This is done by using a JSON RPC provider that can take our instructions + an ABI (application binary interface) so the EVM can interpret it and run the code.
Since the RPC uses JSON we can use libraries in Typescript, making it really easy to access onchain data in modern web apps like the one you're using now. The code on the right is being used when you click "Write to Contract"!
Create your wallet first!
Read Contract
Now that you've set the greeting state on the contract, let's read it!
We'll use the same Typescript library and pass in our contract address, as well as the previously mentioned ABI and function name.
Just click the "Read Contract" button to fetch the greeting!
Create your wallet first!
Offchain Data
Ok we got strings, but what about larger pieces of data?
Storing larger pieces of data onchain has proven to be difficult as it requires more space on the blockchain, and that means much higher gas payments. The solution is using a string as an offchain pointer, where we can fetch the data after getting the pointer.
Another problem quickly encountered was that offchain storage with services like AWS are mutable and could be taken down, which is not ideal when you're building with an immutable ledger. The most popular solution became IPFS, a distributed immutable file sharing protocol.
You can learn more about IPFS here, but for now we'll change our greeting to an offchain pointer on IPFS via Pinata
Create your wallet first!
Reading Offchain Data
Just like before we'll make a call to the contract to get the greeting.
Since we know we're expecting an offchain reference on IPFS, we can render the response as a link we can click on to access it while it lives on IPFS
Create your wallet first!
What's Next?
In just a matter of minutes you've deployed a smart contract to Base, wrote data to it, and read it back. Now it's time to start building!
Of course you don't have to do this alone. There are so many good resources for how you can take the next steps with Base, so we've decided to link a few.
GO BUILD
Thank you for taking the time to visit HelloBase! We hope you found it helpful to kickstart your journey to building on Base.
If you're interested in how this site was built or if you'd like to contribute, please check out the GitHub repository