Coder Social home page Coder Social logo

crabsinger / typescript-eth-starter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from nezz0746/typescript-eth-starter

0.0 0.0 0.0 1.92 MB

๐Ÿ”Œ Ethereum Dapp Basic Typescript Starter

TypeScript 94.57% JavaScript 1.73% CSS 0.13% Solidity 3.58%

typescript-eth-starter's Introduction

๐Ÿ”Œ ETH Basic Typescript Starter

This monorepo should allow you to get started with a simple Greeter smart contract on localhost and Rinkeby in record time with this basic react stack using

  • Typescript
  • NextJS
  • ๐Ÿ‘ท Hardhat
  • ๐Ÿค useDapp
  • Tailwind CSS
  • Redux Toolkit
  • Yarn Workspace

Heavily influenced by Scaffold-Eth and the existing Typescript branch. Go ๐Ÿ— check it out ๐Ÿ— if you haven't !

TODO

  • Add Mintable NFTs example (In progress !)
  • Add Mainnet fork as dev chain

Get Started

Clone the project and install dependencies,

git clone https://github.com/nezz0746/typescript-eth-starter.git
cd typescript-eth-starter
yarn install

Environement variables setup

First create an Infura projetct and add your project id to the .env variable INFURA_ID.

This starter is setup to be usable/deployable on a local node and on Rinkeby. So before you start make sure you fill the RINKEBY_PRIVATE_KEY variable. (Checkout this section for more info on the private key), or comment out the rinkeby section if you juste want to start working asap on localhost.

// packages/hardhat/hardhat.config.ts
  ...
  networks: {
    hardhat: {
      chainId: 1337,
    },
    rinkeby: {
      url: `https://rinkeby.infura.io/v3/${INFURA_ID}`,
      accounts: [`0x${RINKEBY_PRIVATE_KEY}`]
    }
  }
  ...

Then open 3 separate terminals and run

  1. Start your local node
yarn chain
  1. Deploy your Greeter contract to your local node with
yarn deploy
  1. Then start your frontend !
yarn dev

Finnally, open http://localhost:3000 to see the app.

You frontend should be live on localhost and ready to submit and new setGreeting transaction to the local chain !

Here is what it should look like when launched !

Deploy your Smart Contracts on Rinkeby

To deploy your app on Rinkeby, you'll first need to populate two environment variables in your .env file, that are used in packages/hardhat/hardhat.config.ts. Checkout Infura it is a suite of tools that make it easy for developpers to deploy things on Ethereum and IPFS. Create a project there, go to Settings and copy the Project ID.

For your private key make sure you use an account you do not have any real funds on and export the private key. As a good practive, never share any account's private key in your repository. Metamask > (Select a dev account) > Account details > Export private key

const INFURA_ID = process.env.INFURA_ID;
const RINKEBY_PRIVATE_KEY = process.env.RINKEBY_PRIVATE_KEY

Now after you deploy,

yarn deploy:rinbeky

your smart contracts should be live on Rinkeby !

Deploy your Dapp on IPFS

IPFS uses Content-Addressing to reference content on the network, instead of location-based addressing as used in traditional web. Whenever you add content to IPFS, a cryptographic hash is produced to identify your content called a CID.

After running,

yarn ipfs

you will be given a hash which reprensent the root CID of the root directory of your website. Then all subdirectories and consequent files will have their own CID since every file on IPFS no matter it's type (folder, image, text, etc) has it's own CID. Using the IPFS CLI you'll be able to visualize what has been hosted on IPFS with all your content by running

> ipfs ls [YOUR_SITE_ROOT_CID]

> QmTgXrRyvfb8su1YaaafBPYDqdjbSG82qMFyW5XPftdjv6 5884  404.html
QmUJUdDtY1hLt73buoaaaDm2rARRVpkYYDHa8BvnZq3TY3 -     _next/
Qme1DM3r38NsjAXYAoazamgrdpk1CffLiPc14ZHp5Dgya1 15086 favicon.ico
QmNufHi8Rgwx6K4854aaa8mSpHS5pXznHvMXrrU4yvk8HC -     images/
QmeUAy5yNYo67C8id7acWyrrUtm6aks4AQcoDhcveYXrKE 5130  index.html
Qmdd8btEki1ASFBjMeeeaDNyAAzXH1skok8csiPQWWrnaS 1101  vercel.svg

You could also use the IPFS Desktop App to see your content, it has a nice GUI and extra content to better understand how IPFS works. It'll also run a IPFS node for you locally so you can obtain content from other peers.

(This video provides a great introdction to how IPFS works)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.