iotaledger / curl.lib.js

IOTA Proof-of-Work algorithm ported to Javascript to work in WebGL2-enabled browsers
GNU General Public License v3.0
37 stars 31 forks source link

Can't use this lib in browser #28

Open avihai-developer opened 6 years ago

avihai-developer commented 6 years ago

After i load dist/curl.min.js to my site i don't have curl object available in my window scope

jlvandenhout commented 5 years ago

Any updates on this? I'm struggling to get this to work as well. Including the library in my html page as <script src="curl.min.js"></script>, but window.curl is not defined and const Curl = require('curl.min.js') or const Curl = require('curl.lib.js') aren't working either.

pRizz commented 5 years ago

As an alternative, I've created npm friendly wrappers for curl which may be used as so:

npm install curl-transaction-core curl-transaction-webgl2-impl

Then in code:

import curlTransaction from 'curl-transaction-core'
import curlImpl from 'curl-transaction-webgl2-impl'

if(!curlImpl.error) {
    localAttachToTangle = curlTransaction({ curlImpl }).localAttachToTangle
    console.log('Your browser does support WebGL2')
    this.iota.link.api.attachToTangle = localAttachToTangle
} else {
    console.error('Your browser does not support WebGL2')
    this.isWebGL2Supported = false
}
desjob commented 5 years ago

I have no problem doing the following, based on the current master branch:

<script type="text/javascript" src="./old.curl.min.js"></script>
<script type="text/javascript">
curl.init();
... etc
</script>

maybe this has been fixed in the meantime? try making a new version of curl.min.js, clone this repository and run: npm install npm run build and the new curl.min.js will be in the dist folder