ThirdwebSDKProvider
The ThirdwebSDKProvider
is used when you want to provide your own wallet connection logic and just use the thirdweb SDK to
interact with smart contracts and the blockchain. This means you can use everything in the SDK except for wallet connection-related components and hooks.
Wrap your app in the ThirdwebSDKProvider
to access the SDK’s functionality from anywhere in your app. Provide a signer
prop to inform the SDK of the wallet you want to use, among other configuration options.
Wrap your app in the ThirdwebSDKProvider
to access the SDK's functionality from anywhere in your app.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";import { ethers } from "ethers";function MyApp() {// Example: Use ethers to get the signer from the window.ethereum objectconst signer = new ethers.providers.Web3Provider(window.ethereum,).getSigner();return (<ThirdwebSDKProvideractiveChain={"ethereum"}signer={signer}clientId="your-client-id"><App /></ThirdwebSDKProvider>);}
A signer is an abstraction of an Ethereum Account, which can be used to sign messages and initiate transactions.
Since the ThirdwebSDKProvider
is used when you want to provide your own wallet connection logic,
you will need to provide a signer
prop to inform the SDK of the wallet you want to use to sign transactions.
Libraries such as ethers.js, web3.js, wagmi, etc. all provide ways to get a signer.
To use this signer with the SDK, pass it to the signer
prop. If the signer is connected, the SDK will use this wallet
to sign transactions for all write operations on the blockchain.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";import { ethers } from "ethers";function MyApp() {// Example: Use ethers to get the signer from the window.ethereum objectconst signer = new ethers.providers.Web3Provider(window.ethereum,).getSigner();return (<ThirdwebSDKProvideractiveChain={"ethereum"}signer={signer}clientId="your-client-id"><App /></ThirdwebSDKProvider>);}
The clientId
prop is required to use the thirdweb infrastructure services with the SDK. You can get a client ID by creating an API key on thirdweb dashboard.
function MyApp() {return (<ThirdwebSDKProvideractiveChain={"ethereum"}clientId="your-client-id"><App /></ThirdwebSDKProvider>);}
The activeChain
prop determines which chain you want your app to be operating on.
It defaults to "ethereum"
if activeChain
prop is not provided.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";import { Gnosis } from "@thirdweb-dev/chains";function Example() {return (<ThirdwebSDKProvideractiveChain={Gnosis}clientId="your-client-id"><App /></ThirdwebSDKProvider>);}
If you are using one of our default chains, provide the name of the chain as a string
to the activeChain
prop.
["ethereum","goerli","polygon","arbitrum","arbitrum-goerli","optimism","optimism-goerli","binance","binance-testnet","fantom","fantom-testnet","avalanche-fuji","avalanche-fuji-testnet","localhost",];
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";function App() {return (<ThirdwebSDKProvideractiveChain="ethereum"clientId="your-client-id"><YourApp /></ThirdwebSDKProvider>);}
If the chain you are looking for is not one of default supported chains, you can import a chain from the @thirdweb-dev/chains package which has 1000+ chains.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";import { <chain_id>} from "@thirdweb-dev/chains";function App() {return (<ThirdwebSDKProvider activeChain={<chain_id>} clientId="your-client-id"><YourApp /></ThirdwebSDKProvider>);}
Override the default values (such as an RPC URL) for any given chain.
By default, the @thirdweb-dev/chains
provides free-to-use RPCs. No configuration required!
Using the spread syntax,
you can override any properties of a chain, such as the rpc
field.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";import { <chain_id> } from "@thirdweb-dev/chains";const activeChain = {...<chain_id>,rpc: ["https://<your-rpc-to-use>.com"], // Override the "rpc" field.// ... Override any other fields you want to customize.};const App = () => {return (<ThirdwebSDKProvider activeChain={activeChain}><YourApp /></ThirdwebSDKProvider>);};
If your chain is not included in the @thirdweb-dev/chains
package,
you can provide the chain information yourself to the activeChain
prop.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";const customChain = {// Required information for connecting to the networkchainId: 59140, // Chain ID of the networkrpc: ["<your-rpc-url-here>"], // Array of RPC URLs to use// Information for adding the network to your wallet (how it will appear for first time users) === \\// Information about the chain's native currency (i.e. the currency that is used to pay for gas)nativeCurrency: {decimals: 18,name: "Consensys ETH",symbol: "crETH",},shortName: "czkevm", // Display value shown in the wallet UIslug: "consensys", // Display value shown in the wallet UItestnet: true, // Boolean indicating whether the chain is a testnet or mainnetchain: "ConsenSys", // Name of the networkname: "ConsenSys zkEVM Testnet", // Name of the network};const App = () => {return (<ThirdwebSDKProvider activeChain={customChain}><YourApp /></ThirdwebSDKProvider>);};
If you are running a local node using a tool such as Hardhat or
Anvil,
provide "localhost"
as the activeChain
prop, (or Localhost
imported from @thirdweb-dev/chains
).
Deploy or import your contracts to the dashboard to interact with them.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";function MyApp() {return (<ThirdwebSDKProvider activeChain="localhost"><YourApp /></ThirdwebSDKProvider>);}
The configuration object for setting up Auth, allowing users to sign in with their wallet.
Property | Type | Description |
---|---|---|
authUrl | string | The backend URL of the authentication endpoints. For example, if your endpoints are at /api/auth/login , /api/auth/logout , etc. then this should be set to /api/auth . |
domain | string | The frontend domain used to generate the login payload. This domain should match the domain used on your auth backend. |
secureStorage | ISecureStorage | Secure storage to use when working with JWT tokens. ** By default auth uses cookies so no need to set this unless you want to specifically use JWT tokens ** |
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";function MyApp() {return (<ThirdwebSDKProviderauthConfig={{authUrl: "/api/auth",domain: "https://example.com",}}><YourApp /></ThirdwebSDKProvider>);}
Override any of the default values for the SDK.
Gas settings, gasless transactions, RPC configuration, and more.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";const sdkOptions = {readonlySettings: {rpcUrl: "<rpc-url>", // force read calls to go through your own RPC urlchainId: 1, // reduce RPC calls by specifying your chain ID},gasSettings: {maxPriceInGwei: 123, // Maximum gas price for transactions (default 300 gwei)speed: "fastest", // the tx speed setting: 'standard'|'fast|'fastest' (default: 'fastest')},gasless: {// By specifying a gasless configuration - all transactions will get forwarded to enable gasless transactionsengine: {relayerUrl: "<engine-relayer-url>", // your thirdweb Engine relayer URL},openzeppelin: {relayerUrl: "<open-zeppelin-relayer-url>", // your OZ Defender relayer URLrelayerForwarderAddress: "<open-zeppelin-forwarder-address>", // the OZ defender relayer address (defaults to the standard one)},biconomy: {apiId: "biconomy-api-id", // your Biconomy API IdapiKey: "biconomy-api-key", // your Biconomy API KeydeadlineSeconds: 123, // your Biconomy timeout preference},},infuraApiKey: "<infura-api-key>", // your Infura API keyalchemyApiKey: "<alchemy-api-key>", // your Alchemy API key};function Example() {return (<ThirdwebSDKProvider sdkOptions={sdkOptions}><App /></ThirdwebSDKProvider>);}
Override the default Storage interface used by the SDK.
Allows you to create an instance of ThirdwebStorage
with your own customized config, and pass it to the SDK.
This requires the @thirdweb-dev/storage
package to be installed.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";import {ThirdwebStorage,StorageDownloader,IpfsUploader,} from "@thirdweb-dev/storage";// Configure a custom ThirdwebStorage instanceconst storage = new ThirdwebStorage({uploader: new IpfsUploader(),downloader: new StorageDownloader(),gatewayUrls: {"ipfs://": ["https://gateway.ipfscdn.io/ipfs/","https://cloudflare-ipfs.com/ipfs/","https://ipfs.io/ipfs/",],},});// Provide the custom storage instance to the SDKfunction MyApp() {return (<ThirdwebSDKProvider storageInterface={storage}><YourApp /></ThirdwebSDKProvider>);}
If you are using React Query and have your own QueryClient
,
you can pass it as the queryClient
prop to use this client instead of the SDK's default client.
import { ThirdwebSDKProvider } from "@thirdweb-dev/react";import {QueryClient,QueryClientProvider,} from "@tanstack/react-query";function MyApp() {// Your React Query client (or client from other library such as wagmi)const queryClient = new QueryClient();return (<QueryClientProvider client={queryClient}><ThirdwebSDKProvider queryClient={queryClient}><YourApp /></ThirdwebSDKProvider></QueryClientProvider>);}