import { Alert, Button, View } from "react-native";
import { useTurnkey } from "@turnkey/react-native-wallet-kit";
export function SignAndSendTransactionButton() {
const { signAndSendTransaction, wallets } = useTurnkey();
const doSignAndSend = async () => {
try {
const wallet = wallets?.[0];
const walletAccount = wallet?.accounts?.[0];
if (!walletAccount) {
Alert.alert("No account", "Create a wallet and account before sending");
return;
}
const unsignedTransaction = "0x..."; // Replace with your unsigned tx
const txId = await signAndSendTransaction({
walletAccount,
unsignedTransaction,
transactionType: "TRANSACTION_TYPE_ETHEREUM",
// Optionally provide a custom RPC endpoint
// rpcUrl: "https://mainnet.infura.io/v3/<key>",
});
console.log("Transaction broadcasted:", txId);
} catch (error) {
console.error("Error sending transaction:", error);
Alert.alert("Error", "Failed to send transaction");
}
};
return (
<View style={{ padding: 16 }}>
<Button title="Sign & Send" onPress={doSignAndSend} />
</View>
);
}