@starknet-react/core
Version:
Starknet React is a collection of React hooks for Starknet.
279 lines (263 loc) • 13.3 kB
TypeScript
import { Chain, Address } from '@starknet-react/chains';
export { Address } from '@starknet-react/chains';
export { Abi } from 'abi-wan-kanabi';
import { C as Connector, a as ConnectorIcons, b as ConnectArgs, c as ConnectorData, E as Explorer, d as ExplorerFactory } from './index-KYmfBIOq.js';
export { A as AccountStatus, B as Balance, r as CallQueryKey, w as ConnectVariables, P as DeployAccountVariables, I as DeployContractOptions, Y as EstimateFeesArgs, aE as GetStarkprofileResponse, aa as PaymasterEstimateFeesArgs, aT as RequestArgs, aR as RequestMessageTypes, aS as RequestResult, aA as StarkNameArgs, aB as StarkNameResult, aD as StarkProfileArgs, S as StarknetTypedContract, U as UseAccountResult, e as UseAddChainArgs, f as UseAddChainProps, g as UseAddChainResult, i as UseBalanceProps, j as UseBalanceResult, o as UseBlockNumberProps, p as UseBlockNumberResult, l as UseBlockProps, m as UseBlockResult, s as UseCallProps, t as UseCallResult, x as UseConnectProps, y as UseConnectResult, D as UseContractArgs, H as UseContractFactoryProps, J as UseContractFactoryResult, F as UseContractResult, L as UseDeclareContractArgs, M as UseDeclareContractProps, N as UseDeclareContractResult, Q as UseDeployAccountProps, R as UseDeployAccountResult, V as UseDisconnectProps, W as UseDisconnectResult, Z as UseEstimateFeesProps, _ as UseEstimateFeesResult, a0 as UseEventsProps, a1 as UseEventsResult, a5 as UseNetworkResult, a7 as UseNonceForAddressProps, a8 as UseNonceForAddressResult, ab as UsePaymasterEstimateFeesProps, ac as UsePaymasterEstimateFeesResult, ae as UsePaymasterGasTokensProps, af as UsePaymasterGasTokensResult, ah as UsePaymasterSendTransactionArgs, ai as UsePaymasterSendTransactionResult, ak as UseProviderResult, am as UseReadContractProps, an as UseReadContractResult, ap as UseSendTransactionArgs, aq as UseSendTransactionProps, ar as UseSendTransactionResult, at as UseSignTypedDataArgs, au as UseSignTypedDataProps, av as UseSignTypedDataResult, ax as UseStarkAddressProps, ay as UseStarkAddressResult, aF as UseStarkProfileResult, aH as UseSwitchChainArgs, aI as UseSwitchChainProps, aJ as UseSwitchChainResult, aL as UseTransactionReceiptProps, aM as UseTransactionReceiptResult, aO as UseUniversalDeployerContractProps, aP as UseUniversalDeployerContractResult, aU as UseWalletRequestProps, aV as UseWalletRequestResult, aX as UseWatchAssetArgs, aY as UseWatchAssetProps, aZ as UseWatchAssetResult, u as useAccount, h as useAddChain, k as useBalance, n as useBlock, q as useBlockNumber, v as useCall, z as useConnect, G as useContract, K as useContractFactory, O as useDeclareContract, T as useDeployAccount, X as useDisconnect, $ as useEstimateFees, a2 as useEvents, a3 as useExplorer, a4 as useInvalidateOnBlock, a6 as useNetwork, a9 as useNonceForAddress, ad as usePaymasterEstimateFees, ag as usePaymasterGasTokens, aj as usePaymasterSendTransaction, al as useProvider, ao as useReadContract, as as useSendTransaction, aw as useSignTypedData, az as useStarkAddress, aC as useStarkName, aG as useStarkProfile, aK as useSwitchChain, aN as useTransactionReceipt, aQ as useUniversalDeployerContract, aW as useWalletRequest, a_ as useWatchAsset } from './index-KYmfBIOq.js';
import { RpcMessage, RequestFnCall, RpcTypeToMessageMap } from '@starknet-io/types-js';
import { ProviderInterface, PaymasterInterface, AccountInterface, ProviderOptions, constants } from 'starknet';
import * as react_jsx_runtime from 'react/jsx-runtime';
import { QueryClient } from '@tanstack/react-query';
import React from 'react';
import { ChainProviderFactory } from './providers/index.js';
export { AlchemyProviderArgs, BlastProviderArgs, InfuraProviderArgs, JsonRpcProviderArgs, LavaProviderArgs, SlotProviderArgs, alchemyProvider, blastProvider, cartridgeProvider, infuraProvider, jsonRpcProvider, lavaProvider, publicProvider, slotProvider } from './providers/index.js';
import { ChainPaymasterFactory } from './providers/paymaster/index.js';
export { AvnuPaymasterProviderArgs, PaymasterRpcProviderArgs, avnuPaymasterProvider, paymasterRpcProvider } from './providers/paymaster/index.js';
import 'eventemitter3';
import 'abi-wan-kanabi/kanabi';
type UseInjectedConnectorsProps = {
/** List of recommended connectors to display. */
recommended?: Connector[];
/** Whether to include recommended connectors in the list. */
includeRecommended?: "always" | "onlyIfNoConnectors";
/** How to order connectors. */
order?: "random" | "alphabetical";
/** Shim the following legacy connectors if they are detected. */
shimLegacyConnectors?: string[];
};
type UseInjectedConnectorsResult = {
/** Connectors list. */
connectors: Connector[];
};
declare function useInjectedConnectors({ recommended, includeRecommended, order, shimLegacyConnectors, }: UseInjectedConnectorsProps): UseInjectedConnectorsResult;
/** Injected connector options. */
interface InjectedConnectorOptions {
/** The wallet id. */
id: string;
/** Wallet human readable name. */
name?: string;
/** Wallet icons. */
icon?: ConnectorIcons;
}
declare class InjectedConnector extends Connector {
private _wallet?;
private readonly _options;
constructor({ options }: {
options: InjectedConnectorOptions;
});
get id(): string;
get name(): string;
get icon(): ConnectorIcons;
available(): boolean;
chainId(): Promise<bigint>;
ready(): Promise<boolean>;
account(provider: ProviderInterface, paymasterProvider?: PaymasterInterface): Promise<AccountInterface>;
connect(_args?: ConnectArgs): Promise<ConnectorData>;
disconnect(): Promise<void>;
request<T extends RpcMessage["type"]>(call: RequestFnCall<T>): Promise<RpcTypeToMessageMap[T]["result"]>;
private isLocked;
private requestChainId;
private ensureWallet;
protected onAccountsChanged(accounts?: string[]): Promise<void>;
private onNetworkChanged;
private switchChain;
}
/** Injected connector options. */
interface LegacyInjectedConnectorOptions {
/** The wallet id. */
id: string;
/** Wallet human readable name. */
name?: string;
/** Wallet icons. */
icon?: ConnectorIcons;
}
declare class LegacyInjectedConnector extends Connector {
private _wallet?;
private _options;
constructor({ options }: {
options: LegacyInjectedConnectorOptions;
});
get id(): string;
get name(): string;
get icon(): ConnectorIcons;
available(): boolean;
chainId(): Promise<bigint>;
ready(): Promise<boolean>;
connect(_args?: ConnectArgs): Promise<ConnectorData>;
disconnect(): Promise<void>;
account(): Promise<AccountInterface>;
request<T extends RpcMessage["type"]>(call: RequestFnCall<T>): Promise<RpcTypeToMessageMap[T]["result"]>;
private ensureWallet;
private onAccountsChanged;
private onNetworkChanged;
}
declare function ready(): InjectedConnector;
declare const argent: typeof ready;
declare function braavos(): InjectedConnector;
declare function injected({ id }: {
id: string;
}): InjectedConnector;
declare function legacyInjected({ id, }: {
id: string;
}): LegacyInjectedConnector;
type MockConnectorOptions = {
/** The wallet id. */
id: string;
/** Wallet human readable name. */
name: string;
/** Wallet icons. */
icon?: ConnectorIcons;
/** Whether the connector is available for use. */
available?: boolean;
/** Whether the connector should fail to connect. */
failConnect?: boolean;
/** Include account when switching chain. */
unifiedSwitchAccountAndChain?: boolean;
/** Emit change account event when switching chain. */
emitChangeAccountOnChainSwitch?: boolean;
/** Reject request calls */
rejectRequest?: boolean;
};
type MockConnectorAccounts = {
sepolia: AccountInterface[];
mainnet: AccountInterface[];
};
declare class MockConnector extends Connector {
private _accounts;
private _accountIndex;
private _connected;
private _chainId;
options: MockConnectorOptions;
constructor({ accounts, options, }: {
accounts: MockConnectorAccounts;
options: MockConnectorOptions;
});
switchChain(chainId: bigint): void;
switchAccount(accountIndex: number): void;
get id(): string;
get name(): string;
get icon(): ConnectorIcons;
available(): boolean;
chainId(): Promise<bigint>;
ready(): Promise<boolean>;
connect(): Promise<ConnectorData>;
disconnect(): Promise<void>;
request<T extends RpcMessage["type"]>(call: RequestFnCall<T>): Promise<RpcTypeToMessageMap[T]["result"]>;
account(_provider: ProviderOptions | ProviderInterface, _paymasterProvider?: PaymasterInterface): Promise<AccountInterface>;
private get _account();
}
declare class CartridgeExplorer implements Explorer {
name: string;
private link;
constructor(chain: Chain);
block(hashOrNumber: {
hash?: string;
number?: number;
}): string;
transaction(hash: string): string;
contract(address: string): string;
class(hash: string): string;
}
declare const cartridge: ExplorerFactory<CartridgeExplorer>;
declare class StarkscanExplorer implements Explorer {
name: string;
private link;
constructor(chain: Chain);
block(hashOrNumber: {
hash?: string;
number?: number;
}): string;
transaction(hash: string): string;
contract(address: string): string;
class(hash: string): string;
}
declare const starkscan: ExplorerFactory<StarkscanExplorer>;
declare class ViewblockExplorer implements Explorer {
name: string;
private link;
constructor(chain: Chain);
block(hashOrNumber: {
hash?: string;
number?: number;
}): string;
transaction(hash: string): string;
contract(address: string): string;
class(hash: string): string;
}
declare const viewblock: ExplorerFactory<ViewblockExplorer>;
declare class VoyagerExplorer implements Explorer {
name: string;
private link;
constructor(chain: Chain);
block(hashOrNumber: {
hash?: string;
number?: number;
}): string;
transaction(hash: string): string;
contract(address: string): string;
class(hash: string): string;
}
declare const voyager: ExplorerFactory<VoyagerExplorer>;
/** Arguments for `StarknetProvider`. */
interface StarknetProviderProps {
/** Chains supported by the app. */
chains: Chain[];
/** Provider to use. */
provider: ChainProviderFactory;
/** Paymaster provider to use. */
paymasterProvider?: ChainPaymasterFactory;
/** List of connectors to use. */
connectors?: Connector[];
/** Explorer to use. */
explorer?: ExplorerFactory;
/** Connect the first available connector on page load. */
autoConnect?: boolean;
/** React-query client to use. */
queryClient?: QueryClient;
/** Application. */
children?: React.ReactNode;
/** Default chain to use when wallet is not connected */
defaultChainId?: bigint;
}
declare function starknetChainId(chainId: bigint): constants.StarknetChainId | undefined;
declare function AccountProvider({ address, account, children, }: {
address?: Address;
account?: AccountInterface;
children: React.ReactNode;
}): react_jsx_runtime.JSX.Element;
type StarknetConfigProps = StarknetProviderProps;
declare function StarknetConfig({ children, ...config }: StarknetConfigProps): react_jsx_runtime.JSX.Element;
declare class ConnectorAlreadyConnectedError extends Error {
name: string;
message: string;
}
declare class ConnectorNotConnectedError extends Error {
name: string;
message: string;
}
declare class ConnectorNotFoundError extends Error {
name: string;
message: string;
}
declare class UserRejectedRequestError extends Error {
name: string;
message: string;
}
declare class WalletRequestError extends Error {
constructor(error?: string | Error | unknown, _cause?: Error | unknown);
}
declare class UserNotConnectedError extends Error {
name: string;
message: string;
}
declare class UnsupportedAccountInterfaceError extends Error {
name: string;
message: string;
}
/**
* Validate and format the address.
*
* @param address - The address string to validate.
* @returns The validated and formatted address as Address type.
*/
declare function getAddress(address: string): Address;
export { CartridgeExplorer, ChainPaymasterFactory, ChainProviderFactory, ConnectArgs, Connector, ConnectorAlreadyConnectedError, ConnectorNotConnectedError, ConnectorNotFoundError, Explorer, ExplorerFactory, InjectedConnector, type InjectedConnectorOptions, LegacyInjectedConnector, type LegacyInjectedConnectorOptions, MockConnector, type MockConnectorAccounts, type MockConnectorOptions, AccountProvider as OverrideAccount, StarknetConfig, type StarknetConfigProps, StarkscanExplorer, UnsupportedAccountInterfaceError, type UseInjectedConnectorsProps, type UseInjectedConnectorsResult, UserNotConnectedError, UserRejectedRequestError, ViewblockExplorer, VoyagerExplorer, WalletRequestError, argent, braavos, cartridge, getAddress, injected, legacyInjected, ready, starknetChainId, starkscan, useInjectedConnectors, viewblock, voyager };