Reader small image

You're reading from  The Essential Guide to Web3

Product typeBook
Published inNov 2023
PublisherPackt
ISBN-139781801813471
Edition1st Edition
Concepts
Right arrow
Author (1)
Vijay Krishnan
Vijay Krishnan
author image
Vijay Krishnan

Vijay Krishnan, an experienced expert in blockchain and Web3, holds the position of head of SysOps for Linea, a Layer 2 blockchain at Consensys. With a rich background in blockchain, he's guided Fortune 100 companies from ideation to product build. With over 50 projects and 300+ use cases to his credit, Vijay has left an indelible mark on the industry. Prior to Consensys, he pioneered the AWS Partner Blockchain ecosystem and led IBM North America's Blockchain Practice. With two decades on Wall Street, he possesses deep financial and tech insights. Vijay, a leader and subject matter expert, empowers clients in DeFi, NFTs, gaming, and the metaverse. Beyond work, he's a mentor, speaker, author, and organic farmer. His knowledge and innovation continue to shape the blockchain and Web3 landscape.
Read more about Vijay Krishnan

Right arrow

Your First Ethereum Transaction

Now we are ready to learn how to make our first transaction using the Ethereum blockchain. Even though executing a transaction with Ethereum is simple enough, it has steps that we need to follow and it is essential to understand these steps to know what we are doing. In this chapter, we will prepare the wallet, initiate a transaction, sign the transaction, and submit it to the public Ethereum blockchain. We’ll learn how to look for this transaction using a blockchain explorer. Then, we’ll summarize everything so that you can try submitting new transactions and get your hands dirty before we dive deep into programming smart contracts.

In this chapter, we’re going to cover the following main topics:

  • Setting up Hardhat
  • Preparing your wallet
  • Initiating a transfer transaction
  • Viewing and verifying results

There are many ways to submit an Ethereum transaction. It also depends on what kind of transaction we...

Setting up Hardhat

There are multiple options when it comes to Ethereum blockchain tooling. The simplest and easiest one to get started is Hardhat.

Hardhat is a popular development framework for Ethereum-based blockchain applications. It provides developers with a suite of tools to develop, test, and deploy smart contracts and decentralized applications (Dapps) on the Ethereum network.

Hardhat includes a development environment, a testing framework, and a deployment pipeline. It also provides built-in support for various popular Ethereum development standards, such as ERC-20 and ERC-721, as well as integration with popular Ethereum testnets such as Goerli () and Sepolia (), and node providers such as Infura ().

With Hardhat, developers can write and test their smart contracts in a sandbox environment, simulate blockchain transactions, and deploy their Dapps to the Ethereum network. Hardhat simplifies the process of building Dapps, making it easier for developers to create...

Preparing your MetaMask wallet

Open the MetaMask wallet that we installed and configured in the previous chapter in the A self-custodial wallet, MetaMask section. Before we initiate a transfer transaction, we need to do some preparation on the wallet by setting up accounts and connecting the wallet to the blockchain. Follow the next steps to prepare your wallet first:

  1. The following figure shows the main login page for MetaMask; enter the password for your wallet here:
Figure 3.5 – Logging in to MetaMask

Figure 3.5 – Logging in to MetaMask

  1. Now, click on the three dots on the right of Account 1 and click Expand view. Figure 3.6 shows you a visual representation of the steps:
Figure 3.6 – Opening MetaMask in Expand view

Figure 3.6 – Opening MetaMask in Expand view

  1. You will see something as shown in the following figure where a new page in a browser will open with an expanded view of the MetaMask wallet:
Figure 3.7 – MetaMask expanded view

Figure 3.7 – MetaMask expanded...

Initiating a transfer transaction

We will do our first transaction with Web3 now by initiating a transfer amount of 2 ETH from Account # 0 to Account # 1. Remember we have to do this transfer only within the local network and you’ll use the test ETH to pay for gas or transaction fees:

  1. As the very first step, open the MetaMask wallet, switch to the local network, and make sure you are seeing the Hardhat Account # 0 details. The balance should show 1,000 ETH. There are two ways to initiate a transfer: Send or Receive. Here, we will use the Send option. Make sure you are using localhost as the network and the account points to Account # 0 to start the transaction.
  2. Click on the Send option and it will take you to the next step.
  3. Now, click on Transfer between my accounts; the following figure shows the list of accounts that you can choose from:
Figure 3.18 – Transferring between accounts

Figure 3.18 – Transferring between accounts

  1. Choose Account # 1. Enter the amount...

Viewing and verifying results

We executed transactions in the previous steps, so now let us see how these transactions reflect in the blockchain and Hardhat local blockchain. Follow these simple steps:

  1. Open the Hardhat node and inspect the transaction. You should see something similar to the following figure. This confirms that the transaction happened in the blockchain and was recorded.
Figure 3.23 – Confirmation of transaction in the blockchain

Figure 3.23 – Confirmation of transaction in the blockchain

  1. Here, in this transaction, you will be able to confirm the sender and receiver of the 2 ETH that we transferred. The gas used is 21000, the gas price is 2375000000, the gas limit is 21001, and the block the transaction belongs to is #1, the first block that was created as a result of this transaction.

This concludes our first transaction on Web3. Practice a few transactions by importing multiple accounts from Hardhat using their private keys, and initiate multiple transfers. Explore...

Summary

In this chapter, we learned about MetaMask, a software cryptocurrency wallet used for interacting with the Ethereum blockchain and Dapps. We went through how to install, set up, and use MetaMask, as well as the importance of securely storing your secret backup phrase. We also learned how to connect MetaMask to a local blockchain such as Hardhat by adding a custom RPC network and importing Hardhat accounts. Finally, we learned about the process of transferring tokens between different accounts within MetaMask when using a local Hardhat blockchain.

In the next chapter, we’ll jump into the world of smart contracts. We’ll start writing and deploying the smart contracts to the locally running blockchain we deployed and take a deep dive into the programming side of smart contracts.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
The Essential Guide to Web3
Published in: Nov 2023Publisher: PacktISBN-13: 9781801813471
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Vijay Krishnan

Vijay Krishnan, an experienced expert in blockchain and Web3, holds the position of head of SysOps for Linea, a Layer 2 blockchain at Consensys. With a rich background in blockchain, he's guided Fortune 100 companies from ideation to product build. With over 50 projects and 300+ use cases to his credit, Vijay has left an indelible mark on the industry. Prior to Consensys, he pioneered the AWS Partner Blockchain ecosystem and led IBM North America's Blockchain Practice. With two decades on Wall Street, he possesses deep financial and tech insights. Vijay, a leader and subject matter expert, empowers clients in DeFi, NFTs, gaming, and the metaverse. Beyond work, he's a mentor, speaker, author, and organic farmer. His knowledge and innovation continue to shape the blockchain and Web3 landscape.
Read more about Vijay Krishnan