Skip to content
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "major",
"comment": "BREAKING: bump to v5 for consistency with core package using starknet.js v8\n\nAlthough this package doesn't directly depend on starknet.js, it's part of the starknet-react monorepo and should maintain version parity with @starknet-react/core for consistency and to avoid confusion when users upgrade.",
"packageName": "@starknet-react/chains",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "major",
"comment": "BREAKING: upgrade starknet.js from 7.6.4 to 8.1.2\n\nThis upgrade includes breaking changes from starknet.js v8:\n- Internal RPC channel updated from 0.8.1 to 0.9.0\n- Contract class now uses _Contract instead of Contract\n- Response parser uses resourceBoundsOverhead instead of margin\n- Added new deployer and defaultTipType properties to Account\n- Block identifier defaults changed from 'pending' to 'latest'",
"packageName": "@starknet-react/core",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "major",
"comment": "BREAKING: bump to v5 for consistency with core package using starknet.js v8\n\nTemplates have been updated to use starknet.js v8.1.2 and will use @starknet-react packages v5.0.0.",
"packageName": "create-starknet",
"email": "[email protected]",
"dependentChangeType": "patch"
}
4 changes: 2 additions & 2 deletions docs/components/demo/read-contract.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function ReadContractInner() {
watch: true,
enabled: enable,
blockIdentifier:
blockIdentifier === "latest" ? BlockTag.LATEST : BlockTag.PENDING,
blockIdentifier === "latest" ? BlockTag.LATEST : BlockTag.PRE_CONFIRMED,
});

