Launch Your Ethereum Donation dApp Today: Easy Steps With MetaMask, Alchemy, and GitHub Codespaces
This guide offers a straightforward walkthrough on building and launching your first Ethereum dApp, "BuyACoffee," using MetaMask, Alchemy, and GitHub Codespaces.
Join the DZone community and get the full member experience.
Join For FreeIn the rapidly evolving world of blockchain technology, building decentralized applications (dApps) presents a unique opportunity for developers to explore the potential of Ethereum and smart contracts. This article aims to guide you through the process of creating a simple yet functional dApp, "BuyACoffee," designed to receive acknowledgments from the readers of Brainupgrade. We'll use the Ethereum test network Sepolia and platforms like Alchemy and MetaMask for wallet management.
Step 1: Setting up MetaMask
MetaMask is a popular Ethereum wallet and a gateway to blockchain apps. Here's how to create a new wallet for our project:
- Download and install MetaMask: Go to the MetaMask website and add the extension to your browser.
- Create a new wallet: Follow the on-screen instructions to create a new wallet. Remember to safely store your recovery phrase.
- Connect to Sepolia test network: By default, MetaMask uses the Ethereum Mainnet. Switch to the Sepolia test network from the network dropdown.
Step 2: Setting up Alchemy
Alchemy provides powerful tools for blockchain developers. We'll use it to deploy our dApp.
- Create an Alchemy account: Sign up at Alchemy and log in.
- Create a new app: Navigate to the dashboard and create a new app. Choose "Sepolia" as the network.
Step 3: Funding Your Wallet With Test ETH
Before deploying our dApp, we need some test ETH. Use a Sepolia faucet (search online for "Sepolia faucet") to receive 0.5 ETH in your MetaMask wallet for testing purposes. Use your MetaMask wallet id.
Step 4: Preparing Your dApp
We'll use the provided source code for the "BuyACoffee" dApp and web app. You can find the complete code at GitHub - Brainupgrade.
- Fork the source code repo: Use GitHub Codespaces to launch the browser-based IDE to make code changes. See the following snapshot. Click on Create codespace on main, and VSCode will be launched in the browser.
- Install dependencies: Navigate to the dApp directory (BuyMeACoffee-contracts) and run npm install to install the required dependencies.
Step 5: Deploying Your Smart Contract With Alchemy
Using Hardhat, we'll deploy the smart contract to the Sepolia network.
- Configure Hardhat: In the hardhat.config.js, set up the Sepolia network configuration using your Alchemy URL and the private key of your MetaMask account. Set the environment variables
SEPOLIA_URL
andPRIVATE_KEY
(these two are found in the Alchemy app settings) - Deploy the contract: Run npx hardhat run scripts/deploy.js --network sepolia to deploy your contract to the Sepolia network.
Step 6: Integrating with Your Web App
The web app (located in the "app" folder) interacts with your deployed smart contract.
- Configure your web app: Update the ./src/App.jsx in the web app folder with the contract address and ./src/utils/BuyMeACoffee.json with the JSON built when the smart contract was deployed.
- Run the web app: Use a local server or a development tool to serve the web app.npm run buildnpm run previewElse, you can dockerize the app and run it using the following commands:
docker build -t buy-me-a-coffee-app .docker run -d -p 80:80 buy-me-a-coffee-appOnce app
is running, you can open the URL in the browser in which the MetaMask extension is available. See the following snapshot. You may have a URL that is provided by GitHub Codespaces.
Step 7: Testing Your dApp
Use MetaMask to interact with your dApp. Ensure you're connected to the Sepolia network and have some test ETH.
- Interact with your dApp: Use the web app interface and connect to your MetaMask wallet to send a "coffee" (a small ETH transaction) as a token of appreciation.
- Monitor transactions: Use Alchemy's dashboard to monitor incoming transactions and contract interactions.
Deploying and Testing With GitHub Codespaces
For deployment and testing, GitHub Codespaces offers a convenient cloud-based development environment. Simply fork the provided GitHub repository and open it in Codespaces to start developing and testing your dApp without needing to set up a local development environment.
Conclusion
This walkthrough demonstrates the simplicity and power of creating and deploying a blockchain dApp using MetaMask, Alchemy, and the Sepolia test network. By following these steps, developers can gain hands-on experience with Ethereum smart contracts and the broader ecosystem. Remember, this is just the beginning of your blockchain development journey. The possibilities are endless, and as you grow more comfortable with these tools, you'll be well on your way to building more complex and impactful decentralized applications.
Happy coding, and may your coffee cup always be full, courtesy of our supportive readers!
If you like the article, Buy Me A Coffee.
Published at DZone with permission of Rajesh Gheware. See the original article here.
Opinions expressed by DZone contributors are their own.
Comments