A full-stack dApp starter built on Ethereum (Solidity) with Next.js (React).

Overview

A full stack dApp starter built on Ethereum (Solidity) with Next.js (React)

This repo contains boilerplate code for interacting with a simple smart contract from the client-side using Solidity, React and TailwindCSS.

Prerequisites

Getting Started

Environment Setup

Duplicate .env.example to .env and fill out the HARDHAT_CHAIN_ID environment variable.

Run npm install.

Running The Smart Contract Locally

Compile the ABI for the smart contract using npx hardhat compile.

Deploy the smart contract to the local blockchain for testing with npx hardhat node.

If you're successful, you'll get something like the following CLI output:

Greeter deployed to: 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0

Then in a new terminal window, npx hardhat run scripts/deploy.js --network localhost.

If you're successful, you'll be presented with a number of account details in the CLI. Here's an example:

Account #0: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266 (10000 ETH)
Private Key: 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

Adding A Local Account To MetaMask

Open your MetaMask browser extension and change the network to Localhost 8545.

Next, import one of the accounts by adding its Private Key (for example, 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 to MetaMask.

If you're successful, you should see the a balance resembling something like 9999.99 ETH in the wallet.

Connecting The Front-End

In .env set the NEXT_PUBLIC_GREETER_ADDRESS environment variable to the address your smart contract was deployed to. For example, 0x9fE46736679d2D9a65F0992F2272dE9f3c7fa6e0.

In a new terminal window, load the front-end with npm run dev. If you want to use an alternate port from 3000, use npm run dev -- --port=1234, or whatever port number you prefer.

Demo'ing The Functionality

Once set up, go to localhost:3000 (or whatever post number you used), to view your dApp in the browser.

Clicking Fetch greeting from the blockchain should bring back a value of Hello world! in the input above. This is the default string passed to the smart contract on first deloy.

To update the greeting value, type something in the input with placeholder Write a new greeting, then click Set new greeting on the blockchain. If you're successful, a MetaMask window will open in your browser. From here you can connect the local account you added earlier and sign the transaction.

Click Fetch greeting from the blockchain again to see the changes you've made.

Editing The Front-End

To modify the front page of your application, edit pages/index.js.

All TailwindCSS classes are available to you.

To lint your front-end code, use npm run lint.

Testing

To test your smart contracts, run npx hardhat test.

A sample test can be found in test/sample-test.js.

Deploying To The Ropsten Test Network

This is a more advanced step after running the smart contract locally.

Up to now, the smart contract has been running on a local blockchain. The next step, is to test how it works on a live test network. We'll do this by deploying to Ropsten.

MetaMask

First, switch your MetaMask network from Localhost 8545 to Ropsten Test Network.

Then, view the account details of your test account. Click Export Private Key. After entering your password, you'll be given a private key. Copy and paste your private key (example, df57089aefbcaf7ba0bc227dafbffa9fc08a93fdc65e1e42214a14efcf23656e) as the value of ROPSTEN_PRIVATE_KEY in .env.

Important: Never expose the private key of an account with real assets inside. Always add private keys as environment variables. Never commit private keys to code.

Infura

Infura is a service that allows developers to connect to Ethereum infrastructure through their API. In this boilerplate, we'll be using Infura to deploy our smart contract to the Ropsten test network.

Sign up for an account if you don't have one already, then create a new Ethereum project. Name your project, then select Ropsten from the endpoints drop down. Save changes.

Copy and paste the URL starting with https and set it as the ROPSTEN_URL value in your .env file.

Obtaining Test ETH

You'll need some test ETH in your wallet for use on Ropsten. Head over to the Ropsten Ethereum Faucet, paste in your wallet account address (for example, 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80) and press Send me test Ether.

In a few minutes, you should see your balance update in MetaMask. This is your test ETH.

Deploying Your Smart Contract To Ropsten

In your terminal enter, npx hardhat run scripts/deploy.js --network ropsten.

If you're successful, you'll get a confirmation message as follows:

Greeter deployed to: 0x9045cEc7161f380C224ae95c15EbE96659A53c46

This address is where your smart contract is deployed on the Ropsten Test Network.

Post deployment, you should also see your ETH decrease a little in MetaMask from the gas transaction fee.

Etherscan

Because your smart contract is now deployed to a live test network, you'll be able to view it's details on Etherscan. Go to Ropsten Etherscan and copy and paste the address you were given in the previous step (for example, 0x9045cEc7161f380C224ae95c15EbE96659A53c46) into the explorer.

You'll be able to see all historical transactions and events here.

Testing The Functionality

Change the NEXT_PUBLIC_GREETER_ADDRESS variable in .env to be the smart contract address on the Ropsten Test Network (for example, 0x9045cEc7161f380C224ae95c15EbE96659A53c46).

Start (or restart) the front-end using npm run dev.

Fetching the greeting from the blockchain will return Hello world! on first run.

Setting a new greeting may take a little longer than it did locally as we're using a real test network.

All instance of setting a new greeting will now create a transaction attached to the smart contract that you can view on Ropsten Etherscan

Roadmap

You might also like...

Hi there! This is a react native starter which used to build a awesome Event Booking App based on the Figma design. You can download or clone it to speed up your projects.

Hi there! This is a react native starter which used to build a awesome Event Booking App based on the Figma design. You can download or clone it to speed up your projects.

mcrn-event-booking-app-starter Hi there! This is a react native starter which used to build a awesome Event Booking App based on the Figma design. You

Dec 19, 2022

⚡️ Set up Next.js Progressive Web App with `npx create-next-pwa`

⚡️ Set up Next.js Progressive Web App with `npx create-next-pwa`

⚡️ create-next-pwa A cross-platform Node.js based CLI tool that creates Progressive Web App (PWA) with Next.js. You can also integrate tailwind with t

Nov 20, 2022

A Gatsby starter using the latest Shopify plugin showcasing a store with product overview, individual product pages, and a cart

A Gatsby starter using the latest Shopify plugin showcasing a store with product overview, individual product pages, and a cart

Gatsby Starter Shopify Kick off your next Shopify project with this boilerplate. This starter creates a store with a custom landing page, individual f

May 12, 2021

The deck, starter project, & final demo for @lachlanjc’s talk at PrideMakers 2021.

PrideMakers 2021 The deck, starter project, & final demo for @lachlanjc’s talk at PrideMakers 2021. Starter on Glitch: https://glitch.com/~pridemakers

Sep 24, 2021

A Remix starter with intuitive defaults, like support for internationalization and localized URLs

A Remix starter with intuitive defaults, like support for internationalization and localized URLs

💿 Remix Starter A Remix starter with intuitive defaults, like support for internationalization and localized URLs. Coming soon: Authentication and au

Jan 8, 2023

A simple Vue3, Nuxt3 and Tailwind3 Starter Template

Nuxt 3 + Tailwind CSS 3 Starter This is a minimal starter template for Nuxt 3 projects with Tailwind CSS 3. It includes a simple template pages/index.

Feb 11, 2022

Fastify + Typescript starter

Fastify + Typescript starter A really basic API template powered by: Fastify Typescript EsLint + Prettier Jest + Supertest Available scripts: npm run

Aug 24, 2022

A starter project to run your local server, and start sending voice packets to Deepgram

A starter project to run your local server, and start sending voice packets to Deepgram

A starter project to run your local server, and start sending voice packets to Deepgram

Sep 30, 2022

NextJS Starter Example for Running Zesty.io CMS

NextJS Starter Example for Running Zesty.io CMS

Zesty.io + NextJS Getting Started Node and NPM need to be installed. From your command line.

Dec 8, 2022
Comments
  • Update dependencies and Tailwind config.

    Update dependencies and Tailwind config.

    Hey! I noticed this repo needed to be updated to Next.js 11.1, as well as some updates to the Tailwind configuration.

    • Purges unused styles in tailwind.config.js, which decreases CSS bundle size
    • Uses Tailwind JIT mode, which increases local development speed

    https://tailwindcss.com/docs/guides/nextjs

    opened by leerob 2
Owner
Tom Hirst
Web Consultant | WordPress, PHP, JavaScript, React, JamStack, Solidity
Tom Hirst
Full-Stack solution to quickly build PWA applications with Vue.js and Firebase

Welcome to bento-starter ?? ?? bento-starter is an Open-Source Full-Stack solution that helps you to build fast and maintainable web applications usin

Franck Abgrall 1.5k Jan 5, 2023
React + Redux starter kit / boilerplate with Babel, hot reloading, testing, linting and a working example app built in

A comprehensive starter kit for rapid application development using React. Why Slingshot? One command to get started - Type npm start to start develop

Cory House 9.8k Jan 3, 2023
Minimal Electron Starter Kit built with Typescript, React, Webpack 5 and Babel 7

electron-webpack-boilerplate Minimal Electron Starter Kit built with Typescript, React, Webpack 5 and Babel 7 To create a JS library, check out js-lib

Francisco Hodge 10 Aug 16, 2022
React Starter Kit — isomorphic web app boilerplate (Node.js, Express, GraphQL, React.js, Babel, PostCSS, Webpack, Browsersync)

React Starter Kit — "isomorphic" web app boilerplate React Starter Kit is an opinionated boilerplate for web development built on top of Node.js, Expr

Kriasoft 21.7k Jan 1, 2023
This is a template project demonstrating how the MERN stack(Mongo, Express, React, Node) can be used, here we have the back end implementation and there is the React implementation as the front end

Versão em português MERN stack This is a template project demonstrating how the MERN stack(Mongo, Express, React, Node) can be used, here we have the

Douglas Samuel Gonçalves 2 Jan 22, 2022
Meet Pompom, the Proof of Meeting Dapp 🍭 (ETHGlobal x Polygon)

POMPOM - Proof of Meeting Meet PomPom, a Proof of Meeting Dapp cooking for ETHGlobal Polygon Hackaton. Contracts are created in separated repo. Find t

WebX DAO 11 Oct 22, 2022
Next.js + Tailwind CSS + TypeScript starter packed with useful development features

?? ts-nextjs-tailwind-starter Next.js + Tailwind CSS + TypeScript starter packed with useful development features. Made by Theodorus Clarence Features

Cornelius Denninger 7 Nov 12, 2022
A Next + TypeScript Starter. Featuring Styled-Components, ESLint, Prettier, Axe a11y monitoring, Fathom analytics, sitemap generation, and more!

Next + TypeScript Starter A Next + TypeScript Starter by Justin Juno. Featuring Styled-Components, ESLint, Prettier, Axe a11y monitoring, Fathom analy

Justin Juno 11 Dec 13, 2022
A highly opinionated and complete starter for Next.js projects ready to production

The aim for this starter is to give you a starting point with everything ready to work and launch to production. Web Vitals with 100% by default. Folder structure ready. Tooling ready. SEO ready. SSR ready.

Fukuro Studio 28 Nov 27, 2022
🚀 A well-structured boilerplate and Starter for Next.js 12+, Tailwind CSS 3, Redux, Redux Thunk, and TypeScript

?? A well-structured boilerplate and Starter for Next.js 12+, Tailwind CSS 3, Redux, Redux Thunk, and TypeScript ⚡️ Made with developer experience first ESLint + Prettier + Lint-Staged + VSCode setup

null 4 Nov 28, 2022