Code Monkey home page Code Monkey logo

Comments (7)

jasonandjay avatar jasonandjay commented on August 25, 2024 1

Thanks, how do you mean I can't open test.html in the browser directly? Note that I'm running this in an offline environment, just on my local computer (that doesn't run a webserver). It always worked like this with previous BitcoinJS versions (v5 and earlier) but I think since v6 there have been some changes resulting in this browser incompatibility.

Note that it works fine if I comment the const ecc line, it's just this particular tiny-secp256k1 that seems to cause an issue when using in a browserified package (this was not the case with previous versions).

I'm not sure sure what you mean by the second option. Note that I don't use any wasm file myself, it's just the code from one of the libraries used in BitcoinJS, I use it as-is. I'd rather not manually change it or mess with its internals, otherwise I'll have the same trouble whenever I update to a newer version.

use @bitcoinerlab/secp256k1 replace tiny-secp256k1
have a try

from bitcoinjs-lib.

junderw avatar junderw commented on August 25, 2024 1

@bitcoinerlab/secp256k1 is a great alternative implementation that works well with browser bundlers.

WASM support in bundlers is still very iffy.

@bitcoinjs-lib/tiny-secp256k1-asmjs is also available, but a bit slower than bitcoinerlab. But it is generated from the WASM.

from bitcoinjs-lib.

SuperHenkie avatar SuperHenkie commented on August 25, 2024 1

use @bitcoinerlab/secp256k1 replace tiny-secp256k1 have a try

Thanks! That did the trick! 👍

P.S. may I suggest to include this in the using bitcoinjs-lib in browser instructions as I can imagine it may save people a lot of troubleshooting.

Much appreciated! 🙏

from bitcoinjs-lib.

VictorZhang2014 avatar VictorZhang2014 commented on August 25, 2024

The first option, you need to use bundle.js in an environment, like http://localhost:3000 or https://google.com/web3, but do not use the file like index.html opened in the browser directly, it won't work in this way.

The second option, find the error position like(0 , fs_1.readFileSync) and annotate the code, and replace it by loading the wasm file through fetch.

from bitcoinjs-lib.

SuperHenkie avatar SuperHenkie commented on August 25, 2024

Thanks, how do you mean I can't open test.html in the browser directly? Note that I'm running this in an offline environment, just on my local computer (that doesn't run a webserver). It always worked like this with previous BitcoinJS versions (v5 and earlier) but I think since v6 there have been some changes resulting in this browser incompatibility.

Note that it works fine if I comment the const ecc line, it's just this particular tiny-secp256k1 that seems to cause an issue when using in a browserified package (this was not the case with previous versions).

I'm not sure sure what you mean by the second option. Note that I don't use any wasm file myself, it's just the code from one of the libraries used in BitcoinJS, I use it as-is. I'd rather not manually change it or mess with its internals, otherwise I'll have the same trouble whenever I update to a newer version.

from bitcoinjs-lib.

VictorZhang2014 avatar VictorZhang2014 commented on August 25, 2024

If you are using tiny-secp256k1, undoutedly, it uses wasm file because the library was built by Rust. So when you load it in your test.html, the js environment needs to fetch the wasm file at first. Simply speaking, remove the fs and replace it by fetch.

By the way, if you are use @bitcoinerlab/secp256k1 which already removed the wasm file, hence, there shouldn't be an issue occurred like you posted fs_1.readFileSync not found. I suggest you search the fs module in your output bundle script, and check what's going on there because there's no wasm indeed.

from bitcoinjs-lib.

junderw avatar junderw commented on August 25, 2024

use @bitcoinerlab/secp256k1 replace tiny-secp256k1 have a try

Thanks! That did the trick! 👍

P.S. may I suggest to include this in the using bitcoinjs-lib in browser instructions as I can imagine it may save people a lot of troubleshooting.

Much appreciated! 🙏

https://github.com/bitcoinjs/tiny-secp256k1#alternatives

It is mentioned on tiny-secp256k1.

Please make a suggestion as to how you would change it, pull requests to update READMEs etc. are always welcome (even if they tend to get bike-sheddy)

from bitcoinjs-lib.

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.