Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync Ch-1 with the last PR version the Scaffold Stark #181

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ jobs:
uses: actions/checkout@master

- name: Install scarb
run: curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.8.5
run: curl --proto '=https' --tlsv1.2 -sSf https://docs.swmansion.com/scarb/install.sh | sh -s -- -v 2.9.2

- name: Install snfoundryup
run: curl -L https://raw.githubusercontent.com/foundry-rs/starknet-foundry/master/scripts/install.sh | sh

- name: Install snforge
run: snfoundryup -v 0.33.0
run: snfoundryup -v 0.34.0

- name: Run snforge tests
run: snforge test
Expand Down Expand Up @@ -66,4 +66,4 @@ jobs:

- name: Build Next.js project
run: yarn build
working-directory: ./packages/nextjs
working-directory: ./packages/nextjs
Empty file removed .gitmodules
Empty file.
6 changes: 3 additions & 3 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
scarb 2.8.5
starknet-foundry 0.33.0
starknet-devnet 0.2.0
scarb 2.9.2
starknet-foundry 0.34.0
starknet-devnet 0.2.3
2 changes: 1 addition & 1 deletion .yarn/plugins/@yarnpkg/plugin-typescript.cjs

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
compressionLevel: mixed

enableColors: true

enableGlobalCache: false

nmHoistingLimits: workspaces

nodeLinker: node-modules

plugins:
- path: .yarn/plugins/@yarnpkg/plugin-typescript.cjs
spec: "@yarnpkg/plugin-typescript"

yarnPath: .yarn/releases/yarn-3.2.3.cjs
6 changes: 3 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Contributing to Scaffold-Stark

Thank you for your interest in contributing to Scaffold-Stark! Your support enhances this StarkNet-focused framework that bridges smart contract integration with web applications.
Thank you for your interest in contributing to Scaffold-Stark! Your support enhances this Starknet-focused framework that bridges smart contract integration with web applications.

## About the Project

**Scaffold-Stark** provides a full DApp development template, offering seamless integration of StarkNet smart contracts with web applications. **SpeedrunStark.com** offers interactive challenges that serve to practice your Cairo and StarkNet skills, learn how to use the provided hooks, and launch your applications swiftly with potential rewards.
**Scaffold-Stark** provides a full DApp development template, offering seamless integration of Starket smart contracts with web applications. **SpeedrunStark.com** offers interactive challenges that serve to practice your Cairo and Starknet skills, learn how to use the provided hooks, and launch your applications swiftly with potential rewards.

## Project Vision

Our goal is to simplify the DApp development and learning process, enabling developers to launch applications efficiently while understanding the intricacies of StarkNet.
Our goal is to simplify the DApp development and learning process, enabling developers to launch applications efficiently while understanding the intricacies of Starknet.

## How to Get Involved

Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Before you begin, you need to install the following tools:

### Compatible versions

- Starknet-devnet - v0.2.0
- Scarb - v2.8.5
- Snforge - v0.33.0
- Cairo - v2.8.5
- Starknet-devnet - v0.2.3
- Scarb - v2.9.2
- Snforge - v0.34.0
- Cairo - v2.9.2
- Rpc - v0.7.1

