Advanced Bitcoin Scripting - Discussion

Hi @filip!
I get the following errors. I’ve tried several things like reinstall Node JS (removed all NodeJS and NPM files). install newest MS VS Redistributable version.
I also followed the hints from: https://github.com/nodejs/node-gyp/issues/119
I have execute all command as Admin

Do you have any idea what could happen?
Thanks a lot!

gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:223:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\danie\OneDrive\03_Blockchain\Ivan_On_Tech_Academy\005_Bitcoin_Programming\multisigprobject\node_modules\leveldown
gyp ERR! node -v v12.15.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Admin\AppData\Roaming\npm-cache\_logs\2020-02-06T07_31_31_835Z-debug.log
1 Like

Hmm, so did you try all of the different solutions in the github thread? There seems to be a lot of different solutions for different people :joy: Did you try it in both cmd and powershell?

Here you might find some possible solutions as well: https://github.com/Hashnode/mern-starter/issues/195

1 Like

Hi filip,
thanks for the link - unfortunately it do not work. I’ve tried both cmd and ps. also I’ve tried my other pc - same issue. I will set up a linux machine an will try it later on it - i think on linux it must be much easier :wink:

1 Like

Great instructional filip! this was my first time testing node.js, went very well.

**root@kali:~/bitcoin-source/bitcoin/segment# cat address.js
‘use strict’

const fs = require(‘fs’);
const bcoin = require(‘bcoin’);
const KeyRing = bcoin.wallet.WalletKey;
const Script = bcoin.Script;

//create 2 private keys
const keypair1 = KeyRing.generate(true, ‘main’);

fs.writeFileSync(‘test-key1.wif’, keypair1.toSecret(‘main’) + “\n”);
root@kali:~/bitcoin-source/bitcoin/segment# node address.js
root@kali:~/bitcoin-source/bitcoin/segment# cat test-key1.wif
L3BAHTKN4XhLACCrJ1nqFiqEp7TvppRaKMr1KDuVyGoqEkGdvD6c
root@kali:~/bitcoin-source/bitcoin/segment# bitcoin-cli importprivkey L3BAHTKN4XhLACCrJ1nqFiqEp7TvppRaKMr1KDuVyGoqEkGdvD6c false
root@kali:~/bitcoin-source/bitcoin/segment# **

1 Like

thanks for that little advanced tutorial. what do you suggest to follow on from here @filip and i noticed you didn’t drop the link to the bcoin tutorials. i have bcoin open but not found the tutorials yet.

1 Like

Good job! Depends on what you’re interested in? :slight_smile: This is our last pure Bitcoin course. You could perhaps continue with our lightning course? Or you could continue to play around with bcoin or bitcoind.

Hi @filip,
It was a great tutorial, I learned a lot from it. However, I got a different output when running console.log(tx) in Create 2nd Signature video. Here is what is displayed in my powershell:

MTX {
  version: 1,
  inputs: [
    Input {
      prevout: [Outpoint],
      script: [Script],
      sequence: 4294967295,
      witness: [Witness]
    }
  ],
  outputs: [
    Output { value: 5000000000, script: [Script] },
    Output { value: 4999000000, script: [Script] }
  ],
  locktime: 0,
  mutable: true,
  _hash: null,
  _hhash: null,
  _whash: null,
  _raw: null,
  _size: -1,
  _witness: -1,
  _sigops: -1,
  _hashPrevouts: null,
  _hashSequence: null,
  _hashOutputs: null,
  changeIndex: -1,
  view: CoinView {
    map: Map {
      'ce12a2b31e5702c9223d651139f45d80fea0c6f1f82ba63bc42a2ec87cd11d3b' => [Coins]
    },
    undo: UndoCoins { items: [] }
  }
}

Could you please let me know how to get the same output as yours?
Best,
Tomcio

You mean that you have different addresses on screen than on the course? In case this is what you mean, that’s perfectly normal. Because you would have different private /public keys.
Or you mean different output of btc?

I mean there is no redeem code in my output and whole structure looks different from what was shown in the video. Maybe it’s because I am running a more current version of bcoin?

Hey, Daniel, did you ever get this to work?
I had a similar problem and tried everything I could find, but I noticed my error seemed to be telling me that it was needing to compile some C++ code and was referencing my Visual Studio C++ compiler. First, I made sure I actually had the C++ workload installed in VS but when it still didn’t work, I did “npm config list” and it seemed to be missing an element called msvs_version. I then did “npm config set msvs_version 2017” (I have VS 2017) and it seemed to run right through the bcoin install.

I hope this helps someone, as I spent a lot of time googling around to find it.

@filip, I’m finally getting through the P2SH Multisig example and when I run the program, I don’t get the same type of output as you. I don’t see the scripts, etc. Why are things formatted differently for me? Compare your output in Part 7 - Create 2nd Signature with mine:

