Advanced Bitcoin Scripting - Discussion

Fixed it. Added the missing video. That new video became the real part 5. So the part numbers have changed.

Not sure if this is the place to leave feedback but I just want to say a big thank you, and I really enjoyed the course and I’m looking forward to the next one! I know it’s a lot of work but to make it a little bit more interactive, it would be nice to have some quizzes or coding exercises, a bit like in the smart contract programming course :slightly_smiling_face:

1 Like

Thank you very much. I appreciate the feedback :slight_smile:

1 Like

flip,

How are UTXOs collected to create a transaction? If I want to send .5 BTC and have a number of small UTXOs that sum to a value greater than .5 and another UTXO with a value of .6 BTC, will the smaller UTXOs be combined first to reduce the overall number of them or select the single .6 BTC UTXOto create the output?

That’s a good but difficult question. The short answer is that it can be done in many different ways and it’s up to the wallet that you use to choose to decide this. For example, I just did a video on my YT channel on how the Wasabi wallet structures UTXOs to maximize privacy.

The long answer is that you have to make tradeoffs when you choose how to pick UTXOs. Here is a good blog posts about all of this: https://medium.com/@lopp/the-challenges-of-optimizing-unspent-output-selection-a3e5d05d13ef

1 Like

Thanks Filip. Interesting article. Had thought about a couple of items and the remainder were interesting. Looking forward to class update.

1 Like

@filip - great course …much appreciated to you plus Ivan, Regards, Paul

1 Like

When I want to “npm i bcoin” on my Windows 10 mashine I get the following error(s):

> leveldown@4.0.1 install E:\OneDrive\no-excuses\nick\Entwicklungsumgebung\blockchain\test4\node_modules\leveldown
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=11.15.0 runtime=node arch=x64 platform=win32)

E:\OneDrive\no-excuses\nick\Entwicklungsumgebung\blockchain\test4\node_modules\leveldown>if not defined npm_config_node_gyp (node "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Traceback (most recent call last):
  File "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 16, in <module>
    sys.exit(gyp.script_main())
  File "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\gyp\pylib/gyp/__init__.py", line 545, in script_main
    return main(sys.argv[1:])
  File "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\gyp\pylib/gyp/__init__.py", line 538, in main
    return gyp_main(args)
  File "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\gyp\pylib/gyp/__init__.py", line 514, in gyp_main
    options.duplicate_basename_check)
  File "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\gyp\pylib/gyp/__init__.py", line 98, in Load
    generator.CalculateVariables(default_variables, params)
  File "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\gyp\pylib/gyp/generator/msvs.py", line 1916, in CalculateVariables
    generator_flags.get('msvs_version', 'auto'))
  File "C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\gyp\pylib/gyp/MSVSVersion.py", line 434, in SelectVisualStudioVersion
    versions = _DetectVisualStudioVersions(version_map[version], 'e' in version)
KeyError: '2019'
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Users\Nick\AppData\Roaming\nvm\v11.15.0\node_modules\npm\node_modules\node-gyp\lib\configure.js:345:16)
gyp ERR! stack     at ChildProcess.emit (events.js:193:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:255:12)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\Nick\\AppData\\Roaming\\nvm\\v11.15.0\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd E:\OneDrive\no-excuses\nick\Entwicklungsumgebung\blockchain\test4\node_modules\leveldown
gyp ERR! node -v v11.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN test4@1.0.0 No description
npm WARN test4@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! leveldown@4.0.1 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the leveldown@4.0.1 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\Nick\AppData\Roaming\npm-cache\_logs\2019-10-06T16_35_44_348Z-debug.log

I also tried…

  • the newest versions of node and npm.
  • deleteing node_modules and run npm install again
  • reinstalled python 2.7
  • installed visual studio 2019 with the C++ extension for C++ compiler
  • using power shell as admin all the time
  • reinstalling node-gyp a few times

I am now using node 11 because one of the errors says

npm ERR! leveldown@4.0.1 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1

In the docs of leveldown they say:

If you get compilation errors on Node.js 12, please ensure you have leveldown >= 5. This can be checked by running npm ls leveldown.

The newest versions of leveldown and node did not work for me…
So I installed nvm-windows to manage the version of node and leveldown to try a combination that works. But it did not for me…

I am looking forward to your answers and thanks.

Hmmm, good question. I did some googling, as I’m sure you have too, and found this: https://github.com/nodejs/node-gyp/issues/809.

There are a lot of different solutions there that worked for different people. You can try some of them. Many people got it to work by making sure they have no spaces in their filepath, deleting the .node-gyp folder and then restarting the computer.

Let me know if any of it works.

1 Like

Hi Filip,

U are teh man, bro :rocket:

