libitx / txforge Goto Github PK
View Code? Open in Web Editor NEWModern Bitcoin transaction builder, capable of supporting any non-standard and custom script type.
License: Apache License 2.0
Modern Bitcoin transaction builder, capable of supporting any non-standard and custom script type.
License: Apache License 2.0
I'm using VSCode on p2pkh.js but it seems that the code content itself requires Identification and Function, which is why the code p2pkh.js becomes like this below:
const { forgeTx } =require('txforge')
// We'll use these Casts in our transaction
const casts = () => { P2PKH, OpReturn }
// You'll need UTXOs to fund a transaction. Use the toUTXO
helper to turn
// your UTXO data into the required objects.
const utxo = () => toUTXO({
txid, // utxo transaction id
vout, // utxo output index
satoshis, // utxo amount
script // utxo lock script
})
// Forge a transaction
const P2PKH = () => { P2PKH }
const myPrivateKey = () => { myPrivateKey }
const tx = forgeTx({
inputs: [
function unlock() {
P2PKH.unlock(utxo, { privkey: myPrivateKey })
}
],
outputs: [
function lock() {
P2PKH.lock(5000, { address: '1DBz6V6CmvjZTvfjvWpvvwuM1X7GkRmWEq' }),
OpReturn.lock(0, { data: ['meta', '1DBz6V6CmvjZTvfjvWpvvwuM1X7GkRmWEq', txid] })
}
],
change: { address: '1Nro9WkpaKm9axmcfPVp79dAJU1Gx7VmMZ' }
})
// And behold! Forged by the Gods and found by a King - a transaction is born.
console.log(tx.toHex())
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '/Users/jsjs77/node_modules/@runonbitcoin/nimble/classes/p2pkhs.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
Any solution for the above? Note that my VScode in Mac unable to Import, that's why use "const"
Thanks
Dear Community,
Sorry is me again. I'm referring to - nimble/classes/p2pkh.js
Have solved the first "import" issue that is to replace with - const { forgeTx } =require('txforge') and in the package.json, I've added "module":"true"
Right now, the next line problem is the:
const { P2PKH, OpReturn } =casts
^
ReferenceError: casts is not defined
I did add the word "require" --> const { P2PKH, OpReturn } =require('casts')
then the new error is:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module 'casts'
Require stack:
Question - how to search for "casts" module within nimble?
Kindly refer to the screenshot for your easy reference, thanks.
In some cases the changeScript is not built despite it being set.
Issue appears to be here as length
is undefined on a Script instance. Need to measure length of the binary script.
Line 265 in cdf75db
Dont understand why this works some times but not others. Should fail all the time. Needs more digging.
As per libitx/txpost-js#1, I'll get started on writing a type declaration file for this library.
Dear Community,
I think I need help as I'm quite confused with the @runonbitcoin/nimble and TxForge. Yes, I downloaded TxForge via NPM into my MacBook. I found that there are 2 separate folders --> 1. @runonbitcoin/nimble and 2. TxForge.
As per the instruction after downloading (I'm using VSCode), I open the Nimble folder to "Run" the p2pkh.js but seems that there's an unsolved error, that is, "SyntaxError: The requested module '@runonbitcoin/nimble' does not provide an export named 'default'
import nimble from '@runonbitcoin/nimble'
^^^^^^
The source file of the error comes from ./txforge/src/classes/tape.js:1
Fyi, I did go back to the TxForge folder and then direct locate to src/classes/tape.js:1 --> inside of the code, I did input the following code, export default nimble
import nimble from '@runonbitcoin/nimble'
export default nimble
I did save but when I go back to Nimble/classes/p2pkh.js --> the SyntaxError remains the same.
I'm confused because 2 separate folders are unable to call each other even though I have put the 'export default' code.
Have attached the screenshot for your easy reference.
Hi,
I would like to modify the txforge library but I cannot run any test.
Here is the error:
npm run test
> [email protected] test /home/baobui/txforge
> mocha "test/**/*.test.js" --require esm
/home/baobui/txforge/test/cast.test.js:1
TypeError: Cannot read property 'OpCode' of undefined
at Object.<anonymous> (/home/baobui/txforge/test/cast.test.js:8:17)
at Generator.next (<anonymous>)
at Object.exports.requireOrImport (/home/baobui/txforge/node_modules/mocha/lib/esm-utils.js:42:12)
at Object.exports.loadFilesAsync (/home/baobui/txforge/node_modules/mocha/lib/esm-utils.js:55:34)
at Mocha.loadFilesAsync (/home/baobui/txforge/node_modules/mocha/lib/mocha.js:473:19)
at singleRun (/home/baobui/txforge/node_modules/mocha/lib/cli/run-helpers.js:125:15)
at exports.runMocha (/home/baobui/txforge/node_modules/mocha/lib/cli/run-helpers.js:190:10)
at Object.exports.handler (/home/baobui/txforge/node_modules/mocha/lib/cli/run.js:362:11)
at /home/baobui/txforge/node_modules/yargs/build/index.cjs:443:71
at process.runNextTicks [as _tickCallback] (internal/process/task_queues.js:60:5)
at internal/main/run_main_module.js:17:47
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] test: `mocha "test/**/*.test.js" --require esm`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] test script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/baobui/.npm/_logs/2021-07-06T18_57_31_462Z-debug.log
I tried to run the tests for txforge on both Ubuntu and Windows. Same error!
It seems that there are problems with the bsv library. Is there any special setup that I missed in order to run the tests?
Thanks,
Reports that sometimes the fee gets calculated at 0.499 s/b. Review the fee calculation logic.
Possibly the feeEstimate function is just wrong. Possibly the p2pkh input size is wrong (check sig size).
moneybutton/bsv does not automatically parse a testnet address - it must be explicitly instantiated with Address.Testnet()
.
To support testnet there should be a configuration flag and instantiate from the correct class at the following places:
Sometimes TxForge creates transactions which have their version byte set to 00 rather than 01.
I cannot figure out why (so far).
The function dustThreshold
is currently internal but is actually pretty useful.
Considering exposing utility functions as part of the package.
now we got a
// Assuming the UTXO is a P2PKH input, we can sign it with a KeyPair
forge1
.buld()
.sign({ keyPair })
buld() --> build()
I guess that is a typo.
TypeError: Cannot read property 'OP_RETURN' of undefined at Object. (/workspace/node_modules/txforge/dist/txforge.cjs.js:354:18) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10) at Module.load (internal/modules/cjs/loader.js:977:32) at Function.Module._load (internal/modules/cjs/loader.js:877:14) at Module.require (internal/modules/cjs/loader.js:1019:19) at require (internal/modules/cjs/helpers.js:77:18) at Object. (/workspace/hybrid-server.js:35:19) at Module._compile (internal/modules/cjs/loader.js:1133:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
npm version 0.1.7
PR #7 by @freddiehonohan allowed the hardcoded dust limit to be overridden by the user with a dustLimit
config option. This has been merged but not released yet.
Propose reverting this change and replacing the dust limit constant with a function that is determined by output script size and miner relay fee.
See https://github.com/bitcoin-sv/bitcoin-sv/blob/master/src/primitives/transaction.h#L188-L208 for reference.
Correct function should be:
dustLimit = 3 * (lockingScriptSize + 148) * minRelayTxFee / 1000
Required changes:
rates
config option should include mine and relay figures. User can provide their own rates object straight from minercraft. Care needed to ensure this isn't a breaking change for some.build()
function should calculate the dustLimit for each output programatically - as per function aboveWhich Format must the 'myPrivateKey' be in the example forge Transaction?
I'm currently trying with bsv v2: const privKey = bsv.PrivKey.fromWif(myPrivateKey) but it does not work.
Maybe you could add a "real" privateKey as an example.
Need to add a config attribute that is used in build()
to set the nlocktime value.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.