Advanced Bitcoin Scripting - Discussion

Hi,

After struggling for a day, I managed to complete the “Creating Keys” example. For clarification I am not a developer myself, but I am learning. So bear with me if I misnomer something.

Through what I learned today, it seems that in order to run the Bcoin module in Node.js, you need some software on your computer installed.

STEP 1
I suggest you start by downloading and installing all the following software:
As a remark I am noting versions I downloaded at the time of this post; which were the latest available. I also want to state that I am using Windows 10.

Python 3.7 (downloaded from Python website)
Node.js v12.19.0 (downloaded from Node.js website)
NPM v6.14.8 (included in Node.js)
git version 2.28.0.windows.1 (downloaded from this site https://git-scm.com/ )
Microsoft Visual Studio Community 2019 Version 16.7.6, installed with the Desktop C++ “workload”

Restart your computer after all this software installation.

STEP 2
I found through trial and error that the module that helps you install the Bcoin module, need NPM to know how to access to the python software. Therefore you have to configure it. I found this information here: https://github.com/nodejs/node-gyp, if you would like to reference yourself.
Using the Powershell you will configure your NPM to the python program executable with the command below:

npm config set python “C:\locationinyourcomputer\Python 3.7 (64-bit).lnk”

In Windows 10 you can find the python executable location just by typing “Python” and right-click open file location…

STEP 3
Follow Filip’s steps to create the folder directory “multisigproject” and run the “npm init” code from powershell in that directory.

STEP 4
Being in the “multisigproject” directory, in powershell run the command:

npm install bcoin

The powershell is going to think for a while and it is very likely you will get an error at the end. However, this expected, and what is important is that it would have created a new directory called “node-modules”

STEP 5
Move into the new “node-modules” directory, and now you will install Bcoin, but instead of using NPM call, you will use git. I found this procedure in this link: https://github.com/bcoin-org/bcoin/blob/master/docs/getting-started.md) In fact, in there you can read the following statement: “Bcoin is meant to be installed via Git for security purposes, as there are security issues when installing via npm.” The command will be as follows:

git clone git://github.com/bcoin-org/bcoin.git

Once powershell has finished whatever it downloaded, a new folder will appear inside “node-modules”. This new folder is the “bcoin” module. You will have to now go into the new “bcoin” directory.

cd bcoin

Once Inside that directory, in the powershell run the following command:

npm rebuild

STEP 6
At this point I think ‘bcoin’ module is properly installed. You can then proceed to create the “address.js” as instructed by Filip and move on with the class.

Please like and let me know if you tried this and it helped. I am not sure if I missed steps, remember I spent almost an entire day digging this and I am not a developer.

3 Likes

Hey thanks a lot I have tried your method of getting bcoin working using git and can confirm it also works on latest versions of node! :smiley: Great job figuring this out! :raised_hands:

I’m working on Linux and have most of these stuff preinstalled (like Python and build tools). I know that setting things to work on Windows is tough because it is not really suitable for development. But we have to get around it because we are aware most users are using it and have to support them as well :slight_smile:

Would you mind posting your findings in FAQ category? :slight_smile:

2 Likes

Hey @dcota, hope you are great!

Thank your for this little guideline for bcoin, this can be very helpful to other students, but your post could get lost if you leave it here.

So if you want to reach the entire community, i could suggest to copy/paste it here: FAQ

If you have more questions, please let us know so we can help you :nerd_face:

Carlos Z.

2 Likes

Hi,

In Filip’s exercise Video: “Part 6 - Create 1st Signature”, I found that the following piece of code gives an error.

tx.addOutput({
address: ‘RF1PJ1VkHG6H9dwoE2k19a5aigWcWr6Lsu’,
value: Amount.fromBTC(‘50’).toValue()
});

I know this section of the code is the problem with certainty because I added dummy console prints through out the code to see where it was failing. I also removed that part of the code and everything ran ok.

console.log(‘code-test-area-X’);

Now, when the previously mentioned piece of code is there, the error that prints into powershell is:

C:\Users\Dcota\multisigproject\node_modules\bcoin\lib\protocol\network.js:235
throw new Error(Network not found for ${name}.);

It seems to me that the address provided in the exercise is not recognized or that somewhere I need to specify to what network this address belongs. “RF1PJ1VkHG6H9dwoE2k19a5aigWcWr6Lsu”

Please advise.

Thank you!

I have replicated your error and it seems to be a bug in bcoin source code for not interpreting the regtest address correctly.

I have opened an issue in their repo: https://github.com/bcoin-org/bcoin/issues/1002

2 Likes

Hey @Alko89, I saw the response in Github. It seems like the addresses starting with “R…” are no longer applicable. To move one with the class exercise, what address should we put in place?

I separated this post from my last, just to keep posts “clean”, since this is a separate question.

So far I am understanding that Bcoin module in Node.js is an alternative to running the “standard” Bitcoin-qt software package.

However, Bcoin (Node.js) allows you to interact “more easily” with the Bitcoin protocol using javascript.
Now, when I am running the scripts in powershell using Bcoin(node.js) am I actually interacting with the actual “Bitcoind.exe” software or am I just simply running scripts (“hello-world-type”)?

In the first lessons it seemed like we had to “jump-start” a “regtest” using Bcoind, but now with Bcoin(node.js) we don’t. Unless all is secretly happening in the background with Bcoin(node.js).

I assume Bitcoin(node.js) does have a way to deploy a node, and from what I can read it, it is a powerful tool? that expands capabilities to interact with the Web and so forth. Is there a further course on this?

Please let me know if I am assuming the right things. Thank you!

Bcoin is a library to create transactions and doesn’t require a running node, we were just using regtest addresses and these are not supported anymore because they switched to bech32 addresses.
It also contains a daemon you can run, but you can use bitcoind as well.

One thing you can do is to go to your node and send some funds to the addresses you generated with address.js.
Then you can use the transaction id you got in the txInfo and generate an output address.

I created these two in bitcoind, you can replace them with your own in both cases you will be able to construct a tx, but if you use my values you won’t be able to sent them to your network

txid: 7e8f41f9762095be300505d9a864fef44f5d11e29aa3e1dfb078271270044db1
address: bcrt1qsv0eakq6j7785gjtvqacvwpeu4svc0zza7kecr
changeAddress: bcrt1qjrteh4yns38heymd49w72rwhy2nh24phs862ly

If you use your values then you can for fun try to print the raw transaction you got using bcoin using tx.toRaw().toString('hex')

and then you can send this raw transaction to your node using bitcoin-cli

bitcoin-cli -regtest sendrawtransaction <RAWTRANSACTION>

You must have your bitcoind running in another terminal, then you create a block and the transaction will get mined :slight_smile:

I’m sorry for the inconvenience, blockchain is a fast evolving technology and things brake quite fast. I will write the updated instructions in FAQ, but it will take quite a while before we will be able to re-record the videos I imagine :confused: we have a lot of work in the backlog.

1 Like

Even after running npm install bcoin as an administrator, I get the follwoing errors:

gyp ERR! build error
gyp ERR! stack Error: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\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:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:315:20)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:277: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\jorti\multisigproject\node_modules\leveldown
gyp ERR! node -v v14.15.0
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.