These steps helped me to solve my issue:

  • use node 11.10.0
  • went to …/AppData/Roaming/nvm/v11.10.0/node_modules/npm/node_modules and deleted the node-gyp folder
  • npm install -g node-gyp@latest
    (this installs node-gyp in AppData/Roaming/nvm/v11.10.0/node_modules/ and NOT in the folder mentioned above)
  • went to my project and deleted node_modules folder as wells as package-lock.json
  • “npm i” in project folder
  • “npm i bcoin” in project folder

Can’t wait to finally finish up this course and start with LN :smiley:

1 Like

NIIIIIIICEEEEE. I’m happy you are able to progress. Good luck :slight_smile:

PS C:> cd .\Users\Utente\multisigproject
PS C:\Users\Utente\multisigproject> npm install bcoin

leveldown@4.0.1 install C:\Users\Utente\multisigproject\node_modules\leveldown
prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=12.13.0 runtime=node arch=ia32 platform=win32)

C:\Users\Utente\multisigproject\node_modules\leveldown>if not defined npm_config_node_gyp (node “C:\Program Files\nodejs
\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\…\node_modules\node-gyp\bin\node-gyp.js” rebuild ) else
(node “C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js” rebuild )
gyp ERR! find Python
gyp ERR! find Python Python is not set from command line or npm configuration
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. (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:302:5)
gyp ERR! stack at ChildProcess.errorhandler (child_process.js:314:5)
gyp ERR! stack at ChildProcess.emit (events.js:210:5)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
gyp ERR! stack at onErrorNT (internal/child_process.js:456:16)
gyp ERR! stack at processTicksAndRejections (internal/process/task_queues.js:80: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\Utente\multisigproject\node_modules\leveldown
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN multisigproject@1.0.0 No description
npm WARN multisigproject@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! leveldown@4.0.1 install: prebuild-install || node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the leveldown@4.0.1 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\Utente\AppData\Roaming\npm-cache_logs\2019-11-19T02_39_31_541Z-debug.log
PS C:\Users\Utente\multisigproject>

I don’t have python installed but node.js…
I kept trying to run this on admin mode but it’s still giving me errors.

What am I doing wrong?

Ok, I think I have found a clue why this isn’t working…First of all, downgrading to node 11.10.0.
I have tried the leveldown command but this is what powershell is telling me:

PS C:\users\utente\multisigproject> npm install -g node@11.10.0

> node@11.10.0 preinstall C:\Users\Utente\AppData\Roaming\npm\node_modules\node
> node installArchSpecificPackage

npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for node-win-x86@11.10.0: wanted {"os":"win32","arch":"x86"} (current: {"os":"win32
","arch":"ia32"})
npm ERR! notsup Valid OS:    win32
npm ERR! notsup Valid Arch:  x86
npm ERR! notsup Actual OS:   win32
npm ERR! notsup Actual Arch: ia32

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Utente\AppData\Roaming\npm-cache\_logs\2019-11-25T16_41_05_454Z-debug.log
internal/modules/cjs/loader.js:797
    throw err;
    ^

Error: Cannot find module 'node-win-x86/package.json'

Could it be because my laptop doesn’t run the X86 architecture? Yes it’s a bit old…

Help please, I am stuck on this…I can’t seem to find anything working, I tried all the steps describe above like deleting folders and try downloading the latest versions but I still get the same messages…

I am going to follow the rest of the course even if I will not be able to repeat the steps on my laptop…@Filip, I need only one piece of advice:

npm ERR! code EBADPLATFORM
npm ERR! notsup Unsupported platform for node-win-x86@11.10.0: wanted {"os":"win32","arch":"x86"} (current: {"os":"win32
","arch":"ia32"})
npm ERR! notsup Valid OS:    win32
npm ERR! notsup Valid Arch:  x86

Could this be the reason why it isn’t working?

Have you tried installing python?

Yes, I have the latest version (Python 3) installed which npm couldn’t locate. As a response to that, I downloaded Python 2 and it finally recognised it. Then it asked me about visual studio with the C++ extensions and I did download the 2017 version with the windows package.

I also had visual studio installed before re downloading it with the packages… I don’t understand why it’s so hard for it to recognize components.

After completing the above steps, this is what I currently get by typing the command “npm install bcoin”:

PS C:\> cd .\Users\Utente\multisigproject
PS C:\Users\Utente\multisigproject> npm install bcoin

> mrmr@0.1.8 install C:\Users\Utente\multisigproject\node_modules\mrmr
> node-gyp rebuild || echo 'Build failed.'


C:\Users\Utente\multisigproject\node_modules\mrmr>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node
_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node
 "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
  File "<string>", line 1
    'from
        ^
SyntaxError: EOL while scanning string literal
gyp: Call to 'python -c 'from __future__ import print_function; import sys; print(sys.byteorder)'' returned exit status
1 while in binding.gyp. while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\configur
e.js:351:16)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
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\Utente\multisigproject\node_modules\mrmr
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
'Build failed.'

> secp256k1@3.5.0 install C:\Users\Utente\multisigproject\node_modules\secp256k1
> npm run rebuild || echo "Secp256k1 bindings compilation fail. Pure JS implementation will be used."


> secp256k1@3.5.0 rebuild C:\Users\Utente\multisigproject\node_modules\secp256k1
> node-gyp rebuild


C:\Users\Utente\multisigproject\node_modules\secp256k1>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs
\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else
(node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Compilazione dei progetti nella soluzione uno alla volta. Per abilitare la compilazione parallela, aggiungere l'opzione
"/m".
  addon.cc
  privatekey.cc```
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files\Microsoft Visual Studio\2017\Community\MSBuild\15.0\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:1
94:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
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\Utente\multisigproject\node_modules\secp256k1
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! secp256k1@3.5.0 rebuild: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the secp256k1@3.5.0 rebuild script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Utente\AppData\Roaming\npm-cache\_logs\2019-11-28T15_29_21_075Z-debug.log
"Secp256k1 bindings compilation fail. Pure JS implementation will be used."

> leveldown@4.0.1 install C:\Users\Utente\multisigproject\node_modules\leveldown
> prebuild-install || node-gyp rebuild

prebuild-install WARN install No prebuilt binaries found (target=12.13.0 runtime=node arch=ia32 platform=win32)

C:\Users\Utente\multisigproject\node_modules\leveldown>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs
\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else
(node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Compilazione dei progetti nella soluzione uno alla volta. Per abilitare la compilazione parallela, aggiungere l'opzione
"/m".
  builder.cc
  db_impl.cc
  db_iter.cc
  filename.cc
  dbformat.cc
  log_reader.cc
  log_writer.cc
  memtable.cc
  repair.cc
  table_cache.cc
  version_edit.cc
  version_set.cc
  write_batch.cc
  memenv.cc
  port_posix_sse.cc
  block.cc
  block_builder.cc
  filter_block.cc
  format.cc
  iterator.cc
  merger.cc
  table.cc
  table_builder.cc
  two_level_iterator.cc
  arena.cc
  bloom.cc
  cache.cc
  coding.cc
  comparator.cc
  crc32c.cc
  env.cc
  filter_policy.cc
  hash.cc
  logging.cc
  options.cc
  status.cc
  port_uv.cc
  env_win.cc
  win_logger.cc
  win_delay_load_hook.cc
  leveldb.vcxproj -> C:\Users\Utente\multisigproject\node_modules\leveldown\build\Release\\leveldb.lib
  snappy-sinksource.cc
  snappy-stubs-internal.cc
  snappy.cc
  win_delay_load_hook.cc
  snappy.vcxproj -> C:\Users\Utente\multisigproject\node_modules\leveldown\build\Release\\snappy.lib
  batch.cc
  batch_async.cc
  c:\users\utente\appdata\local\node-gyp\cache\12.13.0\include\node\v8.h(3402): note: vedere la dichiarazione di 'v8::O
  bject::Set' (compilazione del file di origine ..\src\leveldown_async.cc)
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files\Microsoft Visual Studio\2017\Community\MSBuild\15.0\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:1
94:23)
gyp ERR! stack     at ChildProcess.emit (events.js:210:5)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
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\Utente\multisigproject\node_modules\leveldown
gyp ERR! node -v v12.13.0
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\Utente\multisigproject\package.json'
npm WARN multisigproject No description
npm WARN multisigproject No repository field.
npm WARN multisigproject No README data
npm WARN multisigproject No license field.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! leveldown@4.0.1 install: `prebuild-install || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the leveldown@4.0.1 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\Utente\AppData\Roaming\npm-cache\_logs\2019-11-28T15_32_28_676Z-debug.log
PS C:\Users\Utente\multisigproject>



and to be honest, i had to cut much of the error code it was giving me because it couldn’t even fit the max words allowed here…

Hmm, I’m not sure what’s going on here. Seems like something is deeply wrong with your npm. I would try to completely remove node and npm and then download a new fresh version from node https://nodejs.org/en/.

I’m sorry I don’t have a final solution for you. But this is what I would have done.

1 Like

No worries, It’s very difficult to diagnose this one…I’ve been trying for days now. It could also be that my machine is quite old, either way, I’ll follow your suggestion and try to erase/reinstall everything. In case it doesn’t still work, I’ll just follow the rest of the course with a notepad and a pen :wink:

1 Like

BOOM! SORTED! It turns out that you had a final solution for me…I reinstalled everything from scratch and I’ve beautifully created the 2 private keys… Thanks buddy :wink:

Wow amazing! So glad you managed to solved it!!