Bitcoinjs module missing issue

0

I am trying to run this code with node and bitcoinjs-lib but I keep getting missing lib.

Any idea what am I missing?

I am on a Windows Server 2016. I try to create a P2SH address by hashing a redeemScript.

// OP_HASH160 {scriptHash} OP_EQUAL
var bitcoin = require('bitcoinjs-lib')
var bscript = require('../../script')
var types = require('../../types')
var typeforce = require('typeforce')
var OPS = require('bitcoin-ops')

function check (script) {
  var buffer = bscript.compile(script)

  return buffer.length === 23 &&
    buffer[0] === OPS.OP_HASH160 &&
    buffer[1] === 0x14 &&
    buffer[22] === OPS.OP_EQUAL
}
check.toJSON = function () { return 'scriptHash output' }

function encode (scriptHash) {
  typeforce(types.Hash160bit, scriptHash)

  return bscript.compile([OPS.OP_HASH160, e216c9ev2d0drec3xxxxxxxxxxxxxxa3b5576d9176, OPS.OP_EQUAL])
}

function decode (buffer) {
  typeforce(check, buffer)

  return buffer.slice(2, 22)
}

module.exports = {
  check: check,
  decode: decode,
  encode: encode
}

Error is this below, but couldn't find this lib 'script'.

Error: Cannot find module '../../script'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Module.require (module.js:596:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (C:\Program Files\Bitcoin\rob\hash2.js:3:15)
    at Module._compile (module.js:652:30)
    at Object.Module._extensions..js (module.js:663:10)
    at Module.load (module.js:565:32)
    at tryModuleLoad (module.js:505:12)
    at Function.Module._load (module.js:497:3)

Thanks!

RobertH

Posted 2018-06-17T22:59:08.393

Reputation: 151

Answers

1

Your file is in the directory:

…/hash2.js

while the script module is in

…/src/script.js

The relative path between these two would be ./src/script while your file is prescribing to find it in ../../script. Once you correct the relative path, your program should be able to find the module.

Murch

Posted 2018-06-17T22:59:08.393

Reputation: 41 609

I was trying to do that, but the only 'script' I could find is a .js file under the subfolder /src.

Here are some screenshots.

https://i.imgur.com/F8PMdmH.png

https://i.imgur.com/1fgdo6U.png

Maybe I am entering the wrong path or that is not the .js file required?

RobertH 2018-06-18T09:29:49.570

And what is the location of your file?Murch 2018-06-18T23:12:16.030

RobertH 2018-06-18T23:47:13.930