Connect
- React
- React-Native
- TypeScript
- Unity
useConnect
Hook for connecting any supported wallet config to your app.
import { useConnect } from "@thirdweb-dev/react";
const connect = useConnect();
The wallet also needs to be added in ThirdwebProvider's supportedWallets if you want the wallet to auto-connect on next page load.
Usage
import { useConnect, metamaskWallet } from "@thirdweb-dev/react";
const metamaskConfig = metamaskWallet();
function App() {
const connect = useConnect();
return (
<button
onClick={async () => {
const wallet = await connect(metamaskConfig, connectOptions);
console.log("connected to ", wallet);
}}
>
Connect to MetaMask
</button>
);
}
Configuration
walletConfig
The wallet to connect to your app with.
Must be of type WalletConfig
.
connectOptions
connectOptions
depends on the wallet you are connecting.
If you are using typescript, connect
will automatically infer the type of connectOptions
based on the walletConfig
you pass in.
useConnect
Hook for connecting any supported wallet config to your app.
import { useConnect } from "@thirdweb-dev/react-native";
const connect = useConnect();
The wallet also needs to be added in ThirdwebProvider's supportedWallets if you want the wallet to auto-connect on next page load.
Usage
import { useConnect, metamaskWallet } from "@thirdweb-dev/react-native";
const metamaskConfig = metamaskWallet();
function App() {
const connect = useConnect();
return (
<button
onClick={async () => {
const wallet = await connect(metamaskConfig, connectOptions);
console.log("connected to ", wallet);
}}
>
Connect to MetaMask
</button>
);
}
Configuration
walletConfig
The wallet to connect to your app with.
Must be of type WalletConfig
.
connectOptions
connectOptions
depends on the wallet you are connecting.
If you are using typescript, connect
will automatically infer the type of connectOptions
based on the walletConfig
you pass in.
Connect
Connect any supported wallet connector to your app.
const walletAddress = await wallet.connect();
Connect
Connect a user’s wallet to your game.
Usage
string address = await sdk.wallet.Connect();
Configuration
walletConnection
The type of wallet to connect to, and which chain to connect to.
// Connect to the user's wallet via CoinbaseWallet
string address = await sdk.wallet.Connect(
new WalletConnection(
provider = WalletProvider.WalletConnect, // e.g. use WalletConnect on any platform
chainId = 1 // Switch the wallet Ethereum Mainnet on connection
)
);
chainId
The ID of the blockchain to switch to upon connection.
Must be a BigInteger
(or int
).
password
Optional password for encrypted Local Wallet account, uses auto-generated password if left empty.
Must be a string
.
email
Optional email used for MagicLink provider.
Must be a string
.
personalWallet
Optional WalletProvider
to use with WalletProvider.SmartWallet
as your main provider.
Defaults to WalletProvider.LocalWallet
Return Value
Returns a string
representing the connected wallet address with a valid checksum.
string;