Skip to main content
React Native
// Requires setting up the RN Viem extension
// See: /react-native/wallets/viem
import { dynamicClient } from '<path-to-your-dynamicClient>'; // extended with ViemExtension
import { parseEther } from 'viem'

export const sendTransaction = async (to: `0x${string}`, amountEth: string) => {
  const wallet = dynamicClient.wallets.primary;
  if (!wallet) return;

  const publicClient = dynamicClient.viem.createPublicClient({ chain: { id: await wallet.getNetwork() } as any })
  const walletClient = dynamicClient.viem.createWalletClient({ wallet });

  const hash = await walletClient.sendTransaction({
    to,
    value: parseEther(amountEth),
  });

  const receipt = await publicClient.getTransactionReceipt({ hash });
  console.log(receipt);
  return hash;
}

Simulate a Transaction

Before sending a transaction, you can simulate it to preview the effects and validate that it will succeed. Transaction simulation shows all asset transfers involved in the transaction.
Transaction simulation uses the currently selected primary wallet. Make sure the user has a wallet connected before attempting to simulate a transaction.
React Native
import { dynamicClient } from '<path-to-your-dynamicClient>';
import { parseEther } from 'viem';

const simulateEvmTransaction = async (to: `0x${string}`, amountEth: string) => {
  const simulationResult = await dynamicClient.wallets.simulateEVMTransaction({
    transaction: {
      from: dynamicClient.wallets.primary.address,
      to,
      value: parseEther(amountEth),
      data: '0x',
    },
    type: 'SignTransaction',
  });

  console.log('Simulation result:', simulationResult);
  return simulationResult;
};