Workshop for starknetCC (nextjs x starknetjs x cairo)

Overview

NextJS - Starknet.js - Cairo • Workshop

StarknetCC - Full dApp workshop by Alpha Road team

You'll find the PDF presentation here

Introduction

This workshop will show you how to dev a full Starknet dApp with NextJS & Starknet.js, including multi-wallets support(Argent-x | Braavos) and multi-call transactions.

This repo contains the front-end part, you'll find the contracts part here (access controller)

You'll also use an ERC20 contract, with a 'freeMint' function added allowing you to mint up to 1k tokens per call(see ABI).

This workshop currently run on the Starknet Goerli Testnet

Use case

Explore the contract interactions in NextJS by using an access controller contract (whitelist) & ERC20 contracts deployed on Starknet.

  • Contract interactions
    • Start with existing contracts
    • Deploy & connect your own
  • Access controller
    • freeSlotsCount
    • isAllowed
    • register
  • Minting tokens (multicalls)

The Goal

TODO

Prerequisite

To follow this workshop you should at least:

  • Have a Starknet compatible wallet installed (with some Starknet Goerli ETH in wallet to do TX's)
  • Have basic knowledge in ReactJS / NextJS framework
  • Have basic knowledge in Cairo smart contracts development
  • Have basic knowledge on how Starknet works(BC in general, Account abstraction, ...)

About the tooling:

  • IDE
  • Yarn or NPM
  • Nile (smart contracts part)

Clone the repository

git clone [email protected]:419Labs/workshop-arf-dapp.git
cd workshop-arf-dapp

Install Dependencies

yarn | npm install 

Run in dev

yarn dev | npm run dev

File tree

Here are the interesting files tree you'll have to update/use during this workshop

  • src
    • components
      • wallet
        • Block.tsx
        • MultiMint.tsx
        • RegisterWhitelist.tsx
        • Transactions.tsx
        • WalletConnect.tsx
    • pages
      • _app.tsx
      • index.tsx
    • context
      • BlockProvider
      • ContractProvider
      • StarknetProvider
      • TransactionsProvider
    • contracts
      • abis
        • ARF_ERC20.json
        • AccessController.json
      • addresses.ts

TODO

  1. Familiarize a little with the project
    1. See the file tree
    2. Contract addresses are located in contract constants
    3. Use of React Context to isolate code complexity
    4. (use of ChakraUI components library)
    5. Uncomment part by part the workshop in index.ts
  2. Fetching block infos
    1. Update the StarknetProvider to connect to the default Starknet provider by using Starknet.js
    2. Update the BlockProvider, use the current provider to fetch current block infos
    3. (The UI part is already done here)
  3. Wallet connect
    1. Look at the WalletConnect button component
    2. Update the "connectBrowserWallet" StarknetProvider to ask user wallet connection by using get-starknet library
      1. Update the default provider by the user provider
    3. You should be able to connect with Braavos or ArgentX, and see your current address on the UI
  4. Your first transaction
    1. Start by taking a look at the Contract Provider model
    2. You can now update the RegisterWhitelist component to
      1. Fetch the total free slots currently available
      2. Fetch the current whitelisted status of the connected account
      3. Register to the whitelist if there is free slots & the connected account is not currently whitelisted
  5. Multi-call
    1. Look at the MultiMint component
    2. Here you'll have to
      1. Fetch balances of arfBTC & arfETH when needed
      2. Mint both arfBTC & arfETH in 1 TX using the multicall
    3. (You can also make a 'register to whitelist + mint token' in 1 TX as well)
  6. Deploy your own Access Controller
    1. You can put aside IDE for the time & open your terminal
    2. clone the access-controller repo
      1. > git clone [email protected]:419Labs/access-controller-contracts.git
    3. Use nile to compile & deploy the contracts
      1. > nile compile
      2. > nile deploy AccessController --alias my_access_controller [...args] --network=goerli
      3. Wait until the contract is deployed
        1. You can check the status of the TX by calling get_transaction on the starknet cli
    4. Once it's ok, you can test it by calling freeSlotsCount on the deployed contract
      1. With Nile CLI
      2. With the voyager
    5. You can now replace the ACCESS_CONTROLLER_CONTRACT_ADDRESS in the contract constants to use your own
  7. Add your feature
    1. In this part you'll add your own feature from A to Z
    2. Start by choosing the feature you want to implement
      1. Remove from whitelist, Get a list of all whitelisted addresses, ...
    3. Implement the feature on the AccessController_base contract & Add the corresponding @view or @external interface on the AccessController contract
    4. Compile & Deploy your new contract
      1. Get the new abi.json & update the current one
    5. Implement the new feature on the UI
      1. By create a new component in /src/components/wallet & add it in the index

Contract addresses

Access Controller

0x027b91a18ed8c3ea77617c1818fb43ab0397144b956506181bf88ab9885a1338

arfETH ERC20

0x3dd7b0db7cca8e8468d06d27b40ca9368754c30d76900fcd19a65736fab9084
name: Ethereum Goerli
symbol: arfETH
supply: Infinite

arfBTC ERC20

0x72df4dc5b6c4df72e4288857317caf2ce9da166ab8719ab8306516a2fddfff7
name: Bitcoin Goerli
symbol: arfBTC
supply: Infinite

Go further

There some improvements you can make to improve this workshop, here is a non-exhaustive list:

  • Save transactions in local storage
  • Display current transaction information on the UI (toast, history panel, ...)
  • Auto reload of: whitelisted after register, balance after mint
  • Implement a button to be able to add a specific token to your wallet
  • ...

Docs

Here is all the docs you'll need to complete the workshop

https://www.starknetjs.com/

https://github.com/starknet-community-libs/get-starknet

https://github.com/OpenZeppelin/nile

https://github.com/OpenZeppelin/cairo-contracts

Helps

Work with big numbers in JavaScript could be a mess. As you'll probably use the 18 decimals standard for the token balances, you'll not be able to store it as a Number but as a string representation. To abstract the complexity, you can use the well known Ether.js library (especially the formatUnits & parseUnits) in completion of the Starknet.js helpers(toFelt, bnToUint256, ...)

Thanks

Forked from Cairopal

License

This workshop is released under the AGPL-3.0-only.

You might also like...

A workshop about JavaScript iteration protocols: iterator, iterable, async iterator, async iterable

A workshop about JavaScript iteration protocols: iterator, iterable, async iterator, async iterable

JavaScript Iteration protocol workshop A workshop about JavaScript iteration protocols: iterator, iterable, async iterator, async iterable by @loige.

Dec 20, 2022

Resources for the App.js Conf Workshop 2022 hosted by Evan Bacon and Lydia Hallie

App.js Conf 2021 React Native workshop Order of sections: up-and-going: Learn about React Native and options to start your first project. get-started:

Sep 14, 2022

Here are the sources for the wdi5 workshop at UI5con 2022.

wdi5 workshop at UI5con 2022 Here are the sources for the wdi5 workshop at UI5con 2022. prerequisites please have this installed on your 'puter: Node

Oct 19, 2022

REST API for a rudimentary blog - from Prisma Day 22 NestJS workshop

NestJS Workshop Prisma Day 22 - Let's build a REST API with NestJS and Prisma! Welcome to the code repository for the Prisma Day 2022 NestJS Workshop!

Jan 3, 2023

Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this workshop, we'll look at some more advanced use cases when building Remix applications.

💿 Advanced Remix Workshop Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. In this

Dec 9, 2022

Remix enables you to build fantastic user experiences for the web and feel happy with the code that got you there. Get a jumpstart on Remix with this workshop.

💿 Remix Fundamentals Build Better websites with Remix Remix enables you to build fantastic user experiences for the web and feel happy with the code

Dec 25, 2022

Matt's Advanced TypeScript workshop

Advanced TypeScript Workshop Hello! My name's Matt Pocock. This is a workshop repo to teach you about Advanced TypeScript. Topics Covered Using typeof

Dec 24, 2022

Under the Sea is an official AWS workshop delivered by AWS SAs and AWS Partners to help customers and partners to learn about AIOps with serverless architectures on AWS.

Under the Sea - AIOps with Serverless Workshop Under the Sea is an exciting MMORPG developed by the famous entrepreneur behind Wild Rydes, the most po

Nov 16, 2022

Matt's Advanced TypeScript workshop

Advanced TypeScript Workshop Hello! My name's Matt Pocock. This is a workshop repo to teach you about Advanced TypeScript. Topics Covered Using typeof

Sep 20, 2022
Owner
419 Labs
419 Labs
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
A set of librairies in Cairo for use on StarkNet

Sekai StarkNet Libraries A series of libraries to help using Cairo on StarkNet. Examples for use in other Cairo contracts are provided in examples. Co

Sekai 38 Nov 14, 2022
The (unofficial) Cairo extension for vscode

Cairo extension (unofficial) Introduction The Starkware team is doing a great job in developing the Cairo language and the Starknet layer2. At the tim

qdqdqd.eth 15 Sep 29, 2022
ITkonekt .NET workshop

Autobarn This is the sample application for Dylan Beattie's workshop on distributed systems with .NET. It's an Asp.NET Core web application based on v

Ursatile 1 Dec 19, 2021
Repository for hands on practice in Git and GitHub workshop

Git and Github Workshop Jan 2022 Successful contributors ✨ of this project will be featured on the GDSC website so as to bring attraction and learn vi

IIIT Vadodara Open Source 2 Feb 10, 2022
GatsbyConf - Decoupling Drupal Using Gatsby: A Crash Course workshop

GatsbyConf - Decoupling Drupal Using Gatsby: A Crash Course workshop

Octahedroid 7 Sep 29, 2022
Workshop contruyendo una API Rest con Node.js + Koa.js

Workshop contruyendo una API Rest con Node.js + Koa.js Tabla de Contenido Acerca de Introducción Explicación del caso de uso Ciclo de vida de las soli

Jhony Rivero 6 Apr 8, 2022
Portuguese version of the Cassandra driver javascript node.js workshop

Versão em Português do workshop Cassandra driver javascript node.js Olá e bem-vindo! Este é o repositório complementar para a apresentação prática dos

DataStax Developers 2 Mar 17, 2022
For this workshop, we're going to learn more about cloud computing by exploring how to use Pulumi to build, configure, and deploy a real-life, modern application using Docker

For this workshop, we're going to learn more about cloud computing by exploring how to use Pulumi to build, configure, and deploy a real-life, modern application using Docker. We will create a frontend, a backend, and a database to deploy the Pulumipus Boba Tea Shop. Along the way, we'll learn more about how Pulumi works.

Kat Cosgrove 9 Dec 29, 2022