addDeclareTransaction
Action for declaring a Starknet contract.
Import
import { addDeclareTransaction } from "starkweb/core";
Usage
index.ts
import { addDeclareTransaction } from "starkweb/core";
import { config } from "./config";
const result = await addDeclareTransaction(config, {
contract: {
program: "...",
entry_points_by_type: {...},
abi: [...],
},
});
Parameters
import { type AddDeclareTransactionParameters } from "starkweb/core";
contract
Contract
The contract to declare.
index.ts
import { addDeclareTransaction } from "starkweb/core";
import { config } from "./config";
const result = await addDeclareTransaction(config, {
contract: {
program: "...",
entry_points_by_type: {...},
abi: [...],
},
});
chainId (optional)
Hex | undefined
The chain ID to declare the contract on. If not provided, uses the current chain.
index.ts
import { addDeclareTransaction } from "starkweb/core";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
const result = await addDeclareTransaction(config, {
contract: {...},
chainId: mainnet.chain_id,
});
Return Type
import { type AddDeclareTransactionReturnType } from "starkweb/core";
Returns the transaction information including:
chainId
Hex
The chain ID of the network.
transaction_hash
Hex
The hash of the declare transaction.
class_hash
Hex
The hash of the declared contract class.
Example
example.ts
import { addDeclareTransaction } from "starkweb/core";
import { mainnet } from "starkweb/chains";
import { config } from "./config";
// Declare contract on current chain
const result = await addDeclareTransaction(config, {
contract: {
program: "...",
entry_points_by_type: {...},
abi: [...],
},
});
console.log("Class hash:", result.class_hash);
// Declare contract on specific chain
const mainnetResult = await addDeclareTransaction(config, {
contract: {...},
chainId: mainnet.chain_id,
});
Error
import { type AddDeclareTransactionErrorType } from "starkweb/core";