Bootstrap a react app
Let’s keep it simple and use create-react-app here. Run the following command in a directory of your choice:npm
npm
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
npx create-react-app txkit-quickstart
cd txkit-quickstart
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import { EtherspotTransactionKit } from "@etherspot/transaction-kit";
import { ethers } from "ethers";
import App from "./App";
const randomWallet = ethers.Wallet.createRandom();
const providerWallet = new ethers.Wallet(randomWallet.privateKey);
const rootElement = document.getElementById("root");
const root = createRoot(rootElement);
root.render(
<StrictMode>
<EtherspotTransactionKit
provider={providerWallet} /* The random wallet we created above */
>
<App />
</EtherspotTransactionKit>
</StrictMode>
);
import "./styles.css";
import {
EtherspotBatches,
EtherspotBatch,
EtherspotTransaction,
useEtherspotTransactions,
useWalletAddress
} from "@etherspot/transaction-kit";
import React from "react";
export default function App() {
const [address, setAddress] = React.useState(
"0x271Ae6E03257264F0F7cb03506b12A027Ec53B31"
);
const [amount, setAmount] = React.useState("0.001");
const { estimate, send } = useEtherspotTransactions();
const etherspotAddresses = useWalletAddress("etherspot-prime", 11155111);
React.useEffect(() => {
console.log(etherspotAddresses);
}, [etherspotAddresses]);
return (
<div className="App">
<h1>Etherspot Demo</h1>
<h2>Let's send some Sepolia ETH.</h2>
<code>{JSON.stringify(etherspotAddresses)}</code>
<EtherspotBatches>
<EtherspotBatch chainId={11155111}>
<EtherspotTransaction to={address} value={amount}>
<input
type="text"
value={address}
onChange={(event) => setAddress(event.target.value)}
/>
<input
type="text"
value={amount}
onChange={(event) => setAmount(event.target.value)}
/>
<hr />
<button onClick={() => estimate()}>Estimate</button>
<button onClick={() => send()}>Send</button>
</EtherspotTransaction>
</EtherspotBatch>
</EtherspotBatches>
</div>
);
}
