Pages:
Author

Topic: How to use BitcoinJS in a normal website? (not using node.js or anything) (Read 8089 times)

brand new
Activity: 0
Merit: 0
Same problem.   Tongue

For those still having issues, I have a compiled version which works perfectly over here:

https://gist.github.com/Someguy123/49f849d693a063e4fbb2

Test it out like this:

Code:
Generate Random Address




How can i create a key from given hex with bitcoinjs.min.js, i've been looking for it everywhere, & the getAddress() only return compressed address. How can i return uncompressed one or hash160?
newbie
Activity: 22
Merit: 0
Same problem.   Tongue

For those still having issues, I have a compiled version which works perfectly over here:

https://gist.github.com/Someguy123/49f849d693a063e4fbb2

Test it out like this:

Code:
Generate Random Address



It works!
Thank you good man Cheesy
sr. member
Activity: 336
Merit: 254
CEO of Privex Inc. (www.privex.io)
Same problem.   Tongue

For those still having issues, I have a compiled version which works perfectly over here:

https://gist.github.com/Someguy123/49f849d693a063e4fbb2

Test it out like this:

Code:
Generate Random Address



sr. member
Activity: 481
Merit: 252
newbie
Activity: 13
Merit: 2
Did you ever solve this?

I had a similar problem, but I got the following Javascript to work on a bare-bones HTML page:
No, unfortunately I didn't get it working correctly.

Your example does work here (it shows an address), but if I change key = new Bitcoin.ECKey(); into key = bitcoin.ECKey.makeRandom(); it doesn't work.

Also, If I change key.getBitcoinAddress().toString() into key.toWIF() (to show the private key instead of the address) it doesn't work either.

Even though both these samples are litterely mentioned as such on the bitcoinjs.org frontpage Sad
In fact, if you search through the bitcoinjs-min.js file, the search terms 'makeRandom' and 'toWIF' don't even seem to exist at all in the entire .js (neither does 'fromWIF'). I've got a feeling that somehow the page is really outdated, or not being maintained anymore.

Too bad, this would be a great library, if it was clear how to actually use it Undecided
member
Activity: 81
Merit: 10
Interesting, which docs did you follow for the browser version, is there separate that are not nodejs related?

Did you ever solve this?

I had a similar problem, but I got the following Javascript to work on a bare-bones HTML page:

Code:



newbie
Activity: 13
Merit: 2
Thanks, received the file, and tested it locally. Didn't work either (same errors in Chrome and Firefox) so I'm starting to wonder if something is wrong with my system.... I'm gonna do a system reinstall and see if that makes things work Smiley
newbie
Activity: 13
Merit: 2
Firefox also works fine. As a last ditch effort I can send you bitcoin.min.js if you PM me your email address (as a rule of thumb please be careful when receiving attachment)
Thanks, see PM
newbie
Activity: 3
Merit: 0
Firefox also works fine. As a last ditch effort I can send you bitcoin.min.js if you PM me your email address (as a rule of thumb please be careful when receiving attachment)
newbie
Activity: 3
Merit: 0
Hmmm... I'm on Windows and it works fine for me. Not really sure what happened. My chrome version is 36.0.1985.143 m on Windows 7
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
I can answer the last part.  "npm" is node package manager.  I'm using GNU/Linux, and after installing node/npm through the normal package manager on my system (apt-get), I use npm commands to install further node packages.

The "$" might refer to a bash prompt, which would be something "unix related" Smiley  But it might stand for the jquery object $.  Depending on the context.   If your examples all start:

$ npm ...

Then it's referring to the bash prompt on a unix-like system (OSX, GNU/Linux, etc).
OK thanks. Well I'm using Windows only, but apparently, after running the NodeJS installer for Windows, when opening a command prompt and going to the NodeJS program directory, I can magically perform npm commands from there. So it seems the $ in this case also refers to the Windows command prompt.

However, I wonder if some Windows-incompatibilities of NodeJS or npm may be the cause of the strange issues I'm getting with the bitcoinjs.min.js I built myself...?