Make sure you have the compatible versions otherwise refer to [Scaffold-Stark Requirements](https://github.com/Scaffold-Stark/scaffold-stark-2?.tab=readme-ov-file#requirements)
Expand Down Expand Up @@ -290,3 +290,4 @@ For production-grade applications, it's recommended to obtain your own API keys
> 🏃 Head to your next challenge [here](https://github.com/Scaffold-Stark/speedrunstark/tree/challenge-2-token-vendor).

> 💬 Problems, questions, comments on the stack? Post them to the [🏗 scaffold-stark developers chat](https://t.me/+wO3PtlRAreo4MDI9)
>
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ss-2",
"version": "0.3.2",
"version": "0.3.13",
"author": "Q3 Labs",
"license": "MIT",
"private": true,
Expand All @@ -13,7 +13,7 @@
"scripts": {
"chain": "yarn workspace @ss-2/snfoundry chain",
"deploy": "yarn workspace @ss-2/snfoundry deploy",
"deploy:reset": "yarn workspace @ss-2/snfoundry deploy:reset",
"deploy:no-reset": "yarn workspace @ss-2/snfoundry deploy --no-reset",
"test": "yarn workspace @ss-2/snfoundry test",
"compile": "yarn workspace @ss-2/snfoundry compile",
"start": "yarn workspace @ss-2/nextjs dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
NEXT_PUBLIC_PROVIDER_URL=https://starknet-sepolia.public.blastapi.io/rpc/v0_7
NEXT_PUBLIC_PROVIDER_URL=https://starknet-sepolia.blastapi.io/64168c77-3fa5-4e1e-9fe4-41675d212522/rpc/v0_7
2 changes: 1 addition & 1 deletion packages/nextjs/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"extends": "next/core-web-vitals"
"extends": "next"
}
2 changes: 1 addition & 1 deletion packages/nextjs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ yarn-error.log*

# typescript
*.tsbuildinfo
next-env.d.ts
next-env.d.ts
71 changes: 31 additions & 40 deletions packages/nextjs/app/configure/_components/DownloadContracts.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
"use client";

import { useProvider } from "@starknet-react/core";
import React, { useState } from "react";
import { useCallback, useState } from "react";
import { useTargetNetwork } from "~~/hooks/scaffold-stark/useTargetNetwork";
import configExternalContracts from "~~/contracts/configExternalContracts";
import { deepMergeContracts } from "~~/utils/scaffold-stark/contract";
import { ArrowDownTrayIcon } from "@heroicons/react/24/outline";
import Link from "next/link";
import prettier from "prettier/standalone";
import parserTypescript from "prettier/plugins/typescript";
import prettierPluginEstree from "prettier/plugins/estree";

export default function DownloadContracts() {
const { provider } = useProvider();
const [address, setAddress] = useState<string>("");

const { targetNetwork } = useTargetNetwork();
const [symbol, setSymbol] = useState<string>("");
const handleInputChange: React.ChangeEventHandler<HTMLInputElement> = (e) => {
const value = e.target.value;
setSymbol(value);
};
const [contractName, setContractName] = useState<string>("");

const handleDownload = async () => {
const handleDownload = useCallback(async () => {
if (!address) return;
try {
const [apiResponse, classHash] = await Promise.all([
Expand All @@ -29,7 +28,7 @@ export default function DownloadContracts() {

const contractData = {
[targetNetwork.network]: {
[symbol]: {
[contractName]: {
address,
classHash,
abi: apiResponse.abi,
Expand All @@ -46,17 +45,23 @@ export default function DownloadContracts() {
console.error(error);
return;
}
};
}, [address, provider, contractName, targetNetwork.network]);

const generateContractsFile = (contractsData: Object) => {
const generateContractsFile = async (contractsData: Object) => {
const generatedContractComment = `/**
* This file is autogenerated by Scaffold-Stark.
* You should not edit it manually or your changes might be overwritten.
*/`;

const fileContent = JSON.stringify(contractsData, null, 2);
const configExternalContracts = `${generatedContractComment}\n\nconst configExternalContracts = ${fileContent} as const;\n\nexport default configExternalContracts;`;

const configExternalContracts = await prettier.format(
`${generatedContractComment}\n\nconst configExternalContracts = ${JSON.stringify(
contractsData,
)} as const;\n\nexport default configExternalContracts;`,
{
parser: "typescript",
plugins: [parserTypescript, prettierPluginEstree],
},
);
const blob = new Blob([configExternalContracts], {
type: "text/typescript",
});
Expand All @@ -78,49 +83,35 @@ export default function DownloadContracts() {
<div className="flex-1">
<div className="font-bold my-3 text-lg">Instructions</div>
<p className="my-2">
This tool allows you to fetch the ABI of a contract by entering
its address. It will download a configuration file that can be
used to replace or append to your local{" "}
This tool generate a contract configuration file by entering a
contract address and name. The downloaded file can be used to
replace your local{" "}
<code className="text-function">configExternalContracts.ts</code>{" "}
file, allowing you to debug in the{" "}
<code className="text-function">/debug</code> page.
for debugging.
</p>
<ol className="flex flex-col gap-2 list-decimal list-outside my-6 space-y-1 ml-4">
<li className="pl-3">Enter contract name and address</li>
<li className="pl-3">
Enter the contract address and name within the designated input
fields.
</li>
<li className="pl-3">
Click the{" "}
Click{" "}
<strong className="text-function">
Download Contract File
</strong>{" "}
button.
</li>
<li className="pl-3">
The tool will fetch the ABI, address, and classHash from the
network and generate a configuration file.
</strong>
</li>
<li className="pl-3">
Download the file and replace it to your local{" "}
Replace your{" "}
<code className="text-function">
configExternalContracts.ts
</code>{" "}
file.
file
</li>
<li className="pl-3">
Use the{" "}
Debug your contract at{" "}
<Link href={"/debug"} className="text-function">
<code>/debug</code>
</Link>{" "}
page to interact with and test the contract using the scaffold
hooks.
and use hooks with the downloaded contract
</li>
</ol>
<p className="mt-2">
Ensure that the format of the ABI matches the expected format in
your project before replacing the file.
</p>
</div>
<div className="flex-1 px-12">
{targetNetwork && (
Expand All @@ -136,8 +127,8 @@ export default function DownloadContracts() {
Contract
</div>
<input
value={symbol}
onChange={handleInputChange}
value={contractName}
onChange={(e) => setContractName(e.target.value)}
list="symbols"
className="input bg-input input-ghost rounded-none focus-within:border-transparent focus:outline-none h-[2.2rem] min-h-[2.2rem] px-4 border w-full text-sm placeholder:text-[#9596BF] text-neutral"
placeholder="Enter contract name"
Expand Down
6 changes: 1 addition & 5 deletions packages/nextjs/app/configure/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ export const metadata = getMetadata({
});

const Configure: NextPage = () => {
return (
<>
<DownloadContracts />
</>
);
return <DownloadContracts />;
};

export default Configure;
2 changes: 1 addition & 1 deletion packages/nextjs/app/debug/_components/contract/Array.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,4 @@ export const ArrayInput = ({
</div>
</div>
);
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ export const ContractInput = ({
{renderInput()}
</div>
);
};
};
35 changes: 21 additions & 14 deletions packages/nextjs/app/debug/_components/contract/ContractUI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ import {
useNetworkColor,
} from "~~/hooks/scaffold-stark";
import { useTargetNetwork } from "~~/hooks/scaffold-stark/useTargetNetwork";
import { ContractName } from "~~/utils/scaffold-stark/contract";
import {
ContractCodeStatus,
ContractName,
} from "~~/utils/scaffold-stark/contract";
import { ContractVariables } from "./ContractVariables";
import { ClassHash } from "~~/components/scaffold-stark/ClassHash";

Expand Down Expand Up @@ -40,23 +43,18 @@ export const ContractUI = ({
false,
);
const { targetNetwork } = useTargetNetwork();
const { data: deployedContractData, isLoading: deployedContractLoading } =
useDeployedContractInfo(contractName);
const {
raw: deployedContractData,
isLoading: deployedContractLoading,
status,
} = useDeployedContractInfo(contractName);

const tabs = [
{ id: "read", label: "Read" },
{ id: "write", label: "Write" },
];

if (deployedContractLoading) {
return (
<div className="mt-14">
<span className="loading loading-spinner loading-lg"></span>
</div>
);
}

if (!deployedContractData) {
if (status === ContractCodeStatus.NOT_FOUND) {
return (
<p className="text-3xl mt-14">
{`No contract found by the name of "${contractName}" on chain "${targetNetwork.name}"!`}
Expand All @@ -79,7 +77,7 @@ export const ContractUI = ({
classHash={deployedContractData.classHash}
size="xs"
/>
<div className="flex gap-1 items-center">
<div className="flex gap-1 items-center h-5">
<span className="font-bold text-sm">Balance:</span>
<Balance
address={deployedContractData.address}
Expand Down Expand Up @@ -108,7 +106,11 @@ export const ContractUI = ({
{tabs.map((tab) => (
<a
key={tab.id}
className={`tab h-10 ${activeTab === tab.id ? "tab-active !bg-[#8A45FC] !rounded-[5px] !text-white" : ""}`}
className={`tab h-10 ${
activeTab === tab.id
? "tab-active !bg-[#8A45FC] !rounded-[5px] !text-white"
: ""
}`}
onClick={() => setActiveTab(tab.id)}
>
{tab.label}
Expand All @@ -130,6 +132,11 @@ export const ContractUI = ({
/>
)}
</div>
{deployedContractLoading && (
<div className="absolute inset-0 rounded-[5px] bg-white/20 z-10">
<div className="animate-spin h-4 w-4 border-2 border-purple-500 border-t-transparent rounded-full absolute top-4 right-4" />
</div>
)}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ export const DisplayVariable = ({
<div className="space-y-1 pb-2">
<div className="flex items-center">
<h3
className={`font-medium text-lg mb-0 break-all ${isDarkMode ? "text-[#4DB4FF]" : "text-[#7800FF]"}`}
className={`font-medium text-lg mb-0 break-all ${
isDarkMode ? "text-[#4DB4FF]" : "text-[#7800FF]"
}`}
>
{abiFunction.name}
</h3>
Expand Down
10 changes: 7 additions & 3 deletions packages/nextjs/app/debug/_components/contract/Struct.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,15 @@ export const Struct = ({
return (
<div>
<div
className={`collapse bg-base-200 pl-4 pt-1.5 pb-2 border-2 ${isDisabled ? "border-base-100 cursor-not-allowed" : "border-secondary"} custom-after`}
className={`collapse bg-base-200 pl-4 pt-1.5 pb-2 border-2 ${
isDisabled ? "border-base-100 cursor-not-allowed" : "border-secondary"
} custom-after`}
>
{!isDisabled && <input type="checkbox" className="min-h-fit peer" />}
<div
className={`collapse-title p-0 min-h-fit peer-checked:mb-2 text-primary-content/50 ${isDisabled && "cursor-not-allowed"} `}
className={`collapse-title p-0 min-h-fit peer-checked:mb-2 text-primary-content/50 ${
isDisabled && "cursor-not-allowed"
} `}
>
<p className="m-0 p-0 text-[1rem]">{abiMember.type}</p>
</div>
Expand Down Expand Up @@ -132,4 +136,4 @@ export const Struct = ({
</div>
</div>
);
};
};
Loading
Loading