@Alko89 … I am using windows only because filip explitly told us to use it in the previous section. Howeverm I tried to install bitcoind in ubuntu, and I could only make bitcoin-qt to work, I didnt find bitcoin-cli nor bitcoind … could you please point me in the right direction to make these 2 things work in ubuntu? Iam also trying to learn how things work with ubuntu and would be very greatful

Personally for me its better if you’re using Linux. :slight_smile:

Bcoin doesn’t work with npm anymore, you will have to clone the repo manually in your project.
You can do this by running

$ git clone git://github.com/bcoin-org/bcoin.git
$ cd bcoin
$ npm rebuild

You will then be able to follow the course normally.
Another issue is that regtest now uses new addresses so the ones in the video will not work and will throw errors. I recommend you use the ones you generated with bitcoin-cli

https://github.com/bcoin-org/bcoin/blob/master/docs/getting-started.md#installing-via-git

@dcota Thanks bro!!1 Im also not a developer (trying to learn by the way, at age 37) … now let´s see if i can get on with the class

@alko89 hey man, dont you think it would be better to uppdate the course? I think a lot of questions here are about the same issue :grimacing: my professional plan allows me to make some critisism :money_mouth_face:

hi, I have a doubt… from part 5 - creating the input video:

When you are defining the txInfo object, you failed to mention where does the hash value come from… you just pasted it from nowhere :crazy_face:

const txInfo = {
value: Amount.fromBTC(‘100’).toValue,
hash: ‘’,
index: 0
}

We will update the course eventually, atm we have a lot of things in the backlog but are working on it. Its is difficult because blockchain technology evolves so fast and videos soon get outdated and we can’t redo the entire course every half a year. :slight_smile: I am really sorry for the inconvenience.

In the transaction info you use the id of the previous transaction. :slight_smile:

2 Likes

where is the file npm to download??

npm package is installed together with nodejs

1 Like

HI filip, Is there a recommended version of nodejs to use for this section of the course in December 2020?
I’m currently using Centos8, with nodejs v10.21.0 and npm v6.14.4 installed.
I have streams 12 and 14 also available on my module list.
Thanks in advance

Hey, you shouldn’t have issues with it. In case you do encounter them I recommend you use the LTS version. :slight_smile:

Thanks Alko, I’ll do that!