Code Monkey home page Code Monkey logo

inkathon's Introduction

INK!athon โ€“ DApp Boilerplate for Substrate & ink!

Typescript Next.js Tailwind ink! Scio Labs

Cover Image


This is an opinionated boilerplate to get up and running with dApp development in the Substrate ecosystem, especially with ink! smart contracts. It uses custom-built useInkathon React Hooks that abstract & improve the polkadot.js experience.

By Dennis Zoma ๐Ÿ’ซ & Scio Labs ๐Ÿช


Table of Contents:

  1. Disclaimer ๐Ÿšจ
  2. The Stack
  3. Projects using it
  4. Getting Started
    1. Frontend
    2. Contracts
  5. Development
    1. Frontend Quickstart
    2. Contracts Quickstart
    3. VSCode Setup
  6. Customization
  7. Deployment
  8. FAQs & Troubleshooting

Disclaimer ๐Ÿšจ

This repository is still work-in-progress and there are probably bugs. See the open issues.

The Stack

  • Package-Manager: pnpm
  • Smart Contract Development: ink!, cargo
  • Frontend: next
  • Misc:
    • Linting & Formatting: eslint, prettier, husky, lint-staged

The Stack of INK!athon

Projects using it

Below you find a few projects that use this boilerplate, a variation of it, or have a similar setup that inspired it:

Getting Started

Frontend

# 1. Install pnpm (https://pnpm.io/installation)
npm i -g pnpm

# 2. Install dependencies
pnpm install

# 3. Copy & fill environments
# NOTE: Documentation of environment variables can be found in the according `.example` file
# NOTE: Start with only the alephzero-testnet
cp packages/frontend/.env.local.example packages/frontend/.env.local

Contracts

# 1. Install Rust: https://docs.substrate.io/install/
# NOTE: Leave out the "Compile a Substrate node" part for now
rustup component add rust-src
rustup target add wasm32-unknown-unknown

# 2. Install ink! tooling (https://use.ink/getting-started/setup#ink-cli)
cargo install cargo-contract --force --locked --git https://github.com/paritytech/cargo-contract.git
cargo install cargo-dylint dylint-link --force --locked

# 3. Install local substrate-contracts-node (https://github.com/paritytech/substrate-contracts-node)
cargo install contracts-node --force --git https://github.com/paritytech/substrate-contracts-node.git

Development

Frontend Quickstart

# NOTE: Can be executed in both, the root-dir or in `packages/frontend/`

# Start Frontend (Next.js)
pnpm dev

Contracts Quickstart

I created shorthand npm-scripts for most interactions (e.g. build, or starting a local node). Therefore, to execute those the active terminal directory needs to be packages/contracts. The full commands can be found in packages/contracts/package.json.

# Start local node with persistence & open contracts-ui
# NOTE: When using Brave, shields have to be taken down for the UIs
# NOTE: Just use `pnpm node` to not automatically open contracts-ui
pnpm dev

# Build Contracts
pnpm build

# Deploy Contracts with the generated `*.contract` file
# via drag'n'drop in contracts-ui in the browser

# Copy the deployed contracts address and save it via the following command
ADDRESS=โ€ฆ pnpm write-address

# NOTE: This command can also be adapted for different contracts and chains
ADDRESS=123 CHAIN=alephzero-testnet CONTRACT=new_greeter pnpm write-address

# Test Contracts
pnpm test

VSCode Setup

Workspace

I strongly recommend developing in VSCode by opening the workspace file located at .vscode/inkathon.code-workspace instead of just the directory. This has multiple advantages and assures a more predictable monorepo configuration. The first plugin listed below will help with getting used to it.

Plugins

I strongly recommend installing all plugins listed inside .vscode/extensions.json. They should be suggested automatically by VSCode.

Plugin Details
  1. zoma.vscode-auto-open-workspace โ€“ Automatically suggests opening the according .code-workspace file.
  2. dbaeumer.vscode-eslint โ€“ Adds ESLint editor support.
  3. esbenp.prettier-vscode โ€“ Adds Prettier editor support.
  4. bradlc.vscode-tailwindcss & lightyen.tailwindcss-intellisense-twin โ€“ Adds tailwindcss & twin.macro editor support.
  5. bungcip.better-toml โ€“ Adds .toml file support.
  6. rust-lang.rust-analyzer โ€“ Adds Rust language support.
  7. Optional: gruntfuggly.todo-tree & wayou.vscode-todo-highlight โ€“ Lists all TODO comments in your workspace.
  8. Optional: mikestead.dotenv โ€“ Adds syntax highlighting for .env files.

Snippets

The file packages/frontend/.vscode/frontend.code-snippets contains useful snippets for quickly creating components & pages with Next.js, React, Typescript, and twin.macro. Example: Enter "Function Component with Props" in an empty .tsx file to get a FC component boilerplate with an empty TypeScript interface declaration and already imported 'twin.macro'. Check out the snippet-file itself to get a full overview.

Customization

There are multiple places where you need to insert your actual project name & identifier. I highlighted most of these occurrences with a /* TODO */ comment in the code. When installing the todo-tree plugin listed above you can easily replace them one by one.

Additionally, there are the following un-highlighted occurrences:

  • The name of the .vscode/*.code-workspace file
  • The package names within package.json, packages/frontend/package.json, and packages/contracts/package.json
  • The workspace dependency defined in packages/frontend/package.json

Deployment

Setting up a deployment via Vercel is pretty straightforward as build settings are preconfigured in vercel.json. To get started, press the Deploy button and enter the default environment variables listed below.

Deploy with Vercel

Environment Variable Value
NEXT_PUBLIC_PRODUCTION_MODE true
NEXT_PUBLIC_URL https://your-repo.vercel.app
NEXT_PUBLIC_DEFAULT_CHAIN alephzero-testnet
NEXT_PUBLIC_DEFAULT_CHAIN ["alephzero-testnet"]

You can find more documentation on those environment variables in packages/frontend/.env.local.example and all available blockchain network identifiers in the useInkathon repository.

FAQs & Troubleshooting

What is pnpm and do I need it?

Pnpm works in my experience way faster and more reliably within monorepos than npm or yarn. When using it though, it's strongly recommended everyone on the team uses it. No installs should perform be performed nor any other lock files should be committed.

Also, esp. the contracts package has multiple shorthand npm scripts defined in its package.json that are recommended to use.

How to approach styling?

This boilerplate currently offers styling via the following options.

  • Chakra UI โ€“ Component library for quick prototyping e.g. during hackathons)
  • twin.macro โ€“ Tailwindcss within Styled Components via Emotion (see snippets)
  • Standard (S)CSS styles via className and *.module.(s)css files.

Important, in production it's recommended to use at most one of 1. and 2. to reduce bundle size.

Can I just use plain TailwindCSS?

The packages above can be easily switched out with plain TailwindCSS, a detailed guide that is coming soon. In the meantime, open an issue to get guidance.

Resources to learn more about Substrate, ink!, and polkadot.js

inkathon's People

Contributors

keeganquigley avatar

Watchers

 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.