return (
Expand All @@ -52,7 +52,7 @@ export function ReadContractInner() {
</SelectTrigger>
<SelectContent>
<SelectItem value={BlockTag.LATEST}>Latest</SelectItem>
<SelectItem value={BlockTag.PENDING}>Pending</SelectItem>
<SelectItem value={BlockTag.PRE_CONFIRMED}>Pre-Confirmed</SelectItem>
</SelectContent>
</Select>

Expand Down
2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"lucide-react": "^0.438.0",
"react": "^18.2.0",
"safe-stable-stringify": "^2.5.0",
"starknet": "^7.6.4",
"starknet": "^8.1.2",
"starknetkit": "^2.12.1",
"tailwind-merge": "^2.5.2",
"tailwindcss-animate": "^1.0.7",
Expand Down
4 changes: 2 additions & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"peerDependencies": {
"get-starknet-core": "^4.0.0",
"react": "^18.0",
"starknet": "^7.6.4"
"starknet": "^8.1.2"
},
"devDependencies": {
"@starknet-react/typescript-config": "workspace:*",
Expand All @@ -52,7 +52,7 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"rimraf": "^4.1.2",
"starknet": "^7.6.4",
"starknet": "^8.1.2",
"tsup": "^8.0.2",
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.5.2"
Expand Down
13 changes: 9 additions & 4 deletions packages/core/src/hooks/use-account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,26 @@ describe("useAccount", () => {
"channel": RpcChannel2 {
"baseFetch": [Function],
"batchClient": undefined,
"blockIdentifier": "pending",
"blockIdentifier": "latest",
"chainId": undefined,
"channelSpecVersion": "0.8.1",
"channelSpecVersion": "0.9.0",
"headers": {
"Content-Type": "application/json",
},
"id": "RPC081",
"id": "RPC090",
"nodeUrl": "http://localhost:5050/rpc",
"requestId": 0,
"retries": 200,
"specVersion": undefined,
"transactionRetryIntervalFallback": undefined,
"waitMode": false,
},
"defaultTipType": "recommendedTip",
"deploySelf": [Function],
"deployer": Deployer {
"address": "0x02ceed65a4bd731034c01113685c831b01c15d7d432f71afb1cf1634b53a2125",
"entryPoint": "deploy_contract",
},
"getStateUpdate": [Function],
"paymaster": _PaymasterRpc {
"baseFetch": [Function],
Expand All @@ -110,7 +115,7 @@ describe("useAccount", () => {
"requestId": 0,
},
"responseParser": RPCResponseParser {
"margin": undefined,
"resourceBoundsOverhead": undefined,
},
"signer": Signer {
"pk": "0xe1406455b7d66b1690803be066cbe5e",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/hooks/use-balance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export function useBalance({

const refetchInterval =
refetchInterval_ ??
(blockIdentifier === BlockTag.PENDING && watch
(blockIdentifier === BlockTag.PRE_CONFIRMED && watch
? DEFAULT_FETCH_INTERVAL
: undefined);

Expand Down
8 changes: 4 additions & 4 deletions packages/core/src/hooks/use-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
type ArgsOrCalldata,
type BlockNumber,
BlockTag,
type CallResult,
type Contract,
type Result,
} from "starknet";

import { type UseQueryProps, type UseQueryResult, useQuery } from "../query";
Expand All @@ -33,7 +33,7 @@ export type CallQueryKey = typeof queryKey;

/** Options for `useCall`. */
export type UseCallProps = CallArgs &
UseQueryProps<Result, Error, Result, ReturnType<CallQueryKey>> & {
UseQueryProps<CallResult, Error, CallResult, ReturnType<CallQueryKey>> & {
/** The target contract's ABI. */
abi?: Abi;
/** The target contract's address. */
Expand All @@ -43,7 +43,7 @@ export type UseCallProps = CallArgs &
};

/** Value returned from `useCall`. */
export type UseCallResult = UseQueryResult<Result, Error>;
export type UseCallResult = UseQueryResult<CallResult, Error>;

/**
* Hook to perform a read-only contract call.
Expand Down Expand Up @@ -89,7 +89,7 @@ export function useCall({

const refetchInterval =
refetchInterval_ ??
(blockIdentifier === BlockTag.PENDING && watch
(blockIdentifier === BlockTag.PRE_CONFIRMED && watch
? DEFAULT_FETCH_INTERVAL
: undefined);

Expand Down
108 changes: 85 additions & 23 deletions packages/core/src/hooks/use-contract-factory.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,113 @@
import { useMemo } from "react";
import { type Abi, type CompiledContract, ContractFactory } from "starknet";
import { useCallback } from "react";
import {
type Abi,
type CompiledContract,
type CompiledSierraCasm,
Contract,
type RawArgs,
type UniversalDetails,
} from "starknet";

import { useAccount } from "./use-account";

/** Arguments for `useContractFactory`. */
export interface UseContractFactoryProps {
/** The compiled contract. */
/** The compiled contract (for declare and deploy). */
compiledContract?: CompiledContract;
/** The class hash */
classHash: string;
/** The CASM contract (required when declaring). */
casm?: CompiledSierraCasm;
/** The class hash (for deploy-only mode). */
classHash?: string;
/** The contract abi. */
abi?: Abi;
}

/** Options for deploying a contract. */
export interface DeployContractOptions {
/** Constructor calldata. */
constructorCalldata?: RawArgs;
/** Salt for address generation. */
salt?: string;
/** Make the address unique. */
unique?: boolean;
/** Additional transaction details. */
details?: UniversalDetails;
}

/** Value returned from `useContractFactory`. */
export interface UseContractFactoryResult {
/** The contract factory. */
contractFactory?: ContractFactory;
/** Function to deploy the contract. */
deployContract?: (options?: DeployContractOptions) => Promise<Contract>;
}

/**
* Hook to create a `ContractFactory`.
* Hook to deploy contracts using the new Contract.factory() method.
*
* @remarks
*
* The returned contract factory is a starknet.js `ContractFactory` object.
* This hook provides a function to deploy contracts using starknet.js v8's
* Contract.factory() static method.
*
* This hook works well with `useDeploy`.
* For declare and deploy, provide compiledContract and casm.
* For deploy-only, provide classHash and optionally abi.
*/
export function useContractFactory({
compiledContract,
casm,
classHash,
abi,
}: UseContractFactoryProps): UseContractFactoryResult {
const { account } = useAccount();

const contractFactory = useMemo(() => {
if (compiledContract && account && classHash) {
return new ContractFactory({
compiledContract,
classHash,
account,
abi,
});
}
return undefined;
}, [compiledContract, classHash, account, abi]);

return { contractFactory };
const deployContract = useCallback(
async (options?: DeployContractOptions) => {
if (!account) {
throw new Error("Account is required to deploy a contract");
}

const { constructorCalldata, salt, unique, details } = options || {};

// Declare and deploy mode
if (compiledContract && casm) {
return await Contract.factory(
{
account,
contract: compiledContract,
casm,
constructorCalldata,
salt,
unique,
},
details,
);
}

// Deploy-only mode
if (classHash) {
return await Contract.factory(
{
account,
classHash,
abi,
constructorCalldata,
salt,
unique,
},
details,
);
}

throw new Error(
"Either compiledContract + casm or classHash is required to deploy a contract",
);
},
[account, compiledContract, casm, classHash, abi],
);

return {
deployContract:
account && ((compiledContract && casm) || classHash)
? deployContract
: undefined,
};
}
14 changes: 7 additions & 7 deletions packages/core/src/hooks/use-contract.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe("useContract", () => {

expect(result.current).toMatchInlineSnapshot(`
{
"contract": Contract {
"contract": _Contract {
"abi": [
{
"members": [
Expand Down Expand Up @@ -173,8 +173,7 @@ describe("useContract", () => {
"callStatic": {
"name": [Function],
},
"contractOptions": undefined,
"deployTransactionHash": undefined,
"classHash": undefined,
"estimateFee": {
"name": [Function],
},
Expand All @@ -190,13 +189,13 @@ describe("useContract", () => {
"channel": RpcChannel2 {
"baseFetch": [Function],
"batchClient": undefined,
"blockIdentifier": "pending",
"blockIdentifier": "latest",
"chainId": "0x534e5f5345504f4c4941",
"channelSpecVersion": "0.8.1",
"channelSpecVersion": "0.9.0",
"headers": {
"Content-Type": "application/json",
},
"id": "RPC081",
"id": "RPC090",
"nodeUrl": "http://localhost:5050/rpc",
"requestId": 0,
"retries": 200,
Expand All @@ -206,7 +205,7 @@ describe("useContract", () => {
},
"getStateUpdate": [Function],
"responseParser": RPCResponseParser {
"margin": undefined,
"resourceBoundsOverhead": undefined,
},
},
"structs": {
Expand All @@ -225,6 +224,7 @@ describe("useContract", () => {
"type": "struct",
},
},
"withOptionsProps": undefined,
},
}
`);
Expand Down
6 changes: 4 additions & 2 deletions packages/core/src/hooks/use-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,11 @@ export function useContract<TAbi extends Abi>({
const contract = useMemo(() => {
const provider = providedProvider ? providedProvider : currentProvider;
if (abi && address && provider) {
return new Contract(abi, address, provider).typedv2(
return new Contract({
abi,
) as StarknetTypedContract<TAbi>;
address,
providerOrAccount: provider,
}).typedv2(abi) as StarknetTypedContract<TAbi>;
}
return undefined;
}, [abi, address, providedProvider, currentProvider]);
Expand Down
15 changes: 9 additions & 6 deletions packages/core/src/hooks/use-estimate-fees.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { useMemo } from "react";
import type {
AccountInterface,
Call,
EstimateFeeDetails,
EstimateFeeResponse,
EstimateFeeResponseOverhead,
UniversalDetails,
} from "starknet";

import { type UseQueryProps, type UseQueryResult, useQuery } from "../query";
Expand All @@ -15,23 +15,26 @@ export type EstimateFeesArgs = {
/** List of smart contract calls to estimate. */
calls?: Call[];
/** Estimate Fee options. */
options?: EstimateFeeDetails;
options?: UniversalDetails;
};

/** Options for `useEstimateFees`. */
export type UseEstimateFeesProps = EstimateFeesArgs &
UseQueryProps<
EstimateFeeResponse,
EstimateFeeResponseOverhead,
Error,
EstimateFeeResponse,
EstimateFeeResponseOverhead,
ReturnType<typeof queryKey>
> & {
/** Refresh data at every block. */
watch?: boolean;
};

/** Value returned from `useEstimateFees`. */
export type UseEstimateFeesResult = UseQueryResult<EstimateFeeResponse, Error>;
export type UseEstimateFeesResult = UseQueryResult<
EstimateFeeResponseOverhead,
Error
>;

/**
* Hook to estimate fees for smart contract calls.
Expand Down
Loading