-
Notifications
You must be signed in to change notification settings - Fork 3
/
deploy.js
44 lines (36 loc) · 1.45 KB
/
deploy.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
const fs = require("fs");
const path = require("path");
const Arweave = require("arweave");
const Warp = require('warp-contracts');
const jwk = require("./.secrets/jwk.json");
const { DeployPlugin } = require('warp-contracts-plugin-deploy');
// Arweave initialization
const arweave = Arweave.init({
host: "arweave.net",
port: 443,
protocol: "https",
});
async function deployContract() {
try {
// Loading contract source and initial state from files
const contractSrc = fs.readFileSync(path.join(__dirname, "./dist/contract.js"), "utf8");
const initialState = JSON.parse(fs.readFileSync(path.join(__dirname, "./init-state.json"), "utf8"))
// Warp initialization
const warp = Warp.WarpFactory.forMainnet().use(new DeployPlugin());
const walletAddress = await arweave.wallets.getAddress(jwk);
initialState.minter = walletAddress
console.log(`Deploying contract for address ${walletAddress}`);
// Deploying contract
const deployResult = await warp.deploy({
wallet: jwk,
src: contractSrc,
initState: JSON.stringify(initialState),
data: { 'Content-Type': 'image/png', body: fs.readFileSync("./pfp.png") },
}, true);
const { contractTxId, srcTxId } = deployResult;
console.log(`Deployment completed.\nDeployer: ${walletAddress}\nContract address: ${contractTxId}\nContract code address: ${srcTxId}`);
} catch (error) {
console.error("Failed to deploy contract:", error);
}
}
deployContract();