React Native Quickstart
Get started with WDK in React Native in under 3 minutes
What You'll Build
Prerequisites
Tool
Version
Why You Need It
Get started with WDK in React Native in under 3 minutes
Was this helpful?
git clone https://github.com/tetherto/wdk-starter-react-native.git
cd wdk-starter-react-nativenpm installcp .env.example .envEXPO_PUBLIC_WDK_INDEXER_BASE_URL=https://wdk-api.tether.io
EXPO_PUBLIC_WDK_INDEXER_API_KEY=your_actual_api_key_here
# Optional: For Tron network support
EXPO_PUBLIC_TRON_API_KEY=your_tron_api_key
EXPO_PUBLIC_TRON_API_SECRET=your_tron_api_secretnpm run iosnpm run androidnpm install @tetherto/wdk-react-native-providernpm install \
@craftzdog/react-native-buffer \
@react-native-async-storage/async-storage \
@tetherto/pear-wrk-wdk \
@tetherto/wdk-secret-manager \
b4a \
bip39 \
browserify-zlib \
decimal.js \
events \
http2-wrapper \
https-browserify \
nice-grpc-web \
path-browserify \
process \
querystring-es3 \
react-native-bare-kit \
react-native-crypto \
react-native-device-info \
react-native-get-random-values \
react-native-keychain \
react-native-tcp-socket \
react-native-url-polyfill \
sodium-javascript \
stream-browserify \
stream-http{
"expo": {
"plugins": [
[
"expo-build-properties",
{
"android": {
"minSdkVersion": 29
}
}
]
]
}
}npx expo install expo-build-propertiesbuildscript {
ext {
minSdkVersion = 29
// ... other config
}
}const { getDefaultConfig } = require("expo/metro-config");
const {
configureMetroForWDK,
} = require("@tetherto/wdk-react-native-provider/metro-polyfills");
const config = getDefaultConfig(__dirname);
const configWdk = configureMetroForWDK(config);
module.exports = configWdk;const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
const {
configureMetroForWDK,
} = require("@tetherto/wdk-react-native-provider/metro-polyfills");
const config = getDefaultConfig(__dirname);
const configWdk = configureMetroForWDK(config);
module.exports = mergeConfig(config, configWdk);// src/config/chains.ts
export const CHAINS_CONFIG = {
ethereum: {
chainId: 1,
blockchain: "ethereum",
provider: "https://mainnet.gateway.tenderly.co/YOUR_KEY",
bundlerUrl: "https://api.candide.dev/public/v3/ethereum",
paymasterUrl: "https://api.candide.dev/public/v3/ethereum",
paymasterAddress: "0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba",
entrypointAddress: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
transferMaxFee: 5000000,
swapMaxFee: 5000000,
bridgeMaxFee: 5000000,
paymasterToken: {
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7", // USDT
},
},
polygon: {
chainId: 137,
blockchain: "polygon",
provider: "https://polygon.gateway.tenderly.co/YOUR_KEY",
bundlerUrl: "https://api.candide.dev/public/v3/polygon",
paymasterUrl: "https://api.candide.dev/public/v3/polygon",
paymasterAddress: "0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba",
entrypointAddress: "0x0000000071727De22E5E9d8BAf0edAc6f37da032",
transferMaxFee: 5000000,
swapMaxFee: 5000000,
bridgeMaxFee: 5000000,
paymasterToken: {
address: "0xc2132d05d31c914a87c6611c10748aeb04b58e8f", // USDT on Polygon
},
safeModulesVersion: "0.3.0",
},
bitcoin: {
host: "api.ordimint.com",
port: 50001,
},
// Add more chains as needed
};// app/_layout.tsx
import { WalletProvider } from "@tetherto/wdk-react-native-provider";
import { Stack } from "expo-router";
import { CHAINS_CONFIG } from "../config/chains";
export default function RootLayout() {
return (
<WalletProvider
config={{
indexer: {
apiKey: process.env.EXPO_PUBLIC_WDK_INDEXER_API_KEY!,
url: process.env.EXPO_PUBLIC_WDK_INDEXER_BASE_URL!,
},
chains: CHAINS_CONFIG,
enableCaching: true,
}}
>
<Stack />
</WalletProvider>
);
}// App.tsx
import React from "react";
import { WalletProvider } from "@tetherto/wdk-react-native-provider";
import { CHAINS_CONFIG } from "./src/config/chains";
import { NavigationContainer } from "@react-navigation/native";
import { MainNavigator } from "./src/navigation";
export default function App() {
return (
<WalletProvider
config={{
indexer: {
apiKey: process.env.EXPO_PUBLIC_WDK_INDEXER_API_KEY!,
url: process.env.EXPO_PUBLIC_WDK_INDEXER_BASE_URL!,
},
chains: CHAINS_CONFIG,
enableCaching: true,
}}
>
<NavigationContainer>
<MainNavigator />
</NavigationContainer>
</WalletProvider>
);
}// src/screens/WalletScreen.tsx
import React from "react";
import { View, Text, Button } from "react-native";
import { useWallet } from "@tetherto/wdk-react-native-provider";
export function WalletScreen() {
const {
wallet,
balances,
transactions,
isInitialized,
isUnlocked,
createWallet,
unlockWallet,
refreshWalletBalance,
} = useWallet();
// Create a new wallet
const handleCreateWallet = async () => {
try {
const wallet = await createWallet({
name: "Imported Wallet",
mnemonic: "your twelve word seed phrase goes here",
});
console.log("Wallet created:", wallet);
} catch (error) {
console.error("Failed to create wallet:", error);
}
};
// Unlock wallet
const handleUnlockWallet = async () => {
try {
await unlockWallet();
console.log("Wallet unlocked");
} catch (error) {
console.error("Failed to unlock wallet:", error);
}
};
if (!isInitialized) {
return <Text>Initializing WDK...</Text>;
}
if (!wallet) {
return (
<View>
<Text>Create or Import a Wallet</Text>
<Button title="Create New Wallet" onPress={handleCreateWallet} />
</View>
);
}
if (!isUnlocked) {
return (
<View>
<Text>Wallet Locked</Text>
<Button title="Unlock Wallet" onPress={handleUnlockWallet} />
</View>
);
}
return (
<View>
<Text>Wallet: {wallet.name}</Text>
{/* Display balances */}
{balances.list.map((balance, index) => (
<Text key={index}>
{balance.denomination}: {balance.value}
</Text>
))}
<Button
title="Refresh Balance"
onPress={refreshWalletBalance}
disabled={balances.isLoading}
/>
{balances.isLoading && <Text>Loading balances...</Text>}
</View>
);
}npx expo prebuild --clean
npx expo run:ios
# or
npx expo run:androidnpx react-native run-ios
# or
npx react-native run-androidconst { balances, transactions, addresses } = useWallet();
...import {
WDKService,
NetworkType,
AssetTicker,
} from "@tetherto/wdk-react-native-provider";
// Send USDT on Ethereum
const result = await WDKService.sendByNetwork(
NetworkType.ETHEREUM,
0, // account index
100, // amount
"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb", // recipient
AssetTicker.USDT
);// Get fee estimate before sending
const feeEstimate = await WDKService.quoteSendByNetwork(
NetworkType.ETHEREUM,
0,
100,
"0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb",
AssetTicker.USDT
);
console.log("Estimated fee:", feeEstimate);const { clearWallet } = useWallet();
// Clear wallet and all stored data
await clearWallet();rm -rf node_modules
npm install{
"expo": {
"plugins": [
["expo-build-properties", { "android": { "minSdkVersion": 29 } }]
]
}
}npx expo prebuild --clean
npx expo run:androidconst { isInitialized, createWallet } = useWallet();
if (isInitialized) {
await createWallet({ name: "My Wallet" });
}{
"compilerOptions": {
"skipLibCheck": true
}
}