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!

1 Answer 1

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.

3
  • 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. i.imgur.com/F8PMdmH.png i.imgur.com/1fgdo6U.png Maybe I am entering the wrong path or that is not the .js file required?
    – Robert
    Commented Jun 18, 2018 at 9:29
  • And what is the location of your file?
    – Murch
    Commented Jun 18, 2018 at 23:12
  • This one: i.imgur.com/F8PMdmH.png hash2.js
    – Robert
    Commented Jun 18, 2018 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.