Advanced Bitcoin Scripting - Discussion

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:

1 Like

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

Regarding the bonus section of the advanced bitcoin scripting…
Wouldn’t it be more secure to use hardware wallet while generating private keys?
I know you are trying to teach how this all works in regtest but in reality creating private keys in this fashion is a disaster waiting to happen.

1 Like

maybe you could generate keys on a laptop using Linux that never went online.

1 Like

That isn’t practical which is why Hardware wallets are popular.
Also to make sure a machine never goes online is difficult.

1 Like

It’s not that hard to make sure a machine never goes online. But I agree that it is safer to use a hardware wallet to generate keys.

2 Likes

Let’s say you disconnected the computer from your network.
How are you going to download files to it? A USB memory stick or a CD ?
Malicious code can still be transferred to the offline computer via USB.
The differentiator between the two isn’t online VS offline.
Hardware wallets have a very limited interface. You cannot expose the private key from them unless the hardware itself is tempered with. It also has a limited feature which is to sign transactions & that is it.
It simply cannot do anything else unless an unofficial malicious firmware is uploaded to it which is pretty hard to do.

1 Like

you can also generate keys using some Javascript code. you can always type it over. But you make a good point if you copy stuff.

2 Likes

I got problems with bcoin on my Macbook.
I followed the source install from https://bcoin.io/guides/install-mac.html
When I execute: node address.js
at line: const Keyring = bcoin.wallet.WalletKey;
I get the following error:

/Users/aw/dev/bitcoin/bcoin/node_modules/loady/lib/loady.js:123
throw err;
^
Error: Could not locate the bindings file. Tried:

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/build/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/build/Debug/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/build/Release/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/out/Debug/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/Debug/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/out/Release/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/Release/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/build/default/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/compiled/12.14.0/darwin/x64/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/addon-build/release/install-root/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/addon-build/debug/install-root/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/addon-build/default/install-root/leveldown.node

  • /Users/aw/dev/bitcoin/bcoin/node_modules/bdb/lib/binding/node-v72-darwin-x64/leveldown.node

at bindings (/Users/aw/dev/bitcoin/bcoin/node_modules/loady/lib/loady.js:118:15)

Hmm, I can’t find the page you linked to. Have they deleted it?

Did you run npm install in your directory? You could try removing the node_modules file and then re-running npm install.

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 multisigprobject@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\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