/
transfer.ts
37 lines (34 loc) · 1.14 KB
/
transfer.ts
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
import { ethers } from "ethers";
import { Client, Presets } from "userop";
import { CLIOpts } from "../../src";
// @ts-ignore
import config from "../../config.json";
export default async function main(t: string, amt: string, opts: CLIOpts) {
const paymaster = opts.withPM
? Presets.Middleware.verifyingPaymaster(
config.paymaster.rpcUrl,
config.paymaster.context
)
: undefined;
const simpleAccount = await Presets.Builder.SimpleAccount.init(
new ethers.Wallet(config.signingKey),
config.rpcUrl,
config.entryPoint,
config.simpleAccountFactory,
paymaster
);
const client = await Client.init(config.rpcUrl, config.entryPoint);
const target = ethers.utils.getAddress(t);
const value = ethers.utils.parseEther(amt);
const res = await client.sendUserOperation(
simpleAccount.execute(target, value, "0x"),
{
dryRun: opts.dryRun,
onBuild: (op) => console.log("Signed UserOperation:", op),
}
);
console.log(`UserOpHash: ${res.userOpHash}`);
console.log("Waiting for transaction...");
const ev = await res.wait();
console.log(`Transaction hash: ${ev?.transactionHash ?? null}`);
}