Basic dApp starter with:
- NextJS and TypeScript support
- MetaMask and WalletConnect Modal
- React Bootstrap 5 UI
- SASS/SCSS support
- Frontend interacting with simple storage smart contract
The dApps is interacting with a Simple Storage that running on Rinkeby testnet, hence you need some ETH in your wallet. If you don't have any, you can request some ETH from Rinkeby Faucet.
The project is bootstrapped with Truffle using truffle init
command.
Steps to run the SimpleStorage smart contract locally:
-
Clone the github repository.
git clone [email protected]:jovst/truffle-nextjs-bootstrap-dapp-starter.git
-
Install Truffle globally.
npm install -g truffle
-
Run the development console in the truffle-nextjs-bootstrap-dapp-starter directory.
truffle develop
-
Compile and migrate the smart contracts. Note inside the development console we don't preface commands with
truffle
.compile migrate
Please note down the contract address of the deployed SimpleStorage smart contract. We will need to update it in the front-end code.
-
Truffle can run tests written in Solidity or JavaScript against your smart contracts. Note the command varies slightly if you're in or outside of the development console.
// If inside the development console. test // If outside the development console. truffle test
-
Deploy smart contract to Rinkeby testnet
- Install dependencies in the root directory.
npm i # or yarn
- Create a
.env.local
file with Infura Project ID and mnemomic of your Rinkeby account, for example:INFURA_PROJECT_ID='b874a2f145f84dc5a8466e5490816789' MNEMOMIC='seed phrase'
- Run the
truffle migrate --network rinkeby
command to deploy smart contract to Rinkeby network.
- Install dependencies in the root directory.
The front-end code of the dApps is located in frontend
directory. It is a Next.js project bootstrapped with create-next-app
and supports React Bootstrap 5 and SASS/SCSS.
The frontend is created by derived/adapted the codes from the following excellence articles:
- Build a Web3 Dapp in React & Login with MetaMask
- Global State Using Only React Hooks with the Context API (TypeScript Edition)
- Build Your First Solidity Dapp With Web3.js and MetaMask
Steps to run the frontend locally:
-
Install dependencies.
npm i # or yarn
-
Create the
.env.local
file in thefrontend
directory and define the following environment variables:NEXT_PUBLIC_SIMPLE_STORAGE_CONTRACT_ADDRESS=0x... NEXT_PUBLIC_INFURA_PROJECT_ID=YOUR_INFURA_PROJECT_ID
As the
.env.local
file is not stored in the repo:- For deployment to Vercel, you need to configure the environment variables there.
-
Run the development server
npm run dev # or yarn dev
Open http://localhost:3000 with your browser, you will see the screen of the React frontend:
-
Run with MetaMask
As
truffle develop
exposes the blockchain onto port9545
, you'll need to add a Custom RPC network ofhttp://localhost:9545
in your MetaMask to make it work.
MIT