Skip to content
Starknet Start

useContractFactory

Hook to deploy contracts with Contract.factory().

Usage

import { useContractFactory } from "@starknetfoundation/starknet-start-react";
 
const { deployContract } = useContractFactory({
  compiledContract: compiledErc20,
  casm: compiledErc20Casm,
  abi: compiledErc20.abi,
});
 
const contract = await deployContract?.({
  constructorCalldata: ["0x1"],
  salt: "0x123",
  unique: true,
});

Deploy result

  • Type: Contract

Type Contract from starknet.

Arguments

compiledContract

  • Type: CompiledContract | undefined

The compiled Sierra contract. Provide this with casm for declare-and-deploy mode.

casm

  • Type: CompiledSierraCasm | undefined

The compiled CASM contract. Required with compiledContract for declare-and-deploy mode.

classHash

  • Type: string | undefined

The class hash to use for deploy-only mode.

abi

  • Type: Abi | undefined

The contract ABI to use in deploy-only mode.

Returns

deployContract

  • Type: ((options?: DeployContractOptions) => Promise<Contract>) | undefined

Deploys the contract. It is undefined until an account is connected and either compiledContract with casm, or classHash, is provided.