-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
67 lines (57 loc) · 1.81 KB
/
index.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
import {
DispatchRawOrigin,
dot,
MultiAddress,
PolkadotRuntimeOriginCaller,
} from "@polkadot-api/descriptors"
import { createClient, type SS58String } from "polkadot-api"
import { getSmProvider } from "polkadot-api/sm-provider"
import { chainSpec } from "polkadot-api/chains/polkadot"
import { start } from "polkadot-api/smoldot"
import { appendFileSync, existsSync, rmSync } from "fs"
import { withLogsRecorder } from "polkadot-api/logs-provider"
let tickDate = ""
let timeoutToken
const setTickDate = () => {
tickDate = new Date().toISOString()
timeoutToken = setTimeout(setTickDate, 0)
}
setTickDate()
const WIRE_FILE = "wire-logs.txt"
const SMOLDOT_LOGS_FILE = "smoldot-logs.txt"
if (existsSync(WIRE_FILE)) rmSync(WIRE_FILE)
if (existsSync(SMOLDOT_LOGS_FILE)) rmSync(SMOLDOT_LOGS_FILE)
const smoldot = start({
maxLogLevel: 9,
logCallback: (level: number, target: string, message: string) => {
appendFileSync(
SMOLDOT_LOGS_FILE,
`${tickDate} (${level})${target}\n${message}\n\n`,
)
},
})
const chain = await smoldot.addChain({ chainSpec })
const client = createClient(
withLogsRecorder((log) => {
appendFileSync(WIRE_FILE, log + "\n")
}, getSmProvider(chain)),
)
const dotApi = client.getTypedApi(dot)
const fromAddress: SS58String =
"15roJ4ZrgrZam5BQWJgiGHpgp7ShFQBRNLq6qUfiNqXDZjMK"
console.log(await dotApi.query.System.Account.getValue(fromAddress))
const tx = dotApi.tx.Balances.transfer_keep_alive({
dest: MultiAddress.Id("14dZ1SSu3krJ8TyBY1E4GQ5RDcnjDaop1J9irm9cSs7T6Xq9"),
value: 10_000_000_000n,
})
const result = await dotApi.apis.DryRunApi.dry_run_call(
PolkadotRuntimeOriginCaller.system(
DispatchRawOrigin.Signed(
"15roJ4ZrgrZam5BQWJgiGHpgp7ShFQBRNLq6qUfiNqXDZjMK",
),
),
tx.decodedCall,
)
console.log(result)
client.destroy()
clearTimeout(timeoutToken)