node .\transaction.js

MTX {
version: 1,
inputs:
[ Input {
prevout: [Outpoint],
script: [Script],
sequence: 4294967295,
witness: [Witness] } ],
outputs:
[ Output { value: 5000000000, script: [Script] },
Output { value: 4999000000, script: [Script] } ],
locktime: 0,
mutable: true,
_hash: null,
_hhash: null,
_whash: null,
_raw: null,
_size: -1,
_witness: -1,
_sigops: -1,
_hashPrevouts: null,
_hashSequence: null,
_hashOutputs: null,
changeIndex: -1,
view:
CoinView {
map:
Map {
‘ce12a2b31e5702c9223d651139f45d80fea0c6f1f82ba63bc42a2ec87cd11d3b’ => [Coins] },
undo: UndoCoins { items: [] } } }

Where are my scripts?

Thanks.

Hi Samm,
unfortunately not.
Thank you for the hint!

Hey @filip! After I installed nodejs I went to install bcoin. While running powershell as an administrator, but ran into a bunch of errors. the errors are saying I need to install the newest versions of Python.
Please advise,
Michael

Hello sir, please try with

npm install python

that problem appears because you dont have the Python libraries installed on your system.

Hope this work for you! Keep learning! :slight_smile:

Carlos Z,

Hello @thecil,
I went through PowerShell and typed in npm install python…
I received a warn;

PS C:\Windows\system32> npm install python
npm WARN saveError ENOENT: no such file or directory, open 'C:\Windows\system32\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'C:\Windows\system32\package.json'
npm WARN system32 No description
npm WARN system32 No repository field.
npm WARN system32 No README data
npm WARN system32 No license field.

+ [email protected]
added 1 package from 1 contributor and audited 1 package in 1.826s
found 0 vulnerabilities

Yes sir, problem is that you are running the powershell into the C:\Windows\system32> folder, that’s a very sensitive folder for windows file system, you have to avoid it at all cost, now if you have seen the videos, fillips advice to create a folder and then you put there all the files you will be using over the course, i advice the same, try to use it on “Documents” or “Desktop” folder, or any other folder of you choice.

npm WARN saveError ENOENT: no such file or directory, open 'C:\Windows\system32\package.json'

it show the saveError because that’s not the folder that should be using, you have to navigate through the folder that you are using to save all the files used on the course.

Try to run the same command i tell you before and let me know!

Carlos Z.

Hello @thecil,
I thought it was about to work…

PS C:\Users\Michael\multisigproject> npm install bcoin

> [email protected] install C:\Users\Michael\multisigproject\node_modules\mrmr
> node-gyp rebuild


C:\Users\Michael\multisigproject\node_modules\mrmr>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\nod
e_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (nod
e "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find Python
gyp ERR! find Python checking Python explicitly set from command line or npm configuration
gyp ERR! find Python - "--python=" or "npm config get python" is "C:\Users\Michael\Downloads\python-3.8.2.exe"
gyp ERR! find Python - executable path is ""
gyp ERR! find Python - "" could not be run
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python checking if "python2" can be used
gyp ERR! find Python - "python2" is not in PATH or produced an error
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python checking if the py launcher can be used to find Python 2
gyp ERR! find Python - "py.exe" is not in PATH or produced an error
gyp ERR! find Python checking if Python is C:\Python27\python.exe
gyp ERR! find Python - "C:\Python27\python.exe" could not be run
gyp ERR! find Python checking if Python is C:\Python37\python.exe
gyp ERR! find Python - "C:\Python37\python.exe" could not be run
gyp ERR! find Python
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "C:\Path\To\python.exe"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.
js:307:47)
gyp ERR! stack     at PythonFinder.runChecks (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-py
thon.js:136:21)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-
python.js:225:16)
gyp ERR! stack     at PythonFinder.execFileCallback (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\
find-python.js:271:16)
gyp ERR! stack     at exithandler (child_process.js:310:5)
gyp ERR! stack     at ChildProcess.errorhandler (child_process.js:322:5)
gyp ERR! stack     at ChildProcess.emit (events.js:310:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
gyp ERR! stack     at onErrorNT (internal/child_process.js:469:16)
gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:84:21)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node
-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Michael\multisigproject\node_modules\mrmr
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Michael\AppData\Roaming\npm-cache\_logs\2020-05-01T22_58_01_208Z-debug.log
PS C:\Users\Michael\multisigproject> npm install bcoin

> [email protected] install C:\Users\Michael\multisigproject\node_modules\mrmr
> node-gyp rebuild


