GithubHelp home page GithubHelp logo

Comments (11)

Fthi-S3074641 avatar Fthi-S3074641 commented on May 16, 2024 7

put a semicolon at the end of the directive, see more.

pragma solidity ^0.4.11;

from solc-js.

vincentvanderwalt avatar vincentvanderwalt commented on May 16, 2024 2

I managed to fix the issue by doing the following.

  • Open the contract in VS Code
  • On bottom right click the current encoding in my case UTF-8
  • It opens the option to Save with Encoding click that.
  • I then reselected UTF-8

after that I ran the code in a previous comment and it worked.

Thanks for looking into this @chriseth

Vinny

from solc-js.

prameshbajra avatar prameshbajra commented on May 16, 2024 2

Neither adding semicolon nor changing the character encoding worked for me. Anything else that I could try? It's very irritating. 😠

from solc-js.

Eric-Showers avatar Eric-Showers commented on May 16, 2024 1

I'm in the same position as @prameshbajra has anyone else found a solution?

from solc-js.

Mehathab4eva avatar Mehathab4eva commented on May 16, 2024 1

@prameshbajra @Eric-Showers I had the same issue. I suggest you copy your code and paste it on http://remix.ethereum.org. On this site, the common syntax errors are pointed out. In my case, there was a semicolon, which after removing, I was able to compile the code.
Let me know if it works for you.
Thank you.

from solc-js.

prameshbajra avatar prameshbajra commented on May 16, 2024 1

@Mehathab4eva My code works fine in remix. I think it was VS Code + Solc Linter integration that made the error. Not completely sure though.

The error is no more. I don't know how.

I was like one fine morning and all errors were gone 🤣. Poof!!

from solc-js.

chriseth avatar chriseth commented on May 16, 2024

Can you provide the exact command you used to compile? The error looks like the compiler got an empty file as input.

from solc-js.

vincentvanderwalt avatar vincentvanderwalt commented on May 16, 2024

let contractsFile = path.join(__dirname, '../contracts/contracts.sol'); var fileContract = fs.readFileSync(contractsFile, { encoding: 'utf-8' }); _**--- fileContract.length = 3532**_ var output = solc.compile(fileContract.toString(), 1);
The output shows the following (abbreviated)

{ errors: [ ':1:1: Error: Expected import directive or contract definition.\npragma solidity ^0.4.10; contract

from solc-js.

tiredoak avatar tiredoak commented on May 16, 2024

Ran into the same error and tried @vinnytheviking solution but it still didn't work. Are there any other workarounds for this?
The code is:

const input = fs.readFileSync('contracts/helloWorld.sol');
console.log(input); // outputs the contract, no issues here
const output = solc.compile(input.toString(), 1);
console.log(output); // returns the error message here
const bytecode = output.contracts['helloWorld'].bytecode;
const abi = JSON.parse(output.contracts['helloWorld'].interface);

from solc-js.

sidasu92 avatar sidasu92 commented on May 16, 2024

putting a semicolon it worked for me

from solc-js.

anistark avatar anistark commented on May 16, 2024

@tiredoak I've the same code and it works.
However, for some contracts, the bytecode is different from what is generated from http://remix.ethereum.org like browser compilers.
Thoughts?

from solc-js.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.