Advanced Bitcoin Scripting - Discussion

And when I run it from the bcoin directory:

internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '/home/mark/multisigproject/bcoin/address.js'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []

Ahh I see, I havenā€™t tried using a globally installed library in node. Can you try if npm link bcoin works?

npm link bcoin

outputs

/home/mark/multisigproject/bcoin/node_modules/bcoin -> /home/mark/.nvm/versions/node/v14.15.3/lib/node_modules/bcoin -> /home/mark/multisigproject/bcoin

but I still get the same errors when I run node address.js

Try creating a node_modules directory and move the bcoin link into that folder.

I just found that there! The bcoin cloned repository has lots of files in it, so Iā€™ve been trying to move the address.js file about to see if it would solve the issue. So, when you told me to try npm link bcoin , the output showed me a path that I hadnā€™t tried yet.

multisigproject/bcoin/node_modules/bcoin

I moved the address.js file to this path and it worked and I now have the two files, regtest-key1.wif and regtest-key2.wif

Thanks again for your help. No doubt youā€™ll be hearing from me soon!! hahaha

1 Like

Just out of curiosity, I deleted the bcoin repo, which I had installed globally and started again from scratch. This time after cloning into the multisigproject directory I only ran npm rebuild and didnt use npm install --global like I did the first time.
However, I had the same problem trying to create the keys. Just putting the address.js file in the node_modules directory did not work. I still had to run npm link bcoin to give me the path multisigproject/bcoin/node_modules/bcoin/address.js .

1 Like

Hey, glad it worked out. We will have to update these instructions soon because its getting a real hassle to help out students because of all the changes in the library :confused:

There are two ways to do this (or many for that matter), you can either include the index.js from bcoin library in your address.js. An easier was is to create a node_modules directory in the multisig project and move the bcoin folder inside this directory, this will force node to look for it when you run node address.js :slight_smile:

If you have any other questions donā€™t hesitate to ask! :smiley:

Cool. Thanks again for your help.

An easier was is to create a node_modules directory in the multisig project and move the bcoin folder inside this directory, this will force node to look for it when you run node address.js

Just for experience, I deleted everything and started over again and tried this but still got errors until I ran npm link bcoin . Iā€™m using Ubuntu 20.04.1. Maybe this is why?

Interesting. But you did got it to work? I only had to rebuild bcoin and it seems to work fine. The OS shouldnā€™t make a difference.

Yeah, It did work. I just tried it out of curiosity after you had mentioned it to me. For me, its a great way to learn rather than just follow along blindly. I feel like I understand more when there are problems and idiosyncrasies.

1 Like

:hammer_and_wrench: Tool Box for Advanced Bitcoin Scripting on Linux :penguin:

  • General remark
    Many thanks for this bonus content! Coding along with Filip was quite interesting, challenging and ā€“ ultimately ā€“ satisfying when everything did run as intended. :smiley:
    It was also very rewarding to read through this forum thread and benefit from all the already solved/documented problems. :tophat::ok_hand: Hat tip to the moderators here as well.
    Because this thread has made my life a lot easier Iā€™ll try to contribute something useful here as wellā€¦

  • Different Linux distributions
    Both seasoned and new Linux users have contributed here and I believe the overlap of blockchain technology with the broader open source community will lead more of them hereā€¦
    So here is a selection of my key insights to make all of this work on both Debian and RedHat related systems:

    In order to use the npm rebuild command on the bcoin code Filip made sure to first have windows-build-tools installed on his Windows box.

    • To make all this work on Debian based systems you
      1. create the subfolder node_modules in your projectā€™s folder and
      2. git clone git://github.com/bitcoin-org/bcoin.git into that.
      3. Now you need to sudo apt install build-essential on your machine before you
      4. go there with cd bcoin/ and
      5. finally run npm build.

      You should be able to use bcoin now.

    • To do this on a system from the RedHat family (e.g. Fedora), however, you should instead of step 3 run sudo dnf grouplist first and find a category that describes something like ā€œdevelopment toolsā€ according to your language settings:


      Then just install that with sudo dnf groupinstall "<name of category>" and continue with step 4 from above.

  • Community-driven, freely-licensed binary distribution of the VSCode editor
    Filip is using Visual Studio Code in his presentation and this is probably one of the best pieces of software to ever come from Microsoft. Fortunately it has been made available for Linux as well.
    Microsoftā€™s VSCode source code is open source (MIT-licensed) but the product available for download is licensed under a not-FLOSS license and contains telemetry/tracking.
    A functionally and visually equivalent version of VSCode without the telemetry and tracking features is available via https://vscodium.com.
    It worked flawlessly to reproduce Filipā€™s setup on my Fedora machine and even supports Vim bindingsā€¦ :nerd_face:


:bulb:Pro Tip: You can open the integrated terminal of VSCodium with Ctrl + Shift + ' to avoid switching between your code editor and the terminal.

2 Likes

Great introduction! :raised_hands: Glad you were able to get through the course without major issues :smiley:
Also for noticing the dual license for Code :stuck_out_tongue: Never heard of vscoduim, Iā€™m using the OSS version (basically a build from GitHub) that provided in Arch packages.

Hello
I need some help I tried to install Bcoin but this is not successfull on windows. I tried with Git and npm install https://github.com/bcoin-org/bcoin

Carlos@LAPTOP-14TAQHNV MINGW64 /e/Importante/Programas creados imagenes iso etc/Bitcoin/multisig
$ git clone git://github.com/bcoin-org/bcoin.git
Cloning into 'bcoin'...
remote: Enumerating objects: 45426, done.
remote: Total 45426 (delta 0), reused 0 (delta 0), pack-reused 45426
Receiving objects: 100% (45426/45426), 30.22 MiB | 333.00 KiB/s, done.
Resolving deltas: 100% (33482/33482), done.
Updating files: 100% (1257/1257), done.