I can't address whether your issues have to do with windows incompatibilties as I haven't used windows in almost 10 years (switched to GNU/Linux and couldn't never wanted to back).  About the prompt, if you actually see a "$" prompt then I guess you're right that "$" might refer to this prompt.  The "$" classically indicates the bash shell on *nix these days because the other famous shells have a different character at the prompt (cshell uses %, IIRC).
newbie
Activity: 13
Merit: 2
I can answer the last part.  "npm" is node package manager.  I'm using GNU/Linux, and after installing node/npm through the normal package manager on my system (apt-get), I use npm commands to install further node packages.

The "$" might refer to a bash prompt, which would be something "unix related" Smiley  But it might stand for the jquery object $.  Depending on the context.   If your examples all start:

$ npm ...

Then it's referring to the bash prompt on a unix-like system (OSX, GNU/Linux, etc).
OK thanks. Well I'm using Windows only, but apparently, after running the NodeJS installer for Windows, when opening a command prompt and going to the NodeJS program directory, I can magically perform npm commands from there. So it seems the $ in this case also refers to the Windows command prompt.

However, I wonder if some Windows-incompatibilities of NodeJS or npm may be the cause of the strange issues I'm getting with the bitcoinjs.min.js I built myself...?
legendary
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
I'm trying to use BitcoinJS in a Bitcoin-related website. However, it seems to be written with node.js in mind, whereas I am just building a normal Html5 site.

Normally I just include a 3rd party javascript lib in my own page, and use it from there. However, this BitcoinJS lib has "require()" all over the place, and require.js doesn't help as it also contains references to other (external) stuff, like require('assert') or require('crypto-js') etc, which I assume are node.js specific modules or something.

How do I deal with this? The getting started instructions at bitcoinjs.org seem to involve "$ npm" but I don't know what $ is (is that from jquery, or something unix related?) nor do I know what "npm" is.

I can answer the last part.  "npm" is node package manager.  I'm using GNU/Linux, and after installing node/npm through the normal package manager on my system (apt-get), I use npm commands to install further node packages.

The "$" might refer to a bash prompt, which would be something "unix related" Smiley  But it might stand for the jquery object $.  Depending on the context.   If your examples all start:

$ npm ...

Then it's referring to the bash prompt on a unix-like system (OSX, GNU/Linux, etc).
newbie
Activity: 13
Merit: 2
Thanks, interesting, I've copied your example html and tried that here in Chrome as well.

Still doesn't work, but Chrome's console shows this error:

Quote from: Chrome JavaScript console
Uncaught ReferenceError: Uint8ClampedArray is not defined
Which makes me wonder, is there anything I need to update or recompile? I would assume that by performing the npm and browserify steps (according to the BitcoinJS website) that I'm getting the latest version of everything, but I'm totally clueless regarding to all this NodeJS stuff Smiley

My previous attempts were done in Firefox (latest version).
newbie
Activity: 3
Merit: 0
My 3rd username for this website (I tend to use captcha as part of my password and end up not remembering it later). My bitcoin.min.js is also around 220kb so most likely you are on the right track. Browser choice is important as bitcoinjs doesn't work with older browser (IE <11?) and Android's WebView. I've tried the following code with Chrome:





My First Web Page



A Paragraph.











newbie
Activity: 13
Merit: 2
Hi,

You can get npm from nodejs website (nodejs.org). You can then install browserify and uglify (also using npm) to help you. If you trust me I can also send you bitcoin.min.js that I generated
That would be cool, yes!

Actually, I messed around with NodeJS a bit further (installing npm and browserify and uglify etc) and I think I now managed to create a bitcoin.min.js on my own. That is, after following the instructions from BitcoinJS.org, the file is now there (about 220Kb).

However, when I try the first example from the BitcoinJS page, it doesn't work. It seems an error occurs right at the first line already, the one with Bitcoin.ECKey.makeRandom(), here is a minimal example .html file:

Code:


And when I open this file:

Quote from: JavaScript Error Console
TypeMismatchError: The type of an object is incompatible with the expected type of the parameter associated to the object
(this occurs in the bitcoinjs.min.js file)

Does it work OK with your bitcoinjs.min.js? If yes, I'm really curious exactly how to create it!
newbie
Activity: 1
Merit: 0
Hi,

You can get npm from nodejs website (nodejs.org). You can then install browserify and uglify (also using npm) to help you. If you trust me I can also send you bitcoin.min.js that I generated
newbie
Activity: 13
Merit: 2
Crypto-JS is a vital part of BitcoinJS. It's basically all the Elliptic Curve calculations.

Without it you wouldn't be able to turn a private key into a public key.

Is the problem that you just don't understand it? or is it that you have some sort of limitation on your site?

If you have a limitation, please specify the limitation in detail, and someone can help you better.

Thanks for the help. I am familiar with Crypto-JS, I've used it before and I see how this is a vital part for BitcoinJS.

My problem is, several .js files in BitcoinJS have a line "require('crypto-js')" which is supposed to include Crypto-JS, but
1. require(...) is some NodeJS-specific construct, and not part of JavaScript.
2. the Crypto-JS library isn't even included in the BitcoinJS code, so I assume it requires some environment or setup where Crypto-JS is already available as some kind of pre-installed library or something.

There are many more require(...) lines, in fact most files require eachother in this way, so other than just the missing Crypto-JS thing I don't even know how to get this JavaScript library working at all.

Basically, what I need is just one big bitcoin.js (or bitcoin.min.js) file that contains everything. Apparently this can be produced with something called "Browserify" but that seems to require NodeJS as well Sad

hero member
Activity: 658
Merit: 500
Hive Wallet is already using bitcoinjs and crypto-js (I think). You could ask them how they used them.
sr. member
Activity: 475
Merit: 252
Crypto-JS is a vital part of BitcoinJS. It's basically all the Elliptic Curve calculations.

Without it you wouldn't be able to turn a private key into a public key.

Is the problem that you just don't understand it? or is it that you have some sort of limitation on your site?

If you have a limitation, please specify the limitation in detail, and someone can help you better.
Pages:
Jump to: