Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

browserify -- provide instructions and best practices #31

Closed
SilentCicero opened this issue Jun 16, 2016 · 13 comments
Closed

browserify -- provide instructions and best practices #31

SilentCicero opened this issue Jun 16, 2016 · 13 comments

Comments

@SilentCicero
Copy link

SilentCicero commented Jun 16, 2016

Please provide the browserify instructions and best practices. Many people will use this module in the browser. We should have a solid known way to browserify everything properly.

i.e. something like this:

browserify -s 'solc' -e . -o ./dist/solc-bundle.js
@axic
Copy link
Member

axic commented Jun 16, 2016

I don't think this package has any specific browserify requirements.

@cofdev0
Copy link

cofdev0 commented Aug 1, 2017

Could you please explain what the best practice is to use solc in Jest tests?

Requiring solc in Jest tests also leads to "Uncaught TypeError: soljson.cwrap is not a function"

@axic
Copy link
Member

axic commented Aug 1, 2017

I am not able to reproduce that problem. Browserify works for me locally. Are you sure you have a local soljson.js? Run npm run downloadsolc to download one.

@wighawag
Copy link

wighawag commented Feb 2, 2018

Get the same issue with jest :

in my js test file :

const solc = require('solc');

fails with:

Uncaught TypeError: soljson.cwrap is not a function

@dangell7
Copy link

dangell7 commented Feb 3, 2018

I'm where you are lol.

Webpack, react redux app. This is my only hangup. Thinking about setting up an api to a server just to get the abi and bytecode for a contract. lol

@woodydeck
Copy link

woodydeck commented Mar 10, 2018

Yea, can't get it to work either. Does anyone have examples of it working? I just need the bytecode, nothing else on the frontend.

I tried browser-solc, but you need to parse the results, and there is no documentation to how it actually outputs.

@jmahhh
Copy link

jmahhh commented Apr 10, 2018

So am I correct in thinking this + browserify/webpack is broken?

@ghost
Copy link

ghost commented Apr 13, 2018

I have the same error "Uncaught TypeError: soljson.cwrap is not a function" in my Jest test files.

Without Jest it works fine. Is there anyone who have found a solution for Jest?

@GrandSchtroumpf
Copy link
Contributor

GrandSchtroumpf commented Apr 22, 2018

Same error here. I'm in Angular (Webpack). I downloaded the soljson.js bin, and did :

const soljson = require('./soljson.js');
console.log(soljson); // Object{}

Same thing with import from :

import * as soljson from './soljson.js';  // Object{}

I saw the electron warning, but it doesn't seems relevant in this case.

@mattiaerre
Copy link

I've been able to fix this issue w/ Jest adding the following setup in my package.json file:

"jest": {
    "testEnvironment": "node"
  }

HTH @max-block

@GrandSchtroumpf
Copy link
Contributor

If you want to import solc in the browser you need to :

  • 1 : Add that to your index.html :
    <script type="text/javascript" src="https://ethereum.github.io/solc-bin/bin/list.js"></script>
    <script type="text/javascript" src="https://ethereum.github.io/solc-bin/bin/{{ SOLC VERSION }}.js"></script>

This will load 3 global variables : soljsonSources, soljsonReleases and Module.
Note: Check the url for the version of solc you want to use here.

  • 2 : Use a solc wrapper :
    By default solc uses its soljson.js inside its wrapper. I don't know why (yet), but it doesn't works in a browser. So you need to provide window.Module inside the wrapper :
import * as wrapper from 'solc/wrapper'; // OR const solc = require('solc/wrapper');

const solc = wrapper(window.Module);
const compiled = solc.compile(/* Your contract */);

If someone knows why the default soljson.js is not loaded correctly in a browser I'm curious to know why.

@axic
Copy link
Member

axic commented Dec 7, 2018

@GrandSchtroumpf could you submit a README update?

@GrandSchtroumpf
Copy link
Contributor

Sure. Btw, do you know why the default sol.json.js is not loaded in a browser?

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

9 participants