Blockchain provider and private key
In v9, the preferred way to perform EVM blockchain operations is through the provider returned by useWeb3Auth(). This is an EIP-1193 compatible provider that you pass directly to ethers or viem — no EthereumPrivateKeyProvider or getPrivKey() is needed.
Using the provider with ethers
import { useWeb3Auth } from '@web3auth/react-native-sdk'
import { ethers } from 'ethers'
function EvmActions() {
const { provider } = useWeb3Auth()
const getAddress = async () => {
const ep = new ethers.BrowserProvider(provider!)
const signer = await ep.getSigner()
return signer.getAddress()
}
const getBalance = async () => {
const ep = new ethers.BrowserProvider(provider!)
const signer = await ep.getSigner()
const balance = await ep.getBalance(await signer.getAddress())
return ethers.formatEther(balance)
}
const signMessage = async (message: string) => {
const ep = new ethers.BrowserProvider(provider!)
return (await ep.getSigner()).signMessage(message)
}
const sendTransaction = async (to: string, valueEth: string) => {
const ep = new ethers.BrowserProvider(provider!)
const signer = await ep.getSigner()
const tx = await signer.sendTransaction({
to,
value: ethers.parseEther(valueEth),
})
return tx.hash
}
}
Using the provider with viem
import { useWeb3Auth } from '@web3auth/react-native-sdk'
import { createWalletClient, custom } from 'viem'
import { sepolia } from 'viem/chains'
function ViemActions() {
const { provider } = useWeb3Auth()
const getAddress = async () => {
const client = createWalletClient({
chain: sepolia,
transport: custom(provider!),
})
const [address] = await client.getAddresses()
return address
}
}
Raw private key export
caution
Exporting raw private keys is strongly discouraged. Use the provider for signing instead. Raw key export must be explicitly enabled in the Embedded Wallets dashboard under Key Export settings.
If key export is enabled in your project, you can request the private key using personal_sign through the provider:
const { provider } = useWeb3Auth()
// Request private key via provider — requires key export to be enabled in the dashboard
const privateKey = await provider?.request({
method: 'eth_private_key',
})