-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathaccount.js
60 lines (56 loc) · 2.28 KB
/
account.js
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 { toSimpleSmartAccount, toSafeSmartAccount, toEcdsaKernelSmartAccount } from "permissionless/accounts"
import { privateKeyToAccount } from "viem/accounts"
import { http, createPublicClient } from 'viem'
import config from '../../../config.js';
import { baseSepolia } from "viem/chains";
const client = createPublicClient({
chain: baseSepolia,
transport: http(config.rpc_url),
});
// To customize the signer, see https://docs.pimlico.io/permissionless/reference/accounts/signerToSimpleSmartAccount
const owner = privateKeyToAccount(config.private_key)
// To use a different account, see https://docs.pimlico.io/permissionless/how-to/accounts/use-simple-account
export const getAccount = async (type) => {
switch (type) {
case "simple":
// EOA signer (private key) and Simple Account
const simpleAccount = await toSimpleSmartAccount({
owner,
client,
entryPoint: {
address: config.entry_point,
version: config.entry_point_version,
},
})
return simpleAccount
case "safe":
// EOA signer (private key) and Safe
const safeAccount = await toSafeSmartAccount({
owners: [owner],
client,
entryPoint: {
address: config.entry_point,
version: config.entry_point_version
},
version: "1.4.1",
// index: 0n, // optional
// address: "0x...", // optional, only if you are using an already created account
})
return safeAccount
case "kernel":
// EOA signer (private key) and Kernel
const kernelAccount = await toEcdsaKernelSmartAccount({
owners: [owner],
client,
entryPoint: {
address: config.entry_point,
version: config.entry_point_version
},
// index: 0n, // optional
// address: "0x...", // optional, only if you are using an already created account
})
return kernelAccount
default:
throw new Error("Invalid account type in config.json")
}
}