-
Notifications
You must be signed in to change notification settings - Fork 0
/
permissionless.ts
92 lines (76 loc) · 2.44 KB
/
permissionless.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import {
ENTRYPOINT_ADDRESS_V06,
ENTRYPOINT_ADDRESS_V07,
createSmartAccountClient,
type UserOperation,
} from "permissionless";
import {
signerToEcdsaKernelSmartAccount,
signerToSimpleSmartAccount,
} from "permissionless/accounts";
import {
createPimlicoBundlerClient,
createPimlicoPaymasterClient,
} from "permissionless/clients/pimlico";
import {
type PublicClient,
createPublicClient,
http,
parseEther,
type Address,
} from "viem";
import { base } from "viem/chains";
import { privateKeyToAccount } from "viem/accounts";
import { JiffyPaymaster } from "@jiffy-labs/web3a";
const rpc = process.env.RPC as string;
export const publicClient: PublicClient = createPublicClient({
transport: http(rpc),
});
const jiffyscanKey = process.env.JIFFYSCAN_KEY as string;
const paymasterClient = new JiffyPaymaster("https://paymaster.jiffyscan.xyz", 8453, {
"x-api-key": jiffyscanKey,
});
const pvtKey = process.env.PVT_KEY as `0x${string}`;
const signer = privateKeyToAccount(pvtKey);
const kernelAccount = await signerToEcdsaKernelSmartAccount(publicClient, {
entryPoint: ENTRYPOINT_ADDRESS_V06, // global entrypoint
signer: signer,
index: 0n, // optional
});
const smartAccountClient = createSmartAccountClient(
{
// @ts-ignore
account: kernelAccount,
entryPoint: ENTRYPOINT_ADDRESS_V06,
chain: base,
bundlerTransport: http('https://base.jiffyscan.xyz', {
fetchOptions: {
headers: { "x-api-key": jiffyscanKey },
},
}),
middleware: {
sponsorUserOperation: paymasterClient.sponsorUserOperationV6,
}
});
console.log(kernelAccount.address);
export const bundlerClient = createPimlicoBundlerClient({
transport: http('https://base.jiffyscan.xyz', {
fetchOptions: {
headers: { "x-api-key": jiffyscanKey },
},
}),
entryPoint: ENTRYPOINT_ADDRESS_V06,
});
const gasPrices = await bundlerClient.getUserOperationGasPrice();
console.log(gasPrices);
// @ts-ignore
console.log(smartAccountClient.account.address);
// @ts-ignore
const txHash = await smartAccountClient.sendTransaction({
to: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
// nonce: 1,
value: parseEther("0.00"),
maxFeePerGas: gasPrices.fast.maxFeePerGas, // if using Pimlico
maxPriorityFeePerGas: gasPrices.fast.maxPriorityFeePerGas, // if using Pimlico
});
console.log(txHash);