The repo shows how to connect your React app to StarkNet

Overview

StarkNet.js + Cairo + Hardhat + React

This repo shows how to connect your React app to StarkNet.

Scripts helper

mkdir -p build

starknet-compile contracts/cairo/counter.cairo
--output build/counter.json
--abi src/lib/abi/counter.json

export CONTRACT_ADDRESS=0x062f0eab9a09ee676a45211096f4d6b1d70bfd2a43ce8b7df284dd644800d6c3 starknet call
--address $CONTRACT_ADDRESS
--abi build/counter.json
--function getCounter

Content

Contracts

The contracts directory contains a simple Cairo contract:

  • incrementCounter(amount): increment the counter by the given amount.
  • counter(): returns the current counter value.

The contract is deployed at 0x5ee069079158344aef3526153db4ba7a3e39481a285059f21c34c4592ed5b2d on StarkNet alpha 3.

React

The src/providers directory contains two React providers:

  • BlockNumberProvider: returns the current StarkNet block number.
    • useBlockNumber: returns the current block number. Returns undefined before loading the block number for the first time.
  • TransactionsProvider: contains a list of transactions sent to StarkNet. The state of this provider is reset between page reloads, for a production app you may want to store its state to local storage.
    • useTransactions: returns a list of all transactions.
    • useTransaction(hash): returns the transaction with the given hash, or undefined if no transaction matches.

The src/lib/hooks.ts file contains the following hooks:

  • useStarknetCall(contract, method, args): calls the specified method on the contract with the given arguments. Returns the raw call output (either a string, an array of strings, or undefined).
  • useStarknetInvoke(contract, method): returns an invoke(args) function to invoke the specified method with the given arguments. Also returns an hash that is set to the hash of the most recent invoke.

The src/lib/counter.ts file shows how to load a Cairo contract using a React hook.

The src/App.tsx file shows how to use the hooks and providers to interact with the on-chain counter contract.

License

Copyright 2021 Francesco Ceccon

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
You might also like...
Weather-App - A Web application shows dynamic weather report using Reactjs and openweather
Weather-App - A Web application shows dynamic weather report using Reactjs and openweather

Screenshots of this project Getting Started with Create React App This project w

Just made this repo to test firebase with my react app.

Firebase Setup Deployment Status Just created this repo because I tend to forget the steps to add firebase to my projects. Steps Go to Firebase home p

Simple netflix clone using React and TMDB API to pull in movies/tv shows.

Netflix React Clone Simple netflix clone using React and TMDB API to pull in movies/tv shows. Uses Material UI for the frontend. Still a work in progr

Application made with React that shows the most current Movies on the market

Movies themoviedb Application made with create-react-app that shows the most current Movies on the market using the api themoviedb Technologies used T

Shopping-cart - Simple shopping cart prototype which shows how React components and Redux can be used to build a friendly user experience
This web application shows the current cryptocurrencies using an API

This web application shows the current cryptocurrencies using an API from coingecko

No-Spoilers-Client: Allows the user to track the shows they are watching
No-Spoilers-Client: Allows the user to track the shows they are watching

No-Spoilers-Client: No Spoilers! is the tool you need in the modern world of non-stop streaming to avoid having your favourite TV shows ruined by either friends or the Internet.

⭐ A non-SSR React starter with TypeScript / No Redux repo with the aim to implement scalable gold star standards from the get go!

A React starter repo with the aim to implement "scalable gold star" standards from the get go giving some examples with a couple of screens.

A p2p version-controlled repo Hypercore's new multiwriter Autobase.

Hyper-VCR (Version Controlled Repo) A p2p version-controlled repo Hypercore's new multiwriter Autobase. TODOs Implement indexer _apply Workspace local

Owner
Sylvain Laurent
Internet wanderer. Cryptohobo.
Sylvain Laurent
An opensource platform to connect with awesome collaborators to work with your side-projects✨

ProStack ?? An open-source platform ?? to peep into some highly interesting and exciting projects & connect with those project's owner for collaborati

Parth Pandya 6 Jul 18, 2022
Al Mentoria is a virtual space to connect with mentors that can help you with your technical as well as behavioral issues

Al Mentoria is a virtual space to connect with mentors that can help you with your technical as well as behavioral issues. If you are stuck somewhere and need a second look at things, make a reservation now.

Uplift Lab 12 Nov 25, 2022
Social Media mobile app that allows users to connect via QR scanning. Built-in React Ionic together with @Mic01.

Tap-n-Chat Mobile Messaging app that allows the user to login/signup and message other users. The app is able to generate and scan QR codes to add use

Connor de Bruyn 2 Oct 3, 2022
Solvent Connect Wallet - A react web app that help its users to see information about the connected wallet and make airdrop or send solana

Solvent Connect Wallet - A react web app that help its users to see information about the connected wallet and make airdrop or send solana

Bhagya Mudgal 0 Aug 1, 2022
Learning how to connect and operate between NodeJS, MySQL and React, build a small app

NodeJS (Express) + MySQL + React JS Backend and frontend side Learning how to connect and operate between NodeJS, MySQL and React, build a small app.

Serjo 2 Apr 12, 2022
Randomfy takes your most listened Spotify artists, selects one of them and shows you similar artists

Randomfy takes your most listened Spotify artists, selects one of them and shows you similar artists, so you can meet new artists based on the previous selected one.

Raul Andrade 9 Nov 6, 2022
DeFi application with a custom ERC20 token and staking vault using vite to bundle a React.js application and ethers library to connect to the blockchain

In this workshop we will be building a DeFi application with a custom ERC20 token and staking vault using vite to bundle a React.js application and ethers library to connect to the blockchain.

Atahan Yorgancı 11 Nov 19, 2022
This uses Azure AI Text Analytics services to teach on how to connect an AI service to a web-based system

Azure AI: Text Analytics services using react This app uses the Azure text analytics services to call various services such as sentiment analysis, ent

Uzochukwu Precious 2 Jun 7, 2022
A demo app of the Hacker News website clone, which shows Next.js 12's experimental React Server Components support

A demo app of the Hacker News website clone, which shows Next.js 12's experimental React Server Components support

Vercel 681 Jan 6, 2023
This app shows all of the Rick and Morty charachters.

This app shows all of the Rick and Morty charachters.

Farnam Homayounfar 1 Oct 23, 2021