Contract Utilities
Helper functions for smart contract interactions.Contract Type System
Location:utils/scaffold-eth/contract.ts
Provides full TypeScript type safety for contract interactions.
Key Types:
getParsedError
Parse and format contract errors for display. Location:utils/scaffold-eth/getParsedError.ts
Usage:
getParsedErrorWithAllAbis
Enhanced error parsing that checks all deployed contracts. Location:utils/scaffold-eth/contract.ts:347
Usage:
- Decodes error signatures from any contract in the system
- Creates lookup table from all deployed contracts
- Provides contract name and error signature
- Helpful context for nested contract calls
simulateContractWriteAndNotifyError
Simulate contract writes before execution. Location:utils/scaffold-eth/contract.ts:406
Usage:
- Pre-execution validation
- Automatic error notifications
- Prevents failed transactions
- Gas estimation
Blockchain Explorers
getBlockExplorerAddressLink
Generate block explorer URL for an address. Location:utils/scaffold-eth/networks.ts
Usage:
getBlockExplorerTxLink
Generate block explorer URL for a transaction. Location:utils/scaffold-eth/networks.ts
Usage:
Data Formatting
replacer
JSON.stringify replacer for BigInt serialization. Location:utils/scaffold-eth/common.ts
Usage:
formatEther / parseEther
Format and parse Ether values (from viem). Usage:formatUnits / parseUnits
Format and parse token amounts with custom decimals. Usage:Address Utilities
ZERO_ADDRESS
Constant for zero address. Location:utils/scaffold-eth/common.ts
Usage:
"0x0000000000000000000000000000000000000000"
isZeroAddress
Check if address is zero address. Location:utils/scaffold-eth/common.ts
Usage:
isAddress
Validate Ethereum address format (from viem). Usage:getAddress
Get checksummed address (from viem). Usage:Constants
LOCAL_STORAGE_KEYS
Constants for localStorage keys. Location:constants/localStorage.ts
Usage:
Roles
Location:constants/roles.ts
Network Utilities
NETWORKS_EXTRA_DATA
Additional network metadata. Location:utils/scaffold-eth/networks.ts
Usage:
Transaction Utilities
decodeTxData
Decode transaction calldata. Location:utils/scaffold-eth/decodeTxData.ts
Usage:
Block Utilities
fetchPriceFromUniswap
Get token price from Uniswap. Location:utils/scaffold-eth/fetchPriceFromUniswap.ts
Usage:
TypeScript Utilities
Common TypeScript helper types.CommonInputProps
Shared props for input components. Location:components/scaffold-eth/Input/index.tsx
Utility Composition Example
Combining multiple utilities:Best Practices
Error Handling
Error Handling
Always use
getParsedErrorWithAllAbis for user-facing error messages:BigInt Serialization
BigInt Serialization
Use the
replacer utility when stringifying data with BigInt:Address Validation
Address Validation
Always validate addresses before using them:
localStorage Keys
localStorage Keys
Use constants instead of magic strings: