Skip to content

Commit

Permalink
Fix deploy.ts (#383)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Rey authored Jan 3, 2024
1 parent e88b483 commit 5efde84
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
17 changes: 3 additions & 14 deletions packages/sc-project-initializer/commands/init/src/deploy.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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');
Expand All @@ -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);

/**
Expand All @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions packages/sc-project-initializer/commands/init/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
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) {
throw new Error(`Missing ${key} in .env file`);
}
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));
}

0 comments on commit 5efde84

Please sign in to comment.