diff --git a/packages/sc-project-initializer/commands/init/src/deploy.ts b/packages/sc-project-initializer/commands/init/src/deploy.ts index 9efc1ab9..a58317da 100644 --- a/packages/sc-project-initializer/commands/init/src/deploy.ts +++ b/packages/sc-project-initializer/commands/init/src/deploy.ts @@ -1,8 +1,4 @@ -import * as dotenv from 'dotenv'; -import path from 'path'; -import { readFileSync } from 'fs'; -import { fileURLToPath } from 'url'; -import { getEnvVariable } from './utils'; +import { getScByteCode, getEnvVariable } from './utils'; import { deploySC, WalletClient, ISCData } from '@massalabs/massa-sc-deployer'; import { Args, @@ -11,13 +7,6 @@ import { CHAIN_ID, } from '@massalabs/massa-web3'; -// Obtain the current file name and directory paths -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(path.dirname(__filename)); - -// Load .env file content into process.env -dotenv.config(); - // Get environment variables const publicApi = getEnvVariable('JSON_RPC_URL_PUBLIC'); const secretKey = getEnvVariable('WALLET_SECRET_KEY'); @@ -27,7 +16,7 @@ const maxGas = MAX_GAS_DEPLOYMENT; // Gas for deployment Default is the maximum const fees = 0n; // Fees to be paid for deployment. Default is 0 const waitFirstEvent = true; -// Create an account using the private keyc +// Create an account using the private key const deployerAccount = await WalletClient.getAccountFromSecretKey(secretKey); /** @@ -46,7 +35,7 @@ const deployerAccount = await WalletClient.getAccountFromSecretKey(secretKey); deployerAccount, // account deploying the smart contract(s) [ { - data: readFileSync(path.join(__dirname, 'build', 'main.wasm')), // smart contract bytecode + data: getScByteCode('build', 'main.wasm'), // smart contract bytecode coins: fromMAS(0.1), // coins for deployment args: new Args().addString('Test'), // arguments for deployment } as ISCData, diff --git a/packages/sc-project-initializer/commands/init/src/utils.ts b/packages/sc-project-initializer/commands/init/src/utils.ts index 8fb7d835..969f668b 100644 --- a/packages/sc-project-initializer/commands/init/src/utils.ts +++ b/packages/sc-project-initializer/commands/init/src/utils.ts @@ -1,3 +1,10 @@ +import * as dotenv from 'dotenv'; +import { readFileSync } from 'fs'; +import { fileURLToPath } from 'url'; +import path from 'path'; + +dotenv.config(); + export function getEnvVariable(key: string): string { const value = process.env[key]; if (!value) { @@ -5,3 +12,10 @@ export function getEnvVariable(key: string): string { } return value; } + +export function getScByteCode(folderName: string, fileName: string): Buffer { + // Obtain the current file name and directory paths + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(path.dirname(__filename)); + return readFileSync(path.join(__dirname, folderName, fileName)); +}