-
Notifications
You must be signed in to change notification settings - Fork 6
/
cli.js
92 lines (79 loc) · 3.18 KB
/
cli.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
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
const fs = require("fs");
const program = require('commander');
const { Tezos } = require('@taquito/taquito');
const { encodeExpr } = require('@taquito/utils');
const { HttpBackend } = require('@taquito/http-utils');
program.version('0.0.1');
const setup = async () => {
const { email, password, mnemonic, secret } = JSON.parse(fs.readFileSync('./faucet.json').toString())
Tezos.setProvider({ rpc: "https://api.tez.ie/rpc/babylonnet" })
await Tezos.importKey(email, password, mnemonic.join(" "), secret)
return Tezos;
}
program.command("deploy <total_supply>")
.action(async (total_supply, command) => {
console.log('Deploying...')
try {
const Tezos = await setup();
const op = await Tezos.contract.originate({
code: JSON.parse(fs.readFileSync("./build/Token.json").toString()),
storage: {
totalSupply: total_supply,
ledger: {
[await Tezos.signer.publicKeyHash()]: {
balance: total_supply,
allowances: {
[await Tezos.signer.publicKeyHash()]: total_supply,
},
}
}
},
})
const contract = await op.contract();
console.log('Deployed at address: ', contract.address)
} catch (ex) {
console.error(ex)
}
})
const prettyPrint = (obj) => JSON.stringify(obj, null, 2)
program.command("storage <address>")
.action(async (address, command) => {
try {
const Tezos = await setup();
const contract = await Tezos.contract.at(address)
const storage = prettyPrint(await contract.storage());
const rawStorage = prettyPrint(await Tezos.rpc.getStorage(address))
console.log(`Storage:\n${storage}`)
console.log(`Raw Storage:\n${rawStorage}`)
} catch (ex) {
console.error(ex)
}
})
program.command("account")
.action(async () => {
try {
const Tezos = await setup();
console.log(await Tezos.signer.publicKeyHash())
} catch (ex) {
console.error(ex)
}
})
program.command("bigMap <address> <key>")
.action(async (address, keyToEncode, command) => {
try {
const Tezos = await setup();
const contract = await Tezos.contract.at(address)
const storage = await contract.storage()
const bigMapID = storage.ledger.id.toString()
const { key, type } = storage.ledger.schema.EncodeBigMapKey(keyToEncode);
const { packed } = await Tezos.rpc.packData({ data: key, type });
const encodedExpr = encodeExpr(packed);
const bigMapValue = prettyPrint(await storage.ledger.get(keyToEncode))
const rawBigMapValue = prettyPrint(await Tezos.rpc.getBigMapExpr(bigMapID, encodedExpr));
console.log(`Storage:\n${bigMapValue}`)
console.log(`Raw Storage:\n${rawBigMapValue}`)
} catch (ex) {
console.error(ex)
}
})
program.parse(process.argv);