Carlos@LAPTOP-14TAQHNV MINGW64 /e/Importante/Programas creados imagenes iso etc/Bitcoin/multisig
$ cd bcoin

Carlos@LAPTOP-14TAQHNV MINGW64 /e/Importante/Programas creados imagenes iso etc/Bitcoin/multisig/bcoin (master)
$ npm rebuild
npm ERR! code 1
npm ERR! path E:\Importante\Programas creados imagenes iso etc\Bitcoin\multisig\bcoin\node_modules\bcrypto
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | win32 | x64
npm ERR! gyp info find Python using Python version 2.7.15 found at "C:\Users\Carlos\.windows-build-tools\python27\python.exe"
npm ERR! gyp info find VS using VS2017 (15.9.28307.1401) found at:
npm ERR! gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools"
npm ERR! gyp info find VS run with --verbose for detailed information
npm ERR! gyp info spawn C:\Users\Carlos\.windows-build-tools\python27\python.exe
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args   'C:\\Users\\Carlos\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\gyp\\gyp_main.py',
npm ERR! gyp info spawn args   'binding.gyp',
npm ERR! gyp info spawn args   '-f',
npm ERR! gyp info spawn args   'msvs',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'E:\\Importante\\Programas creados imagenes iso etc\\Bitcoin\\multisig\\bcoin\\node_modules\\bcrypto\\build\\config.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\Carlos\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\addon.gypi',
npm ERR! gyp info spawn args   '-I',
npm ERR! gyp info spawn args   'C:\\Users\\Carlos\\AppData\\Local\\node-gyp\\Cache\\14.15.4\\common.gypi',
npm ERR! gyp info spawn args   '-Dlibrary=shared_library',
npm ERR! gyp info spawn args   '-Dvisibility=default',
npm ERR! gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Carlos\\AppData\\Local\\node-gyp\\Cache\\14.15.4',
npm ERR! gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\Carlos\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp',      
npm ERR! gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\Carlos\\\\AppData\\\\Local\\\\node-gyp\\\\Cache\\\\14.15.4\\\\<(target_arch)\\\\node.lib',
npm ERR! gyp info spawn args   '-Dmodule_root_dir=E:\\Importante\\Programas creados imagenes iso etc\\Bitcoin\\multisig\\bcoin\\node_modules\\bcrypto',
npm ERR! gyp info spawn args   '-Dnode_engine=v8',
npm ERR! gyp info spawn args   '--depth=.',
npm ERR! gyp info spawn args   '--no-parallel',
npm ERR! gyp info spawn args   '--generator-output',
npm ERR! gyp info spawn args   'E:\\Importante\\Programas creados imagenes iso etc\\Bitcoin\\multisig\\bcoin\\node_modules\\bcrypto\\build',
npm ERR! gyp info spawn args   '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: C:\Users\Carlos\AppData\Local\node-gyp\Cache\14.15.4\common.gypi not found (cwd: E:\Importante\Programas creados imagenes iso etc\Bitcoin\multisig\bcoin\node_modules\bcrypto) while reading includes of binding.gyp while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack     at ChildProcess.onCpExit (C:\Users\Carlos\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:351:16)
npm ERR! gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
npm ERR! gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:277:12)
npm ERR! gyp ERR! System Windows_NT 10.0.18363
npm ERR! gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Carlos\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd E:\Importante\Programas creados imagenes iso etc\Bitcoin\multisig\bcoin\node_modules\bcrypto
npm ERR! gyp ERR! node -v v14.15.4
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Carlos\AppData\Local\npm-cache\_logs\2021-02-16T02_06_35_980Z-debug.log

Carlos@LAPTOP-14TAQHNV MINGW64 /e/Importante/Programas creados imagenes iso etc/Bitcoin/multisig/bcoin (master)
$ 

Hey, try removing the old ~/.node_gyp folder and run npm install install again and then rebuild. :slight_smile:

1 Like

thanks @Alko89.
I need to removed also my npm folder C:\Users\Carlos\AppData\Roaming\npm and begun from scratch.
Thanks to the forum I managed to run everything.
1.
$ git clone git://github.com/bcoin-org/bcoin.git
$ cd bcoin
$ npm rebuild

2.In my project folder I created node_modules folder and put bcoin folder in it.


thank you very much the course was very entertainment

1 Like

Hey! I happy you made it work and enjoyed the course. :raised_hands: hope you also learned a lot :smiley:

1 Like

Hey! Iā€™m getting this error saying that there is no module called address.js which definitely is saved in the Multisig folder.

C:\Users\enrique\Documents\Code\multisig>node address.js
internal/modules/cjs/loader.js:905
  throw err;
  ^

Error: Cannot find module 'bcoin' 
Require stack:
- C:\Users\enrique\Documents\Code\multisig\address.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:902:15)
    at Function.Module._load (internal/modules/cjs/loader.js:746:27)
    at Module.require (internal/modules/cjs/loader.js:974:19)      
    at require (internal/modules/cjs/helpers.js:92:18)
    at Object.<anonymous> (C:\Users\enrique\Documents\Code\multisig\address.js:1:15)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)    
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'C:\\Users\\enrique\\Documents\\Code\\multisig\\address.js' ]
}

C:\Users\enrique\Documents\Code\multisig>

Any ideas as to what Iā€™m doing wrong?
I reinstalled Node.js but that didnā€™t fix it

1

Also bcoin is there, why is it not working?2

Hey, how did you install bcoin library? There doesnā€™t seem to be any sources there, just some scripts.