Skip to content

Commit cb7d80b

Browse files
committed
chore: bump starknet.js to 8.1.2
1 parent 3dc52f1 commit cb7d80b

File tree

13 files changed

+156
-87
lines changed

13 files changed

+156
-87
lines changed

docs/components/demo/read-contract.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export function ReadContractInner() {
3838
watch: true,
3939
enabled: enable,
4040
blockIdentifier:
41-
blockIdentifier === "latest" ? BlockTag.LATEST : BlockTag.PENDING,
41+
blockIdentifier === "latest" ? BlockTag.LATEST : BlockTag.PRE_CONFIRMED,
4242
});
4343

4444
return (
@@ -52,7 +52,7 @@ export function ReadContractInner() {
5252
</SelectTrigger>
5353
<SelectContent>
5454
<SelectItem value={BlockTag.LATEST}>Latest</SelectItem>
55-
<SelectItem value={BlockTag.PENDING}>Pending</SelectItem>
55+
<SelectItem value={BlockTag.PRE_CONFIRMED}>Pre-Confirmed</SelectItem>
5656
</SelectContent>
5757
</Select>
5858

docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"lucide-react": "^0.438.0",
2626
"react": "^18.2.0",
2727
"safe-stable-stringify": "^2.5.0",
28-
"starknet": "^7.6.4",
28+
"starknet": "^8.1.2",
2929
"starknetkit": "^2.12.1",
3030
"tailwind-merge": "^2.5.2",
3131
"tailwindcss-animate": "^1.0.7",

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"peerDependencies": {
4242
"get-starknet-core": "^4.0.0",
4343
"react": "^18.0",
44-
"starknet": "^7.6.4"
44+
"starknet": "^8.1.2"
4545
},
4646
"devDependencies": {
4747
"@starknet-react/typescript-config": "workspace:*",
@@ -52,7 +52,7 @@
5252
"react": "^18.2.0",
5353
"react-dom": "^18.2.0",
5454
"rimraf": "^4.1.2",
55-
"starknet": "^7.6.4",
55+
"starknet": "^8.1.2",
5656
"tsup": "^8.0.2",
5757
"vite-tsconfig-paths": "^4.3.2",
5858
"vitest": "^1.5.2"

packages/core/src/hooks/use-balance.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export function useBalance({
7979

8080
const refetchInterval =
8181
refetchInterval_ ??
82-
(blockIdentifier === BlockTag.PENDING && watch
82+
(blockIdentifier === BlockTag.PRE_CONFIRMED && watch
8383
? DEFAULT_FETCH_INTERVAL
8484
: undefined);
8585

packages/core/src/hooks/use-call.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import {
55
type ArgsOrCalldata,
66
type BlockNumber,
77
BlockTag,
8+
type CallResult,
89
type Contract,
9-
type Result,
1010
} from "starknet";
1111

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

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

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

4848
/**
4949
* Hook to perform a read-only contract call.
@@ -89,7 +89,7 @@ export function useCall({
8989

9090
const refetchInterval =
9191
refetchInterval_ ??
92-
(blockIdentifier === BlockTag.PENDING && watch
92+
(blockIdentifier === BlockTag.PRE_CONFIRMED && watch
9393
? DEFAULT_FETCH_INTERVAL
9494
: undefined);
9595

Lines changed: 85 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,113 @@
1-
import { useMemo } from "react";
2-
import { type Abi, type CompiledContract, ContractFactory } from "starknet";
1+
import { useCallback } from "react";
2+
import {
3+
type Abi,
4+
type CompiledContract,
5+
type CompiledSierraCasm,
6+
Contract,
7+
type RawArgs,
8+
type UniversalDetails,
9+
} from "starknet";
310

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

613
/** Arguments for `useContractFactory`. */
714
export interface UseContractFactoryProps {
8-
/** The compiled contract. */
15+
/** The compiled contract (for declare and deploy). */
916
compiledContract?: CompiledContract;
10-
/** The class hash */
11-
classHash: string;
17+
/** The CASM contract (required when declaring). */
18+
casm?: CompiledSierraCasm;
19+
/** The class hash (for deploy-only mode). */
20+
classHash?: string;
1221
/** The contract abi. */
1322
abi?: Abi;
1423
}
1524

25+
/** Options for deploying a contract. */
26+
export interface DeployContractOptions {
27+
/** Constructor calldata. */
28+
constructorCalldata?: RawArgs;
29+
/** Salt for address generation. */
30+
salt?: string;
31+
/** Make the address unique. */
32+
unique?: boolean;
33+
/** Additional transaction details. */
34+
details?: UniversalDetails;
35+
}
36+
1637
/** Value returned from `useContractFactory`. */
1738
export interface UseContractFactoryResult {
18-
/** The contract factory. */
19-
contractFactory?: ContractFactory;
39+
/** Function to deploy the contract. */
40+
deployContract?: (options?: DeployContractOptions) => Promise<Contract>;
2041
}
2142

2243
/**
23-
* Hook to create a `ContractFactory`.
44+
* Hook to deploy contracts using the new Contract.factory() method.
2445
*
2546
* @remarks
2647
*
27-
* The returned contract factory is a starknet.js `ContractFactory` object.
48+
* This hook provides a function to deploy contracts using starknet.js v8's
49+
* Contract.factory() static method.
2850
*
29-
* This hook works well with `useDeploy`.
51+
* For declare and deploy, provide compiledContract and casm.
52+
* For deploy-only, provide classHash and optionally abi.
3053
*/
3154
export function useContractFactory({
3255
compiledContract,
56+
casm,
3357
classHash,
3458
abi,
3559
}: UseContractFactoryProps): UseContractFactoryResult {
3660
const { account } = useAccount();
3761

38-
const contractFactory = useMemo(() => {
39-
if (compiledContract && account && classHash) {
40-
return new ContractFactory({
41-
compiledContract,
42-
classHash,
43-
account,
44-
abi,
45-
});
46-
}
47-
return undefined;
48-
}, [compiledContract, classHash, account, abi]);
49-
50-
return { contractFactory };
62+
const deployContract = useCallback(
63+
async (options?: DeployContractOptions) => {
64+
if (!account) {
65+
throw new Error("Account is required to deploy a contract");
66+
}
67+
68+
const { constructorCalldata, salt, unique, details } = options || {};
69+
70+
// Declare and deploy mode
71+
if (compiledContract && casm) {
72+
return await Contract.factory(
73+
{
74+
account,
75+
contract: compiledContract,
76+
casm,
77+
constructorCalldata,
78+
salt,
79+
unique,
80+
},
81+
details,
82+
);
83+
}
84+
85+
// Deploy-only mode
86+
if (classHash) {
87+
return await Contract.factory(
88+
{
89+
account,
90+
classHash,
91+
abi,
92+
constructorCalldata,
93+
salt,
94+
unique,
95+
},
96+
details,
97+
);
98+
}
99+
100+
throw new Error(
101+
"Either compiledContract + casm or classHash is required to deploy a contract",
102+
);
103+
},
104+
[account, compiledContract, casm, classHash, abi],
105+
);
106+
107+
return {
108+
deployContract:
109+
account && ((compiledContract && casm) || classHash)
110+
? deployContract
111+
: undefined,
112+
};
51113
}

packages/core/src/hooks/use-contract.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,11 @@ export function useContract<TAbi extends Abi>({
112112
const contract = useMemo(() => {
113113
const provider = providedProvider ? providedProvider : currentProvider;
114114
if (abi && address && provider) {
115-
return new Contract(abi, address, provider).typedv2(
115+
return new Contract({
116116
abi,
117-
) as StarknetTypedContract<TAbi>;
117+
address,
118+
providerOrAccount: provider,
119+
}).typedv2(abi) as StarknetTypedContract<TAbi>;
118120
}
119121
return undefined;
120122
}, [abi, address, providedProvider, currentProvider]);

packages/core/src/hooks/use-estimate-fees.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { useMemo } from "react";
22
import type {
33
AccountInterface,
44
Call,
5-
EstimateFeeDetails,
6-
EstimateFeeResponse,
5+
EstimateFeeResponseOverhead,
6+
UniversalDetails,
77
} from "starknet";
88

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

2121
/** Options for `useEstimateFees`. */
2222
export type UseEstimateFeesProps = EstimateFeesArgs &
2323
UseQueryProps<
24-
EstimateFeeResponse,
24+
EstimateFeeResponseOverhead,
2525
Error,
26-
EstimateFeeResponse,
26+
EstimateFeeResponseOverhead,
2727
ReturnType<typeof queryKey>
2828
> & {
2929
/** Refresh data at every block. */
3030
watch?: boolean;
3131
};
3232

3333
/** Value returned from `useEstimateFees`. */
34-
export type UseEstimateFeesResult = UseQueryResult<EstimateFeeResponse, Error>;
34+
export type UseEstimateFeesResult = UseQueryResult<
35+
EstimateFeeResponseOverhead,
36+
Error
37+
>;
3538

3639
/**
3740
* Hook to estimate fees for smart contract calls.

packages/core/src/hooks/use-events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function queryKey({
137137
// Function to transform a BlockIdentifier into a BLOCK_ID
138138
function blockIdentifierToBlockId(blockIdentifier: BlockIdentifier) {
139139
if (blockIdentifier === null) {
140-
return BlockTag.PENDING; // null maps to 'pending' as per the BlockIdentifier doc
140+
return BlockTag.PRE_CONFIRMED; // null maps to 'pre_confirmed' in v8
141141
}
142142

143143
if (typeof blockIdentifier === "number") {

packages/core/test/devnet.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function makeAccount({
4141
address: string;
4242
privateKey: string;
4343
}): AccountInterface {
44-
return new Account(provider, address, privateKey);
44+
return new Account({ provider, address, signer: privateKey });
4545
}
4646

4747
export const accounts = {

0 commit comments

Comments
 (0)