useDeployedContractInfo
Use this hook to get information about a deployed contract, including its address, ABI, and deployment status. This is useful for dynamically accessing contract data and verifying contract availability.
const { data: contractInfo, isLoading } = useDeployedContractInfo("YourContract");
// Access contract details
console.log(contractInfo?.address);
console.log(contractInfo?.abi);
Configurationโ
| Parameter | Type | Description |
|---|---|---|
| contractName | string | Name of the contract as defined in deployedContracts.ts. |
Return Valuesโ
| Property | Type | Description |
|---|---|---|
| data | Contract | undefined | Contract information object containing address, abi, and classHash |
| isLoading | boolean | true while verifying contract deployment |
| raw | Contract | undefined | Contract config from deployedContracts.ts (independent of deployment status) |
| status | ContractCodeStatus | Deployment status: "LOADING", "DEPLOYED", or "NOT_FOUND" |
Contract Object Structureโ
interface Contract {
address: string; // Contract address on current network
abi: Abi; // Contract ABI for type generation
classHash: string; // Cairo class hash
}
ContractCodeStatusโ
type ContractCodeStatus = "LOADING" | "DEPLOYED" | "NOT_FOUND";
Usage Examplesโ
Basic Usageโ
import { View, Text, ActivityIndicator } from "react-native";
import { useDeployedContractInfo } from "@/hooks/scaffold-stark";
export default function ContractInfo() {
const { data, isLoading, status } = useDeployedContractInfo("YourContract");
if (isLoading) {
return <ActivityIndicator />;
}
if (status === "NOT_FOUND") {
return <Text>Contract not deployed on this network</Text>;
}
return (
<View>
<Text>Address: {data?.address}</Text>
<Text>Class Hash: {data?.classHash}</Text>
<Text>Functions: {data?.abi.length}</Text>
</View>
);
}
Conditional Renderingโ
import { View, Text, Button } from "react-native";
import { useDeployedContractInfo, useScaffoldWriteContract } from "@/hooks/scaffold-stark";
export default function ConditionalInteraction() {
const { status } = useDeployedContractInfo("OptionalFeature");
const { sendAsync, isLoading } = useScaffoldWriteContract({
contractName: "OptionalFeature",
functionName: "activate",
args: [],
});
// Only show button if contract is deployed
if (status !== "DEPLOYED") {
return (
<View>
<Text>This feature is not available on the current network.</Text>
</View>
);
}
return (
<Button
title="Activate Feature"
onPress={() => sendAsync()}
disabled={isLoading}
/>
);
}
Display Contract Addressโ
import { View, Text, TouchableOpacity } from "react-native";
import * as Clipboard from "expo-clipboard";
import { useDeployedContractInfo } from "@/hooks/scaffold-stark";
export default function ContractAddress({ contractName }) {
const { data, status } = useDeployedContractInfo(contractName);
const copyAddress = async () => {
if (data?.address) {
await Clipboard.setStringAsync(data.address);
// Show toast or feedback
}
};
if (status !== "DEPLOYED") {
return <Text>Not deployed</Text>;
}
return (
<TouchableOpacity onPress={copyAddress}>
<View style={{ flexDirection: "row", alignItems: "center" }}>
<Text style={{ fontFamily: "monospace" }}>
{data?.address.slice(0, 6)}...{data?.address.slice(-4)}
</Text>
<Text style={{ marginLeft: 4 }}>๐</Text>
</View>
</TouchableOpacity>
);
}
Multiple Contractsโ
import { View, Text, FlatList, ActivityIndicator } from "react-native";
import { useDeployedContractInfo } from "@/hooks/scaffold-stark";
const CONTRACT_NAMES = ["Token", "NFT", "Governance", "Treasury"];
function ContractRow({ name }) {
const { data, status, isLoading } = useDeployedContractInfo(name);
return (
<View style={{ flexDirection: "row", padding: 8, borderBottomWidth: 1 }}>
<Text style={{ flex: 1 }}>{name}</Text>
{isLoading ? (
<ActivityIndicator size="small" />
) : (
<Text style={{ color: status === "DEPLOYED" ? "green" : "red" }}>
{status}
</Text>
)}
</View>
);
}
export default function ContractStatusList() {
return (
<FlatList
data={CONTRACT_NAMES}
keyExtractor={(item) => item}
renderItem={({ item }) => <ContractRow name={item} />}
/>
);
}
Using Raw Configโ
Access contract configuration even before deployment verification:
import { useDeployedContractInfo } from "@/hooks/scaffold-stark";
export default function ContractPreview({ contractName }) {
const { raw, status } = useDeployedContractInfo(contractName);
// raw is available immediately from deployedContracts.ts
// data is only available after on-chain verification
return (
<View>
<Text>Expected Address: {raw?.address}</Text>
<Text>Verification: {status}</Text>
</View>
);
}
How It Worksโ
The hook performs two operations:
- Config Lookup: Reads contract information from
deployedContracts.tsfor the current network - On-chain Verification: Checks if the contract is actually deployed by querying its class hash
deployedContracts.ts โโโ raw (immediate)
โ
โ
Check class hash on-chain
โ
โ
status: DEPLOYED | NOT_FOUND
โ
โ
data (verified)
Network Awarenessโ
The hook automatically uses the contract configuration for the current target network:
// deployedContracts.ts
export const contracts = {
devnet: {
YourContract: { address: "0x123...", abi: [...] },
},
sepolia: {
YourContract: { address: "0x456...", abi: [...] },
},
};
// Hook automatically selects based on current network
const { data } = useDeployedContractInfo("YourContract");
// Returns devnet config on devnet, sepolia config on sepolia
Related Hooksโ
- useScaffoldReadContract - Uses this hook internally
- useScaffoldWriteContract - Uses this hook internally
- useTargetNetwork - Get current network info