UNPKG

@massalabs/massa-sc-utils

Version:
128 lines 4.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const tslib_1 = require("tslib"); const massa_web3_1 = require("@massalabs/massa-web3"); const SmartContractDeployer_1 = require("../utils/SmartContractDeployer"); const prompt = require("prompt"); const path = require("path"); const fs = require("fs"); const chalk = require("chalk"); prompt.start(); const schema = { properties: { smartContractWasmFile: { description: "Smart Contract Wasm file to deploy", message: "Smart Contract Wasm file to deploy", type: "string", required: true }, networkID: { description: "Network ID", message: "Must be one of MAINNET/TESTNET/LABNET", pattern: "(MAINNET|TESTNET|LABNET)", type: "string", default: "LABNET", required: true }, deployerSecretKey: { description: "Deployer Account Secret Key", message: "Secret key must be base58 encoded", type: "string", hidden: true, replace: "*", required: true }, fee: { description: "Fee", required: true, type: "number", default: 0 }, maxGas: { description: "Max Gas", required: true, type: "number", default: 200000 }, gasPrice: { description: "Gas Price", required: true, type: "number", default: 0 }, coins: { description: "Coins to send with deployment", required: true, type: "number", default: 0, }, } }; prompt.get(schema, (err, result) => tslib_1.__awaiter(void 0, void 0, void 0, function* () { if (err) { console.error(`Prompt error: ${chalk.red(err)}`); process.exit(1); } // get input from prompt const networkID = result.networkID.toUpperCase(); let selectedNetwork = massa_web3_1.DefaultProviderUrls.TESTNET; switch (networkID) { case "TESTNET": { selectedNetwork = massa_web3_1.DefaultProviderUrls.TESTNET; break; } case "MAINNET": { selectedNetwork = massa_web3_1.DefaultProviderUrls.MAINNET; break; } case "LABNET": { selectedNetwork = massa_web3_1.DefaultProviderUrls.LABNET; break; } default: { throw new Error(`Unknown network selected: ${networkID}`); } } const deployerSecretKey = result.deployerSecretKey; const smartContractWasmFile = result.smartContractWasmFile; if (!fs.existsSync(smartContractWasmFile)) { throw new Error(`The wasm file under ${smartContractWasmFile} does not exist.`); } if (!path.extname(smartContractWasmFile).endsWith(".wasm")) { throw new Error(`The wasm file under ${smartContractWasmFile} is not a wasm file.`); } const fee = result.fee; const maxGas = result.maxGas; const gasPrice = result.gasPrice; const coins = result.coins; // init deployer account and a web3 client let deployerAccount; try { deployerAccount = yield massa_web3_1.WalletClient.getAccountFromSecretKey(deployerSecretKey); } catch (ex) { throw new Error(`Wrong secret key. Deployer account could not be initialized: ${ex}`); } let web3Client = null; try { web3Client = yield massa_web3_1.ClientFactory.createDefaultClient(selectedNetwork, true, deployerAccount); } catch (ex) { throw new Error(`Error creating a web3 client: ${ex}`); } try { // upload website to sc address yield (0, SmartContractDeployer_1.deploySmartContract)(smartContractWasmFile, { fee, maxGas, gasPrice, coins, }, web3Client, true, deployerAccount); } catch (ex) { const msg = chalk.red(`Error compiling & deploying smart contract on path ${chalk.yellow(smartContractWasmFile)}`); console.error(msg); throw new Error(ex); } })); //# sourceMappingURL=deploySmartContract.js.map