Wagmi is not available on React Native. Use Ethers.js or Viem for EVM operations.
Send ETH
- Ethers.js
- Viem
import { ethers } from "ethers";
import { ParaEthersSigner } from "@getpara/ethers-v6-integration";
async function sendETH(
signer: ParaEthersSigner,
toAddress: string,
amountInEther: string
) {
const tx = await signer.sendTransaction({
to: toAddress,
value: ethers.parseEther(amountInEther)
});
const receipt = await tx.wait();
return {
hash: tx.hash,
blockNumber: receipt.blockNumber,
gasUsed: receipt.gasUsed.toString()
};
}
import { parseEther } from "viem";
async function sendETH(
walletClient: any,
publicClient: any,
toAddress: `0x${string}`,
amountInEther: string
) {
const hash = await walletClient.sendTransaction({
to: toAddress,
value: parseEther(amountInEther)
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
return {
hash,
blockNumber: receipt.blockNumber,
gasUsed: receipt.gasUsed.toString()
};
}
Send ERC-20 Tokens
- Ethers.js
- Viem
import { ethers } from "ethers";
const ERC20_ABI = [
"function transfer(address to, uint256 amount) returns (bool)"
];
async function sendToken(
signer: any,
tokenAddress: string,
toAddress: string,
amount: string,
decimals: number
) {
const contract = new ethers.Contract(tokenAddress, ERC20_ABI, signer);
const parsedAmount = ethers.parseUnits(amount, decimals);
const tx = await contract.transfer(toAddress, parsedAmount);
const receipt = await tx.wait();
return {
hash: tx.hash,
blockNumber: receipt.blockNumber,
gasUsed: receipt.gasUsed.toString()
};
}
import { parseUnits } from "viem";
const ERC20_ABI = [
{
name: "transfer",
type: "function",
stateMutability: "nonpayable",
inputs: [
{ name: "to", type: "address" },
{ name: "amount", type: "uint256" }
],
outputs: [{ type: "bool" }]
}
] as const;
async function sendToken(
walletClient: any,
publicClient: any,
tokenAddress: `0x${string}`,
toAddress: `0x${string}`,
amount: string,
decimals: number
) {
const parsedAmount = parseUnits(amount, decimals);
const hash = await walletClient.writeContract({
address: tokenAddress,
abi: ERC20_ABI,
functionName: "transfer",
args: [toAddress, parsedAmount]
});
const receipt = await publicClient.waitForTransactionReceipt({ hash });
return {
hash,
blockNumber: receipt.blockNumber,
gasUsed: receipt.gasUsed.toString()
};
}