Giter Site home page Giter Site logo

ownerc20's Introduction

This project is the implementation of an example application with the following components:

  • onchain: implementation of a token using ERC20 standard from @openzeppelin.
  • offchain:
    • backend (moralis): used to manage users, sessions and listen to chain events;
    • frontend (next.js): provides pages for registration, authentication and dashboard with information.

This is a Next.js project bootstrapped with create-next-app.

Getting Started

Install dependencies:

yarn
# or
npm install

On chain

Run tests

To get an overview of the possible actions provided by the OwnERC20 contract:

yarn hardhat test
# or
npx hardhat test
Own ERC20
  ✔ should deploy with initial supply assigned to the owner
  ✔ should return zero balance for new wallets
  ✔ should allow the registration of a new address
  ✔ should allow the unregistration an address
  ✔ should allow transfer from owner to other accounts
  ✔ should allow transfer from other accounts to owner
  ✔ shouldnt allow transfers from accounts other than the owner
  ✔ shouldnt allow owner to give (mint) to unregistered addresses
  ✔ should allow owner to give (mint) tokens
  ✔ shouldnt allow accounts to give (mint) tokens to other accounts (including themselves)
  ✔ shouldnt allow owner to deduct (burn) from unregistered addresses
  ✔ should allow owner to deduct (burn) tokens
  ✔ shouldnt allow accounts to deduct (burn) tokens from other accounts (including themselves)

Deploy

To deploy configure the target network on hardhat.config.ts in the networks property. For example in rinkeby:

const config: HardhatUserConfig = {
  // ... root level
  networks: {
    rinkeby: {
      url: "<url here>",
      chainId: 4, // <chain id, 1 is mainnet>
      accounts: ["<your private key>"],
    },
  },
};

export default config;

And then in a terminal use the command to deploy, made available by hardhat-deploy plugin:

yarn hardhat deploy --network rinkeby
# or
npx hardhat deploy --network rinkeby

Tasks

In order to get some useful control of the application, some tasks are provided:

  • faucet <to>: transfers 1 ether from the 0-index account to another (localhost to send some fake ether using default accounts)

  • give <to> <amount>: mints some tokens into an account

  • deduct <from> <amount>: burns some tokens from an account

  • register <target>: registers an address in the contract

Off chain

The off chain application code is in ./webapp. It is a Next.js application and has three pages: sign up, sign in and index. The backend parte is hosted in moralis that provides backend for storing users, sessions and chain events, which also provides good SDKs for react development.

  • sign up: requests username, e-mail and password for a new user. Sends this information to the backend. Immediately redirects to the user dashboard since Moralis already signs the user in.

  • sign in: form to sign a user in using Moralis.

  • index: the user dashboard. It gets the signed user information (username, wallet address) from the Moralis backend, the basic contract information (token symbol, token name and user balance) from the chain using ethers.js and listens for chain events on websockets provided by Moralis as well.

Configure

Set the values in ./webapp/config.ts:

export default {
  PRIVATE_KEY: "<private key>",
  NETWORK_URL: "<network url>",
  MORALIS_SERVER_URL: "<moralis server url>",
  MORALIS_APP_ID: "<moralis app id>",
};

Run frontend development server

Run the development server:

npm run dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

PS: A local chain provided by Hardhat can also be used, jsut make sure to properly configure moralis to point to your local chain.

ownerc20's People

Contributors

renantarouco avatar

Watchers

James Cloos avatar  avatar

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.