ThirdwebProvider
The ThirdwebProvider
is a wrapper component that provides access to all of the SDK’s hooks and UI components.
API Key
You will require an API key to use thirdweb's infrastructure services with the SDK.
you need to first obtain an API key from the dashboard and then copy the "Client ID" and pass it to the ThirdwebProvider
as the clientId
prop.
Wrap your app in the ThirdwebProvider
to access the SDK’s functionality from anywhere in your app.
import { ThirdwebProvider } from "@thirdweb-dev/react-native";function Example() {return (<ThirdwebProvideractiveChain="ethereum"clientId="your-client-id"><App /></ThirdwebProvider>);}
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 { ThirdwebProvider } from "@thirdweb-dev/react-native";import { Gnosis } from "@thirdweb-dev/chains";function Example() {return (<ThirdwebProvider activeChain={Gnosis} clientId="your-client-id"><App /></ThirdwebProvider>);}
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 { ThirdwebProvider } from "@thirdweb-dev/react-native";function App() {return (<ThirdwebProvideractiveChain="ethereum"clientId="your-client-id"><YourApp /></ThirdwebProvider>);}
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 { ThirdwebProvider } from "@thirdweb-dev/react-native";import { <chain_id> } from "@thirdweb-dev/chains";function App() {return (<ThirdwebProvider activeChain={<chain_id>} clientId="your-client-id"><YourApp /></ThirdwebProvider>);}
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 { ThirdwebProvider } from "@thirdweb-dev/react-native";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 (<ThirdwebProvider activeChain={activeChain}><YourApp /></ThirdwebProvider>);};
If your chain is not included in the @thirdweb-dev/chains
package,
you can provide the chain information yourself to the activeChain
prop.
import { ThirdwebProvider } from "@thirdweb-dev/react-native";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 (<ThirdwebProvider activeChain={customChain}><YourApp /></ThirdwebProvider>);};
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 { ThirdwebProvider } from "@thirdweb-dev/react-native";function MyApp() {return (<ThirdwebProvider activeChain="localhost"><YourApp /></ThirdwebProvider>);}
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 { ThirdwebProvider } from "@thirdweb-dev/react-native";function MyApp() {return (<ThirdwebProviderauthConfig={{authUrl: "/api/auth",domain: "https://example.com",}}><YourApp /></ThirdwebProvider>);}
When the user has connected their wallet to your site, this flag determines whether or not you want to automatically connect to the last connected wallet when user visits your site again in the future.
Defaults to true
import { ThirdwebProvider } from "@thirdweb-dev/react-native";function MyApp() {return (<ThirdwebProvider autoConnect={true}><YourApp /></ThirdwebProvider>);}
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.
import { ThirdwebProvider } from "@thirdweb-dev/react-native";function MyApp() {return (<ThirdwebProvideractiveChain="ethereum"clientId="your-client-id"><YourApp /></ThirdwebProvider>);}
This Metadata is passed to the wallet. Some wallets use this information to display the metadata of the app to the user when a user is connecting the wallet to your app.
If no dAppMeta
prop is set, it defaults to below object:
{name: "thirdweb powered dApp",url: "https://thirdweb.com",};
Property | Type | Description |
---|---|---|
name | string | the name of your app |
description | string | optional - a description of your app |
logoUrl | string | optional - a URL that points to a logo (or favicon) of your app |
url | string | optional - the URL where your app is hosted |
isDarkMode | boolean | optional - whether to show the connect dialog in dark mode or not |
import { ThirdwebProvider } from "@thirdweb-dev/react-native";function MyApp() {return (<ThirdwebProviderdAppMeta={{name: "My App",description: "My app description",logoUrl: "https://example.com/logo.png",url: "https://example.com",isDarkMode: true,}}><YourApp /></ThirdwebProvider>);}
Object that contains all text used for thirdweb components.
It allows you to change the language used in UI components or override the texts used in the UI.
You can add support for any language you want just by passing an object with the required strings.
import { ThirdwebProvider } from "@thirdweb-dev/react-native";<ThirdwebProvider locale="es"><App /></ThirdwebProvider>;
More info in our Locale Reference
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 { ThirdwebProvider } from "@thirdweb-dev/react-native";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}><ThirdwebProvider queryClient={queryClient}><YourApp /></ThirdwebProvider></QueryClientProvider>);}
Override any of the default values for the SDK.
Gas settings, gasless transactions, RPC configuration, and more.
import { ThirdwebProvider } from "@thirdweb-dev/react-native";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 transactionsopenzeppelin: {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 (<ThirdwebProvider sdkOptions={sdkOptions}><App /></ThirdwebProvider>);}
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 { ThirdwebProvider } from "@thirdweb-dev/react-native";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 (<ThirdwebProvider storageInterface={storage}><YourApp /></ThirdwebProvider>);}
An array of chains supported by your app.
You can import chains from @thirdweb-dev/chains
which contains 1000+ chains.
import { ThirdwebProvider } from "@thirdweb-dev/react-native";import { Ethereum, Polygon } from "@thirdweb-dev/chains";function MyApp() {return (<ThirdwebProvideractiveChain={Ethereum}supportedChains={[Ethereum, Polygon]}><App /></ThirdwebProvider>);}
If not provided, It defaults to below shown default chains.
["ethereum","goerli","polygon","arbitrum","arbitrum-goerli","optimism","optimism-goerli","binance","binance-testnet","fantom","fantom-testnet","avalanche-fuji","avalanche-fuji-testnet","localhost",];
An array of wallets that your app supports.
Wallets provided here appear in the ConnectWallet Modal and allow you to use the wallet connection hooks.
Learn more about connecting wallets and the options available.
import {ThirdwebProvider,metamaskWallet,coinbaseWallet,walletConnect,} from "@thirdweb-dev/react-native";function MyApp() {return (<ThirdwebProvidersupportedWallets={[metamaskWallet(),coinbaseWallet(),walletConnect(),]}activeChain="ethereum"clientId="your-client-id"><App /></ThirdwebProvider>);}
Sets the theme for all thirdweb components.
By default it is set to "dark".
theme can be set to either "dark" or "light" or a custom theme object.
You can also import the lightTheme
or darkTheme
functions from @thirdweb-dev/react-native
to use the default themes as base and overrides parts of it.
import { ThirdwebProvider } from "@thirdweb-dev/react-native";<ThirdwebProvider theme="light"><App /></ThirdwebProvider>;
More info in our Theme Reference