Integrate Embedded Wallets with the Ethereum Blockchain in React Native
While using the Embedded Wallets React Native SDK, you get a EIP1193 provider, similar to the MetaMask Provider. Use it with libraries such as viem or ethers to make Ethereum blockchain calls like getting the user's account, fetching balance, sign transaction, send transaction, read from and write to the smart contract, etc.
Chain details for Ethereum
- Mainnet
- Sepolia Testnet
- Holesky Testnet
- Chain ID: 0x1
- RPC URL: You can use our bundled RPC service from Infura, or your own choice of RPC service for production.
- Display Name: Ethereum Mainnet
- Block Explorer Link:
https://etherscan.io - Ticker: ETH
- Ticker Name: Ethereum
- Chain ID: 0xaa36a7
- Public RPC URL:
https://ethereum-sepolia.publicnode.com - Display Name: Ethereum Sepolia Testnet
- Block Explorer Link:
https://sepolia.etherscan.io - Ticker: ETH
- Ticker Name: SepoliaETH
- Chain ID: 0x4268
- Public RPC URL:
https://rpc.holesky.ethpandaops.io - Display Name: Ethereum Holesky Testnet
- Block Explorer Link:
https://holesky.etherscan.io - Ticker: ETH
- Ticker Name: HoleskyETH
Installation
Use any EIP-1193 compatible library with the provider from the SDK. These examples use viem:
- npm
- Yarn
- pnpm
- Bun
npm install viem
yarn add viem
pnpm add viem
bun add viem
To use Wagmi hooks instead, see Ethereum hooks (Wagmi).
Configure the chain
Enable the chain for your project on the Embedded Wallets dashboard,
or add it to web3AuthOptions.chains with chainNamespace: CHAIN_NAMESPACES.EIP155 and the chain
details above. See Configure the SDK.
Initialize
Set up the SDK as described in Get started, with the chain
configured on the dashboard or in web3AuthOptions.chains. After sign-in, read the EIP-1193
provider from useWeb3Auth().connection and create viem clients:
import { useWeb3Auth } from '@web3auth/react-native-sdk'
import { createPublicClient, createWalletClient, custom } from 'viem'
const { connection } = useWeb3Auth()
// Call after the user signs in (isConnected is true)
const transport = custom(connection!.ethereumProvider!)
const walletClient = createWalletClient({ transport })
const publicClient = createPublicClient({ transport })
Get account
const [address] = await walletClient.getAddresses()
Get balance
import { formatEther } from 'viem'
const [address] = await walletClient.getAddresses()
const balance = formatEther(await publicClient.getBalance({ address }))
Send transaction
import { parseEther } from 'viem'
const [account] = await walletClient.getAddresses()
const hash = await walletClient.sendTransaction({
account,
to: '0x40e1c367Eca34250cAF1bc8330E9EddfD403fC56',
value: parseEther('0.001'),
chain: null, // use the provider's active chain
})
const receipt = await publicClient.waitForTransactionReceipt({ hash })
Sign a message
const [account] = await walletClient.getAddresses()
const signature = await walletClient.signMessage({
account,
message: 'YOUR_MESSAGE',
})