Today we’re releasing a new version of our Bitcoin library, Nimble. This release adds script debugging, reduced fee rates, and block header parsing.

Install it from NPM or from github. If you have any questions or feedback, please reach out in the nimble channel in the Atlantis Slack or open an issue on Github.

We will be integrating it into the Run SDK starting in v0.7. You can try it today on the Run homepage using the browser console.

Benefits

Feature: New evalScript function for debugging scripts

You can now use nimble to debug Bitcoin scripts locally.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
const prevtxHex = '010000000001e8030000000000001976a9141f5a3321324238f2abea3fd26dfb03493d72863188ac00000000'
const txHex = '0100000001e42629cfef2bb6abf66c956acc3f4743ef95a8df168f037839761871fc33fd6e000000006b483045022100b00b7f3261947798d1244aeb242164a90c02602d21d8f4f58a115a1baf850a9202200804ef70bbf487f52689700d4be9c4411529e7eff6e4e416423c3ca39e1790fc412103d28494a378076050badaefedb9a9cfa5f06f79aff4939f1508ebad75b63e0993ffffffff0000000000'

const prevtx = nimble.Transaction.fromHex(prevtxHex)
const tx = nimble.Transaction.fromHex(txHex)
const unlockScript = tx.inputs[0].script
const lockScript = prevtx.outputs[0].script
const vin = 0
const parentSatoshis = prevtx.outputs[0].satoshis

const vm = nimble.functions.evalScript(unlockScript, lockScript, tx, vin, parentSatoshis)

console.log('success:', vm.success)
console.log('error:', vm.error)
console.log('chunks:', vm.chunks)
console.log('stack:', vm.stack)
console.log('stackTrace:', vm.stackTrace)

This outputs

1
2
3
4
5
6
7
8
success: false
error: Error: 'OP_EQUALVERIFY failed"
at F (nimble.browser.min.js:1:62984)
at Object.A.exports [as evalScript] (nimble.browser.min.js:1:67240)
at <anonymous>:1:30
chunks: (7) [{…}, {…}, {…}, {…}, {…}, {…}, {…}]
stack: (2) [Uint8Array(72), Uint8Array(33)]
stackTrace: (6) [Array(3), Array(3), Array(3), Array(3), Array(3), Array(3)]

The return of evalScript is an object with various properties to help debug. The stackTrace property in particular stores an array of [chunk, stack, altStack] where each element is a single step of the script.

Feature: Lower default fee rate to 50 sats/kb

Bitcoin SV nodes are now accepting 50 sats/kb by default. While some miners are accepting rates even lower, we believe it’s best as a default to ensure as many nodes as possible receive your transactions. You can configure this rate lower by setting nimble.feePerKb.

Feature: Use 1-sat outputs in Transaction

Bitcoin SV nodes are now accepting 1-satoshi outputs. We default to that now in the Transaction class for P2PKH outputs. We also removed the calculateDust function because this logic no longer is used in Bitcoin nodes.

Feature: New readBlockHeader() function

For light clients and bitcoin services, we added a function to decode block headers.

1
2
3
4
5
6
7
8
9
const genesisBlock = '0100000000000000000000000000000000000000000000000000000000000000000000003BA3EDFD7A7B12B27AC72C3E67768F617FC81BC3888A51323A9FB8AA4B1E5E4A29AB5F49FFFF001D1DAC2B7C0101000000010000000000000000000000000000000000000000000000000000000000000000FFFFFFFF4D04FFFF001D0104455468652054696D65732030332F4A616E2F32303039204368616E63656C6C6F72206F6E206272696E6B206F66207365636F6E64206261696C6F757420666F722062616E6B73FFFFFFFF0100F2052A01000000434104678AFDB0FE5548271967F1A67130B7105CD6A828E03909A67962E0EA1F61DEB649F6BC3F4CEF38C4F35504E51EC112DE5C384DF7BA0B8D578A4C702B6BF11D5FAC00000000'

const reader = new nimble.classes.BufferReader(nimble.functions.decodeHex(genesisBlock))

const header = nimble.functions.readBlockHeader(reader)
const txCount = nimble.functions.readVarint(reader)
const tx = nimble.functions.readTx(reader)

reader.close()