useConnection
Primitive for getting current connection.
Import
ts
import { useConnection } from '@wagmi/solid'Usage
tsx
import { useConnection } from '@wagmi/solid'
import { Show } from 'solid-js'
function App() {
const connection = useConnection()
return (
<Show when={connection.isConnected} fallback={<p>Not connected</p>}>
<p>Address: {connection.address}</p>
<p>Chain ID: {connection.chainId}</p>
</Show>
)
}ts
import { createConfig, http } from '@wagmi/solid'
import { mainnet, sepolia } from '@wagmi/solid/chains'
export const config = createConfig({
chains: [mainnet, sepolia],
transports: {
[mainnet.id]: http(),
[sepolia.id]: http(),
},
})Parameters
ts
import { useConnection } from '@wagmi/solid'
useConnection.Parameters
useConnection.SolidParametersParameters are passed as a getter function to maintain Solid reactivity.
ts
useConnection(() => ({
config,
}))config
Config | undefined
Config to use instead of retrieving from the nearest WagmiProvider.
Return Type
ts
import { useConnection } from '@wagmi/solid'
useConnection.ReturnTypeaddress
Address | undefined
The connected account address.
addresses
readonly Address[] | undefined
All connected account addresses.
chain
Chain | undefined
The connected chain.
chainId
number | undefined
The connected chain ID.
connector
Connector | undefined
The active connector.
isConnected
boolean
Whether an account is connected.
isConnecting
boolean
Whether a connection is in progress.
isDisconnected
boolean
Whether the account is disconnected.
isReconnecting
boolean
Whether a reconnection is in progress.
status
'connected' | 'connecting' | 'disconnected' | 'reconnecting'
The current connection status.