> For the complete documentation index, see [llms.txt](/llms.txt).

# 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[​](#using-the-provider-with-ethers "Direct link to 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 await 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!)
    const signer = await ep.getSigner()
    return await signer.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[​](#using-the-provider-with-viem "Direct link to 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[​](#raw-private-key-export "Direct link to 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](https://developer.metamask.io/) under **Key Export** settings.

If key export is enabled in your project, you can request the private key using `personal_sign` through the provider:

```
import { useWeb3Auth } from '@web3auth/react-native-sdk'

function ExportPrivateKeyView() {
  const { provider } = useWeb3Auth()

  const exportPrivateKey = async () => {
    // Requires key export to be enabled in the dashboard
    const privateKey = await provider?.request({
      method: 'eth_private_key',
    })
    return privateKey
  }

  // Call exportPrivateKey() from a button handler or effect when needed
}

```

## Related[​](#related "Direct link to Related")

- [useWeb3Auth hook reference](/embedded-wallets/sdk/react-native/hooks/useWeb3Auth/)
