Mutation hook for calling state-changing contract functions using a Viem WalletClient from useParaViemClient.
Requires @getpara/viem-v2-integration and viem as peer dependencies.
Import
import { useParaViemWriteContract } from "@getpara/react-native-wallet/evm/viem";
Usage
import { useParaViemClient, useParaViemWriteContract } from "@getpara/react-native-wallet/evm/viem";
import { sepolia } from "viem/chains";
import { http, parseUnits } from "viem";
function TransferTokens() {
const { viemClient } = useParaViemClient({
walletClientConfig: { chain: sepolia, transport: http() },
});
const { writeContractAsync, isPending } = useParaViemWriteContract(viemClient);
const handleTransfer = async () => {
const hash = await writeContractAsync({
address: "0xTokenAddress...",
abi: ERC20_ABI,
functionName: "transfer",
args: ["0xRecipient...", parseUnits("10", 18)],
});
console.log("Tx hash:", hash);
};
return (
<button onClick={handleTransfer} disabled={isPending}>
{isPending ? "Sending..." : "Transfer Tokens"}
</button>
);
}
mutate/mutateAsync are also available alongside the named aliases. All other UseMutationResult fields (data, error, isSuccess, isError, reset, etc.) work as expected.