Skip to content

chore: bump starknet.js to 8.1.2 #578

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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
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,
};
}
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
2 changes: 1 addition & 1 deletion packages/core/src/hooks/use-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ function queryKey({
// Function to transform a BlockIdentifier into a BLOCK_ID
function blockIdentifierToBlockId(blockIdentifier: BlockIdentifier) {
if (blockIdentifier === null) {
return BlockTag.PENDING; // null maps to 'pending' as per the BlockIdentifier doc
return BlockTag.PRE_CONFIRMED; // null maps to 'pre_confirmed' in v8
}

if (typeof blockIdentifier === "number") {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/test/devnet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function makeAccount({
address: string;
privateKey: string;
}): AccountInterface {
return new Account(provider, address, privateKey);
return new Account({ provider, address, signer: privateKey });
}

export const accounts = {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-starknet/src/templates/next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"next": "15.4.4",
"react": "19.1.0",
"react-dom": "19.1.0",
"starknet": "^7.6.4"
"starknet": "^8.1.2"
},
"devDependencies": {
"@eslint/eslintrc": "^3",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-starknet/src/templates/vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"get-starknet-core": "4.0.0",
"react": "^19.1.0",
"react-dom": "^19.1.0",
"starknet": "^7.6.4",
"starknet": "^8.1.2",
"tailwindcss": "^4.1.11"
},
"devDependencies": {
Expand Down
Loading
Loading