'Expected Pragma' error in solc but same code compiles in remix

18 views Asked by At

When I run solc_compiler.js it shows ":1:1: ParserError: Expected pragma, import directive or contract/interface/library definition.\n ... { ... \n ^\n" but it compiles in remix

PairFlash.sol file

pragma solidity ^0.7.6;

contract PairFlash {
}

solc_compiler.js js file

const path = require('path');
const fs = require('fs');
const solc = require('solc');

// Define the relative path to your Solidity file
const relativePath = 'contracts/v3-periphery-main/contracts/examples/PairFlash.sol';
const contractPath = path.resolve(__dirname, relativePath);
const contractCode = fs.readFileSync(contractPath, 'utf8');

const contractName = 'PairFlash.sol'; // Replace with your contract name


// Compile the Solidity code
const input = {
  language: 'Solidity',
  sources: {
    contractName: {
      content: contractCode,
    },
  },
  settings: {
    outputSelection: {
      '*': {
        '*': ['*'],
      },
    },
  },
};

const output = solc.compile(JSON.stringify(input));


// Extract the compiled bytecode and ABI
const compiledContract = output.contracts[contractPath][contractName];
const bytecode = compiledContract.evm.bytecode.object;
const abi = compiledContract.abi;

console.log('Bytecode:\n', bytecode);
console.log('ABI:', JSON.stringify(abi, null, 2));

The solc file string (contractCode) is correct . I checked using the debugger .

Why is it showing an error in solc .

0

There are 0 answers