# Scaffold UI
React components and hooks for Ethereum dApps
# Scaffold UI
**Scaffold-UI** exposes a clean set of components and hooks that give you everything you need to build Ethereum dApps.
## Components
Pre-built React components for common Ethereum UI patterns:
* **[Address](/components/Address)** - Display Ethereum addresses with ENS support, blockie, and copy functionality
* **[AddressInput](/components/AddressInput)** - Input field for Ethereum addresses with ENS resolution
* **[Balance](/components/Balance)** - Display ETH or ERC20 token balances
* **[EtherInput](/components/EtherInput)** - Input field for ETH amounts with USD conversion
**[View Installation Guide →](/components#installation)**
## Hooks
Our components are built on top of these React hooks, which you can use directly to create your own custom Ethereum components, or even combine them to build more complex ones.
* **[useAddress](/hooks/useAddress)** - Manage address state with ENS resolution
* **[useAddressInput](/hooks/useAddressInput)** - Handle address input validation and formatting
* **[useBalance](/hooks/useBalance)** - Fetch and watch address balances with USD conversion toggle
* **[useEtherInput](/hooks/useEtherInput)** - Convert between ETH and USD for input values
**[View Installation Guide →](/hooks#installation)**
## Debug Contracts
**[Debug Contracts](/debug-contracts/Contract)** - A contract UI component for debugging deployed contracts.
# Components
Pre-built React components for common Ethereum UI patterns.
## Installation
### Peer Dependencies
Install the required peer dependencies using your preferred package manager:
:::code-group
```bash [npm]
npm install react react-dom @types/react viem wagmi @tanstack/react-query
```
```bash [pnpm]
pnpm add react react-dom @types/react viem wagmi @tanstack/react-query
```
```bash [yarn]
yarn add react react-dom @types/react viem wagmi @tanstack/react-query
```
:::
### Package Installation
Install Scaffold UI components and hooks using your preferred package manager:
:::code-group
```bash [npm]
npm install @scaffold-ui/components @scaffold-ui/hooks
```
```bash [pnpm]
pnpm add @scaffold-ui/components @scaffold-ui/hooks
```
```bash [yarn]
yarn add @scaffold-ui/components @scaffold-ui/hooks
```
:::
### Import Styles
Import the styles in your root component file (`app.tsx` for React or `layout.tsx` for Next.js):
```typescript
import "@scaffold-ui/components/styles.css";
```
### Create wagmi config and setup Tanstack query
https://wagmi.sh/react/getting-started#create-config
# Address Component
The `Address` component displays Ethereum addresses with automatic ENS resolution, avatar display, and block explorer linking.
## Import
```tsx
import { Address } from "@scaffold-ui/components";
```
## Props
| Prop | Type | Default | Description |
| -------------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------- | ------------------------------------------------- |
| `address` | `Address` | - | The Ethereum address to display |
| `disableAddressLink` | `boolean` | `false` | Disable linking to block explorer |
| `format` | `"short" \| "long"` | `"short"` | Display format for the address |
| `size` | `"xs" \| "sm" \| "base" \| "lg" \| "xl" \| "2xl" \| "3xl"` | `"base"` | Size of the component |
| `onlyEnsOrAddress` | `boolean` | `false` | Show only ENS name or address (not both) |
| `chain` | `Chain` | First chain from [WagmiProvider](https://wagmi.sh/react/api/WagmiProvider) config or `mainnet` | Blockchain network for resolution |
| `style` | `CSSProperties` | - | Custom CSS styles (memoize to prevent re-renders) |
## Live Examples
### Basic Usage
Please enter a valid email
}Short: {shortAddress}
Full with blockexplorer link:{" "} {checkSumAddress}
Resolving...
} {ensAddress && (Address: {ensAddress}
)}Resolving...
} {ensAddress && (Resolved Address: {ensAddress}
)} {ensName && (Resolving...
} {showError &&✗ Could not resolve ENS name
} {ensAddress &&✓ Resolved: {ensAddress}
}Balance: {displayUsdMode ? `$${balanceInUsd.toLocaleString()}` : `${formattedBalance.toLocaleString()} ETH`}
Fetching balance…
; if (isError) return (Could not fetch balance
Balance: {displayUsdMode ? `$${balanceInUsd.toLocaleString()}` : `${formattedBalance.toLocaleString()} ETH`}
Fetching balance…
; if (isError || !data) returnCould not fetch balance
; return (Balance: {Number(formatEther(data.value)).toLocaleString()} {data.symbol}
); } ``` # useFetchNativeCurrencyPrice Hook The `useFetchNativeCurrencyPrice` hook fetches the current USD price of a chain's native currency using a Uniswap V2 pair on Ethereum mainnet. It powers the USD conversion in [`useBalance`](/hooks/useBalance) and the `Fetching ETH price…
; if (isError) returnCould not fetch ETH price
; return1 ETH ≈ ${price.toLocaleString()}
; } ``` ### Convert a Native Amount to USD Multiply a native amount by the fetched price to display its USD value.Loading…
; return ({amount} ETH ≈ ${(amount * price).toLocaleString()}
); } ``` ### Non-ETH Chain (Polygon) For chains whose native currency isn't ETH, the hook resolves the price from `NETWORKS_EXTRA_DATA[chain.id].nativeCurrencyTokenAddress` (e.g. the POL/DAI Uniswap V2 pair on mainnet for Polygon, where the token is the POL ERC-20 at `0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0`) — no extra config required for chains already registered.Fetching POL price…
; if (isError) returnCould not fetch POL price
; return1 POL ≈ ${price.toLocaleString()}
; } ``` # useEtherInput Hook The `useEtherInput` hook converts between ETH and USD for a given input and display mode. It returns both values, the current native currency price, and loading/error flags so you can build responsive inputs. ## Import ```tsx import { useEtherInput } from "@scaffold-ui/hooks"; ``` ## Usage ```tsx const { valueInEth, valueInUsd, nativeCurrencyPrice, isNativeCurrencyPriceLoading, isNativeCurrencyPriceError, } = useEtherInput({ value, usdMode }); ``` ## Parameters | Parameter | Type | Default | Description | | --------- | --------- | ------- | ---------------------------------------------------------------- | | `value` | `string` | - | The current input value. Interpreted as ETH when `usdMode` is `false`, USD when `true`. | | `usdMode` | `boolean` | - | If `true`, `value` is USD; if `false`, `value` is ETH. | ## Return Values | Property | Type | Description | | ----------------------------- | --------- | -------------------------------------------------------------------- | | `valueInEth` | `string` | The input value expressed in ETH. Empty string while conversion is unavailable. | | `valueInUsd` | `string` | The input value expressed in USD. Empty string while conversion is unavailable. | | `nativeCurrencyPrice` | `number` | The fetched native currency price in USD. `0` when not yet available. | | `isNativeCurrencyPriceLoading`| `boolean` | Loading state for fetching the native currency price. | | `isNativeCurrencyPriceError` | `boolean` | Error state for fetching the native currency price. | :::info This hook fetches price data using mainnet under the hood. When the price is not yet available, conversion outputs may be empty strings—keep showing the raw input in your UI. ::: ## Live Examples ### Basic UsageFetching price...
) : (ETH: {valueInEth || "–"} | USD: {valueInUsd || "–"}
)}Price feed unavailable. Showing entered value: ${valueInUsd}
; } returnETH: {valueInEth || "–"} | USD: {valueInUsd || "–"}
; } ``` # Contract Component The `Contract` is a UI component for debugging deployed contracts. ## Import ```tsx import { Contract } from "@scaffold-ui/debug-contracts"; ``` ## Props | Prop | Type | Default | Description | | -------------------------- | -------------------------------- | ----------- | ------------------------------------------------ | | `contractName` | `string` | - | The name of the contract to display | | `contract` | `{ address: Address, abi: Abi }` | - | The abi and address of the contract to display | | `chainId` | `number` | - | The chain ID where the contract is deployed | | `blockExplorerBaseUrl` | `string` | `undefined` | Base URL of the block explorer. The component appends `/address/{addr}` per rendered address. Defaults to `/blockexplorer` for local chain (31337) and to the chain's configured explorer otherwise. | ## Live Example: #### Code ```tsx twoslash // @noErrors // deployedContracts comes from your own project (generated by your deploy // scripts), so it won't resolve in this isolated docs snippet. import React from "react"; import { Contract } from "@scaffold-ui/debug-contracts"; import { deployedContracts } from "./components/ContractExample/deployedContracts"; import { sepolia } from "viem/chains";