-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathdeploy.ts
63 lines (49 loc) · 1.42 KB
/
deploy.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
import { ApiPromise, WsProvider, Keyring } from "@polkadot/api";
import TokenConstructors from "./types/constructors/adder";
import {
Addresses,
uploadCode,
storeAddresses,
estimateContractInit,
} from "./utils";
import "dotenv/config";
import "@polkadot/api-augment";
const envFile = process.env.ENV || "dev";
async function import_env() {
return await import(`./env/${envFile}.json`);
}
async function main(): Promise<void> {
let {
ws_node,
authority,
authority_seed,
} = await import_env();
let wsProvider = new WsProvider(ws_node);
let keyring = new Keyring({ type: "sr25519" });
const api = await ApiPromise.create({ provider: wsProvider });
const deployer = keyring.addFromUri(authority_seed);
const adderCodeHash = await uploadCode(api, deployer, "adder.contract");
console.log("adder code hash:", adderCodeHash);
const adderConstructors = new TokenConstructors(api, deployer);
let estimatedGasToken = await estimateContractInit(
api,
deployer,
"adder.contract",
[],
);
const { address: adderAddress } = await adderConstructors.new(
// 1,
{ gasLimit: estimatedGasToken },
);
console.log("adder address:", adderAddress);
const addresses: Addresses = {
adder: adderAddress,
};
console.log("addresses:", addresses);
storeAddresses(addresses);
await api.disconnect();
}
main().catch((error) => {
console.error(error);
process.exitCode = 1;
});