-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathn3_query_balance.ts
57 lines (44 loc) · 1.87 KB
/
n3_query_balance.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
import { CONST } from "@cityofzion/neon-core-next";
import { rpc } from "@cityofzion/neon-js-next";
import BigNumber from "bignumber.js";
import * as BIP39 from "bip39";
import * as wif from "wif";
import N3Client from "../lib/clients/N3Client";
import { N3Address, SWTHAddress } from "../lib/util/address";
import { BN_ZERO } from "../lib/util/number";
import { CarbonSDK } from "./_sdk";
import "./_setup";
const neoRpcUrl = "http://seed1t4.neo.org:20332";
;
(async () => {
const mnemonics = process.env.MNEMONICS ?? BIP39.generateMnemonic();
console.log("mnemonics", mnemonics);
const n3Client = N3Client.instance({
configProvider: {
getConfig: () => ({
n3: {
rpcURL: neoRpcUrl,
networkMagic: CONST.MAGIC_NUMBER.TestNet,
},
} as any),
},
})
const bech32Address = SWTHAddress.generateAddress(mnemonics);
console.log("deposit to ", bech32Address)
const privateKeyWif = "";
const privateKey = wif.decode(privateKeyWif).privateKey.toString("hex");
const fromAddress = N3Address.privateKeyToAddress(privateKey);
console.log("fromAddress", fromAddress);
const balances = await new rpc.RPCClient(neoRpcUrl).execute(new rpc.Query({
method: "getnep17balances",
"params": [fromAddress],
}));
console.log("balances", balances);
const toAddressBytes = SWTHAddress.getAddressBytes(bech32Address, CarbonSDK.Network.DevNet);
const toAddressHex = Buffer.from(toAddressBytes).toString("hex");
const lockProxyScriptHash = "eeebee7ef57cb2106fbad2c51c5b9b4c30f0c0ca"
const tokenScriptHash = "285b332bc0323bc334987bd4735fb39cc3269e20"
const signer = N3Client.signerFromPrivateKey(privateKey);
const result = await n3Client.lock(lockProxyScriptHash, tokenScriptHash, fromAddress, toAddressHex, new BigNumber(8800), BN_ZERO, signer);
console.log(result);
})().catch(console.error).finally(() => process.exit(0));