Comments (13)
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
from solc-js.
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?
from solc-js.
So am I correct in thinking this + browserify/webpack is broken?
from solc-js.
I don't think this package has any specific browserify requirements.
from solc-js.
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"
from solc-js.
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.
from solc-js.
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
from solc-js.
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
from solc-js.
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.
from solc-js.
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.
from solc-js.
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 itssoljson.js
inside its wrapper. I don't know why (yet), but it doesn't works in a browser. So you need to providewindow.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.
from solc-js.
@GrandSchtroumpf could you submit a README update?
from solc-js.
Sure. Btw, do you know why the default sol.json.js
is not loaded in a browser?
from solc-js.
Related Issues (20)
- Switch to audited and fast version of sha3/keccak HOT 4
- Exception in an import callback leaves the compiler in an inconsistent state, leading to `You shall not have another CompilerStack aside me` error on next compilation HOT 13
- Does solc.loadRemoteVersion() download a new version of solc each time it is run? HOT 2
- Different bytecode when compiling from both solc-js and remix IDE
- cannot uninstall HOT 2
- OSError: [Errno 86] Bad CPU type in executable: HOT 1
- Cannot remap openzeppelin to use when I compile with solc HOT 1
- Release types on npm HOT 3
- Handle standard JSON transalation with `outputSelection` for `=<0.4.19`
- Failed to compile large json inputs HOT 1
- Callback not supported... HOT 2
- Identifier already declared HOT 2
- solc-select is out of date. Please run `solc-select upgrade` HOT 1
- Support for `--metadata` flag HOT 4
- 0.8.23 npm release won't install on Windows due to a stray dependency HOT 3
- findImports fallback on webWorkers not working HOT 5
- loadRemoteVersion is not working with jest test HOT 3
- 'Expected Pragma' error in solc but same code compiles in remix HOT 1
- Improvement: `content` not a key in solidity `input description` in solidity official doc (except under `destructible`) .
- Web3ContractError: code couldn't be stored HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solc-js.