Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node:internal/modules/cjs/loader:936 #23

Open
jsim77 opened this issue Aug 13, 2022 · 2 comments
Open

node:internal/modules/cjs/loader:936 #23

jsim77 opened this issue Aug 13, 2022 · 2 comments

Comments

@jsim77
Copy link

jsim77 commented Aug 13, 2022

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())

  • When I "Run" the above the error prompted as:

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

@libitx
Copy link
Owner

libitx commented Aug 16, 2022

The casts object is exported from the main module. So you use it like this:

const { forgeTx, casts } =require('txforge')

// Get the casts you will use in your transaction
const { P2PKH, OpReturn } = casts

@jsim77
Copy link
Author

jsim77 commented Aug 17, 2022

Thanks for getting back to me along with the solution. I have amended and right now, the new error as the following:

Error: P2PKH unlock must be created with valid 'privkey' as per the screenshot.
Screenshot 2022-08-17 at 1 01 02 PM

Then, I did input the "privkey" from my wallet (saved) and to Run again but the Error message still the same as per the screenshot below:
Screenshot 2022-08-17 at 1 29 09 PM

Does this mean I need to create 'privkey' in a separate coding?

Please advice, thanks so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants