-
Notifications
You must be signed in to change notification settings - Fork 0
/
with-ethers.tsx
60 lines (52 loc) · 1.57 KB
/
with-ethers.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React from "react";
import { ethers, TransactionRequest } from "ethers";
import { CapsuleEthersSigner } from "@usecapsule/ethers-v6-integration";
import useTransactionManager from "../../demo-ui/hooks/useTransactionManager";
import TransactionForm from "../../demo-ui/components/transaction-form";
import { capsuleClient } from "../capsule-client";
const SignWithEthers: React.FC = () => {
const {
fromAddress,
recipient,
amount,
error,
isLoading,
signatureResult,
setRecipient,
setAmount,
setIsLoading,
setSignatureResult,
resetForm,
} = useTransactionManager();
const handleSign = async () => {
setIsLoading(true);
const provider = new ethers.JsonRpcProvider("https://ethereum-sepolia-rpc.publicnode.com");
const capsuleEthersSigner = new CapsuleEthersSigner(capsuleClient, provider);
const demoTx: TransactionRequest = {
from: fromAddress,
to: recipient,
value: ethers.parseUnits(amount, "ether"),
nonce: 0,
gasLimit: 21000n,
gasPrice: ethers.parseUnits("20", "gwei"),
};
const signedTx = await capsuleEthersSigner.signTransaction(demoTx);
setSignatureResult(signedTx);
setIsLoading(false);
};
return (
<TransactionForm
fromAddress={fromAddress}
recipient={recipient}
amount={amount}
onRecipientChange={setRecipient}
onAmountChange={setAmount}
onSign={handleSign}
onReset={resetForm}
isLoading={isLoading}
error={error}
signatureResult={signatureResult}
/>
);
};
export default SignWithEthers;