Skip to content

Instantly share code, notes, and snippets.



Last active Dec 2, 2019
What would you like to do?
Sample code to evaluate bitcoin script using Bitcoin SV Library (bsv)
let bsv = require('bsv')
const slockStr = "OP_2 OP_EQUAL"
const slock = bsv.Script.fromASM(slockStr)
console.log("\nLocking script loaded\n")
const sunlockStr = "OP_2"
const sunlock = bsv.Script.fromASM(sunlockStr)
console.log("\nUnlocking script loaded\n")
const opcode_cnt = slock.chunks.length + sunlock.chunks.length
console.log(opcode_cnt + " opcodes to process ...")
const si = bsv.Script.Interpreter()
const verified = si.verify(sunlock, slock, null, null, bsv.Script.Interpreter.SCRIPT_VERIFY_P2SH |
if (verified) {
console.log("\n\x1b[32m%s\x1b[0m", "True")
} else {
console.log("\n\x1b[31m%s\x1b[0m", "False: " + si.errstr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment