-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
82 lines (72 loc) · 3.22 KB
/
deploy.js
File metadata and controls
82 lines (72 loc) · 3.22 KB
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
/**
* deploy.js — deploy the example QRC20 to the active Quantova network.
*
* Run: npm run deploy:testnet (sets QUANTOVA_NETWORK=testnet)
*
* This script shows the SHAPE of a Quantova deployment. The signing step uses
* the @quantova SDK keyring with a post-quantum key. Compilation (Solidity ->
* QVM bytecode) is done with Qdock.io or solc; point COMPILED_BYTECODE_PATH at
* the artifact, or wire your compiler of choice into the `compile` step.
*
* Security: the deployer key is read from QUANTOVA_DEPLOYER_KEY in the
* environment. NEVER commit a real key. Use a testnet key funded from the faucet.
* See docs/deploying.md.
*/
import fs from "node:fs";
import { QuantovaClient } from "../src/client.js";
import { rpcUrl, activeNetwork } from "../src/config.js";
// The @quantova SDK provides the keyring + post-quantum signing. Install with
// `npm install @quantova/keyring @quantova/util-crypto` and uncomment:
// import { Keyring } from "@quantova/keyring";
const BYTECODE_PATH = process.env.COMPILED_BYTECODE_PATH || "./build/ExampleQRC20.bin";
async function main() {
const net = activeNetwork();
const client = new QuantovaClient(rpcUrl());
console.log(`Deploying to ${net.name} (${rpcUrl()})`);
const deployerKey = process.env.QUANTOVA_DEPLOYER_KEY;
if (!deployerKey) {
throw new Error("Set QUANTOVA_DEPLOYER_KEY in .env (a testnet key funded from the faucet).");
}
if (!fs.existsSync(BYTECODE_PATH)) {
throw new Error(
`Compiled bytecode not found at ${BYTECODE_PATH}. ` +
"Compile ExampleQRC20.sol with Qdock.io or solc first (see docs/deploying.md)."
);
}
const bytecode = "0x" + fs.readFileSync(BYTECODE_PATH, "utf8").trim().replace(/^0x/, "");
// 1. Build the deployment transaction (to = null for a contract creation).
const chainId = await client.chainId();
const tx = {
to: null,
data: bytecode, // append ABI-encoded constructor args here if your contract takes them
gas: "0x" + (await client.estimateGas({ to: null, input: bytecode })).toString(16),
chainId,
};
// 2. Sign locally with the post-quantum deployer key (SDK keyring).
// const keyring = new Keyring();
// const account = keyring.addFromSecret(deployerKey); // Dilithium/Falcon/SPHINCS+
// const signedTx = await account.signTransaction(tx);
//
// For the template we stop before broadcasting so a misconfigured key can't
// accidentally spend. Replace the line below with the real signed payload.
const signedTx = process.env.SIGNED_TX_HEX;
if (!signedTx) {
console.log("\nPrepared deployment transaction:");
console.log(JSON.stringify(tx, null, 2));
console.log(
"\nNext: sign this with the @quantova SDK keyring and broadcast via " +
"client.sendRawTransaction(signedTx). See docs/deploying.md."
);
return;
}
// 3. Broadcast and wait for the receipt.
const txHash = await client.sendRawTransaction(signedTx);
console.log("Submitted:", txHash);
const receipt = await client.waitForReceipt(txHash);
console.log("Deployed at:", receipt.contractAddress);
console.log("Reminder: confirm finality (~3s) before treating the deployment as settled.");
}
main().catch((err) => {
console.error("deploy failed:", err.message);
process.exit(1);
});