C:\Users\Michael\multisigproject\node_modules\mrmr>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\nod
e_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (nod
e "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! find Python
gyp ERR! find Python checking Python explicitly set from command line or npm configuration
gyp ERR! find Python - "--python=" or "npm config get python" is "C:\Users\Michael\Downloads\python-3.8.2.exe"
gyp ERR! find Python - executable path is ""
gyp ERR! find Python - "" could not be run
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python checking if "python2" can be used
gyp ERR! find Python - "python2" is not in PATH or produced an error
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python checking if the py launcher can be used to find Python 2
gyp ERR! find Python - "py.exe" is not in PATH or produced an error
gyp ERR! find Python checking if Python is C:\Python27\python.exe
gyp ERR! find Python - "C:\Python27\python.exe" could not be run
gyp ERR! find Python checking if Python is C:\Python37\python.exe
gyp ERR! find Python - "C:\Python37\python.exe" could not be run
gyp ERR! find Python
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="C:\Path\To\python.exe"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "C:\Path\To\python.exe"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python
gyp ERR! configure error
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-python.
js:307:47)
gyp ERR! stack     at PythonFinder.runChecks (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-py
thon.js:136:21)
gyp ERR! stack     at PythonFinder.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\find-
python.js:225:16)
gyp ERR! stack     at PythonFinder.execFileCallback (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\
find-python.js:271:16)
gyp ERR! stack     at exithandler (child_process.js:310:5)
gyp ERR! stack     at ChildProcess.errorhandler (child_process.js:322:5)
gyp ERR! stack     at ChildProcess.emit (events.js:310:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
gyp ERR! stack     at onErrorNT (internal/child_process.js:469:16)
gyp ERR! stack     at processTicksAndRejections (internal/process/task_queues.js:84:21)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node
-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Michael\multisigproject\node_modules\mrmr
gyp ERR! node -v v12.16.3
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok
npm WARN [email protected] No description
npm WARN [email protected] No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Michael\AppData\Roaming\npm-cache\_logs\2020-05-01T23_12_55_802Z-debug.log

python did pop up and asked if I would like to repair it. which I did but then the rest of the err came in

Ok step by step what i have done in order to properly install python and then bcoin, please read them and follow them in the exact order. I know you have done some of the steps, but still i will write them for other fellow students. (so just skip them until the step 7).

Step 1:

Install NodeJS. Exactly the 12.16.3 version. (Actually recommended for most users).

Step 2:

Open power shell with administrative privileges.

Step 3:

Create a folder for multisigproject. Can be created in a folder of your choice,but I recommend “Documents” or “Desktop” folder to avoid any error.

Step 4:

Navigate through your “multisigproject” and then use the npm init command:

npm init

Step 5:

try to install bcoin with

npm install bcoin

You will probably get the message error that python is not installed bla bla bla…

Step 6: (hope this step work for most users, if not, continue with the next step)

try to install python with simple command

npm install python

If it does not show any error, go directly to step 8.

Step 7:

Welcome to hell boys and girls, but trust me, you will get out of here soon!
We have to install all python dependencies with this command:

npm install --global --production windows-build-tools

It will start to install a lot of things and the console will show a lot of things too…

---------- Visual Studio Build Tools ---------- 2020-05-01T21:39:06 : Verbose : Calling SetupEngine.Installer.EvaluateInstallParameters. [channelId: VisualStudio.15.Release, productId: Microsoft.VisualStudio.Product.BuildTools, installationPath: ‘C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools’, languages: ‘en-US’ selectedPackageReferences.length: 13]
BLA BLA BLA…
------------------- Python --------------------
Successfully installed Python 2.7

DO NOT PANIC IF IT LOOKS UNRESPONSIVE OR STUCK, just give it time to install all the proper tools from Visual Studio and Python, yes it could take a long time, i wait almost 1 hour. DO SOME PUSH UPS WHILE WAITING UNTIL IT SHOWS SOMETHING LIKE THIS:

---------- Visual Studio Build Tools ----------
Successfully installed Visual Studio Build Tools.
------------------- Python --------------------
Successfully installed Python 2.7
Now configuring the Visual Studio Build Tools and Python…
All done!
[email protected]
added 144 packages from 98 contributors in 1849.127s

Step 8:

Finally, try to install again the bcoin.

npm install bcoin

After installing it, how do you know that its OK? if you see this message at the end of the console:

[email protected]
added 3 packages from 2 contributors and audited 387 packages in 48.314s
found 0 vulnerabilities

Happy programming! And be proud of yourself that you made it so far! :muscle:
Hope this work for you! Keep learning! :slight_smile:
PD: I did all this steps inside my “multisigproject” folder, i never left it, please try not to.
If anyone have another more easy way…please let us know so i can destroy this!
Here is the proper documentation that i use to install python correctly: node-gyp.

Carlos Z.

3 Likes

Carlos!
You are Amazing!!!
Now I can finally move on!!!
Thank you so much for your time!
ML

1 Like