Summary

We provide the useRpcProviders hook that allows direct access to RPC providers for EVM & Solana. Rpc providers can be used to make RPC calls to the blockchain while also providing convenience methods without going through a wallet.

Each provider will use the RPC configured in the Dashboard if present, otherwise they fall back to public RPCs urls. By default, all EVM and Solana networks have public default providers as shown in this table:

NetworkPublic RPC Url
Ethereumhttps://cloudflare-eth.com
Solanahttps://api.mainnet-beta.solana.com
Optimismhttps://mainnet.optimism.io
Gnosis Chainhttps://rpc.gnosischain.com
Aurorahttps://mainnet.aurora.dev
Polygonhttps://polygon-rpc.com
Palmhttps://palm-mainnet.infura.io/v3/3a961d6501e54add9a41aa53f15de99b
BNB Smart Chainhttps://arb1.arbitrum.io/rpc

Dashboard Configuration

To enter your provider url for a given network:

  1. Go to the Chains & Networks page in your Dashboard.
  2. Click on the chain to open the details tab
  3. Click the down down arrow to expand a network
  4. Enter your Provider Url
  5. Click the test button to check url

Usage

You are able to use the useRpcProviders hook to obtain an object with rpc providers, and this hook expects a selector parameter that you must use to select either EVM or Solana rpc providers.

import { useRpcProviders } from '@dynamic-labs/sdk-react-core'
import { evmProvidersSelector } from '@dynamic-labs/ethereum-core'
import { solanaProvidersSelector } from '@dynamic-labs/solana-core'

const App = () => {
  const evmProviders = useRpcProviders(evmProvidersSelector)
  const solanaProviders = useRpcProviders(solanaProvidersSelector)
}

The hook returns either EvmRpcProviderMethods or SolanaRpcProviderMethods, with the following fields:

defaultProvider
EvmRpcProvider | SolanaRpcProvider | undefined

The provider for EVM or Solana Mainnet, if mainnet is enabled

providers
EvmRpcProvider[] | SolanaRpcProvider[] | undefined

A full list of all EVM or Solana providers that have been configured

getProviderByChainId
(chainId: number | string) => EvmRpcProvider | SolanaRpcProvider | undefined

A convenience method that lets you retrieve a provider for a specific Chain ID

Check out the reference for EvmRpcProvider and SolanaRpcProvider

Example

Below is a simple example using EVM providers to fetch an arbitrary ENS mapping:

import { useRpcProviders } from '@dynamic-labs/sdk-react-core'
import { evmProvidersSelector } from '@dynamic-labs/ethereum-core'

const useLogEnsMapping = () => {
  const { defaultProvider } = useRpcProviders(evmProvidersSelector)

  const mainnetProvider = defaultProvider?.provider;

  const ensAddress = mainnetProvider.resolveName('myname.eth');

  console.log('address for myname.eth', ensAddress);
}