Installation
Use this React ui package to smoothly embed a fully featured Relay powered interface into your application. Start by installing the required packages:
If using typescript ensure that you’re on v5+. Refer to the package json for the latest version requirements for the peer dependencies.
Tanstack Query Setup
The hooks require TanStack Query to be installed and configured. Refer to the Tanstack installation instructions.
Configuration
Once all dependencies are installed you can now configure and wrap your application with the RelayKitProvider
. You’ll need to also wrap your application with the QueryClientProvider and the WagmiProvider. Note the order in the snippet below.
import { RelayKitProvider } from '@reservoir0x/relay-kit-ui'
import { convertViemChainToRelayChain } from '@reservoir0x/relay-sdk'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import '@reservoir0x/relay-kit-ui/styles.css'
const queryClient = new QueryClient()
const chains = [convertViemChainToRelayChain(mainnet)]
const wagmiConfig = getDefaultConfig({
appName: 'Relay Demo',
projectId: "YOUR_WALLET_CONNECT_ID",
chains: [mainnet]
})
const App = () => {
return (
<QueryClientProvider client={queryClient}>
<RelayKitProvider options={{
appName: 'Relay Demo',
appFees: [
{
recipient: '0x0000000000000000000000000000000000000000',
fee: '100'
}
]
duneApiKey: "YOUR_DUNE_KEY",
chains
}}>
<WagmiProvider config={wagmiConfig}>
<YourApp />
</WagmiProvider>
</RelayKitProvider>
</QueryClientProvider>
)
}
If you’re using the convertViemChainToRelayChain
you’ll need to install and import the @reservoir0x/relay-sdk
to use this function.
Styling
Make sure to import the styles.css globally otherwise the components will be unstyled:
import '@reservoir0x/relay-kit-ui/styles.css'
Configuring Chains Dynamically
While you can easily supply chains that your application supports, you may want to fetch the supported Relay chains dynamically and configure them in your application. This can be done by using the useRelayChains
hook.
import { useRelayChains } from '@reservoir0x/relay-kit-hooks'
import { RelayKitProvider } from '@reservoir0x/relay-kit-ui'
import { convertViemChainToRelayChain } from '@reservoir0x/relay-sdk'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
const queryClient = new QueryClient()
const App = () => {
const { chains, viemChains } = useRelayChains(relayApi)
useEffect(() => {
if (!wagmiConfig && chains && viemChains) {
setWagmiConfig(
getDefaultConfig({
appName: 'Relay Demo',
projectId: 'YOUR_WALLET_CONNECT_ID',
chains: (viemChains && viemChains.length === 0
? [mainnet]
: viemChains) as [Chain, ...Chain[]]
})
)
}
}, [chains, relayApi])
return (
<QueryClientProvider client={queryClient}>
<RelayKitProvider options={{
duneApiKey: "YOUR_DUNE_KEY",
chains
}}>
<WagmiProvider config={wagmiConfig}>
<YourApp />
</WagmiProvider>
</RelayKitProvider>
</QueryClientProvider>
)
}
Learn more about the RelayKitProvider
options.
Review
Let’s review with a checklist to make sure we got everything in:
- Install the required dependencies
- Configure Tanstack Query and Wagmi
- Configure
RelayKitProvider
with chains and options
- Import the
styles.css
file to style our ui components