A tutorial that teaches what providers are, why you need one, and how to configure several providers and use them to connect to the blockchain.
chain
and rpcUrls
listed in Viem’s directory of chain information. You can view the [data for Base Sepolia here].
Most chains will list this information in their docs as well. For example, on the network information pages for [Base] and [Optimism]. If you wanted, you could manually set up a jsonRpcProvider
in wagmi using this information.
window.ethereum
.
Under the hood, these are also just JSON RPC providers. Similar to public providers, they are rate-limited.
Older tutorials for early libraries tended to suggest using this method for getting started, so you’ll probably encounter references to it. However, it’s fallen out of favor, and you’ll want to use the public provider for your initial connection experiments.
[Alchemy Costs] | [QuickNode Costs] | [CDP Costs] | |
---|---|---|---|
Free Tier / Mo. | 3M compute units | 50M credits | 500M billing units |
Mid Tier / Mo. | 1.5B CUs @ $199 | 3B credits @ $299 | Coming soon |
eth_blocknumber | 10 | 20 | 30 |
eth_call | 26 | 20 | 30 |
eth_getlogs | 75 | 20 | 100 |
eth_getbalance | 19 | 20 | 30 |
useContractRead
hook set to watch for changes on a single view
via a TanStack query and useBlockNumber
will call eth_blocknumber
and eth_call
one time each, every 4 seconds.
.
to create a project in the root of the folder you run it from, so you’ll want to run it from your src
directory, or wherever you keep your project folders.It will create a folder with the project name you give, and create the files inside.pages/_app.tsx
. Here, you’ll find a familiar Next.js app wrapped in [context providers] for the TanStack QueryProvider, RainbowKit, and wagmi.
projectId
.
Open up the [WalletConnect] homepage, and create an account, and/or sign in using the method of your choice.
Click the Create
button in the upper right of the Projects
tab.
App
option, and click Create
.
projectId
in getDefaultWallets
.
NEXT_PUBLIC_
to any environment variables that can be read by the browser.Before you deploy, make sure you configure the rest of the items in the control panel to ensure only your site can use this id.mainnet
and base
.
Connect Wallet
button, select your wallet from the modal, approve the connection, and you should see your network, token balance, and address or ENS name at the top of the screen. Select your wallet from the modal.
createConfig
] instead of getDefaultConfig
. The [transports
] property allows you to configure how you wish to connect with multiple networks. If you need more than one connector for a given network, you can use [fallbacks
].
First, set up using [QuickNode] as your provider. Replace your import of the default config from RainbowKit with createConfig
and http
from wagmi:
Endpoints
on the left side, then click + Create Endpoint
.
On the next screen, you’ll be asked to select a chain. Each endpoint only works for one. Select Base
, click Continue
.
Base Mainnet
, but you’ll probably want to delete this endpoint and create a new one for Sepolia when you start building. The free tier only allows you to have one at a time.
If you haven’t already picked a tier, you’ll be asked to do so, then you’ll be taken to the endpoints page, which will display your endpoints for HTTP and WSS.
http
transport
to your config:
Apps
section in the left sidebar, and click Create new app
.