Closed omariosman closed 1 month ago
You are trying to spend single-sig(p2pkh) utxo, but with unlockHashInput
(https://blockstream.info/testnet/tx/abc0354efe91388672b81fa120065b3ad9184f3227c2e3fd672b6b7e9d47f168?expand).
The code example assumes that your input to spend is utxo which is built in a same way of output to send(below one).
// add Target output to send Bitcoin
// sends bitcoin to script with timelock + hashlock (no sig required)
await tx.addOutput({
address: await bitcoin.address.generateScriptAddress(
// if you only want hashlock, you can remove generateTimeLockScript
(await bitcoin.script.generateTimeLockScript(BLOCK_HEIGHT)) +
(await bitcoin.script.generateHashLockScript("abcdef")),
"legacy",
"testnet"
),
value: value - fee, // value of utxo - fee
} as bitcoin.Target);
So after send to the address of above, then try unlockHashInput
.
Thank you so much for clearing up the confusion @ChrisCho-H It worked!
Pleasure :)
The issue
I am trying to create Transaction for TimeLock (or || and) HashLock without Signer(P2SH, P2WSH) However when I try to broadcast the tx to https://blockstream.info/testnet/tx/push it gives me this error: sendrawtransaction RPC error: {"code":-26,"message":"mandatory-script-verify-flag-failed (Script failed an OP_EQUALVERIFY operation)"}
Can you inspect what is wrong with my script?
Tx raw:
010000000168f1479d7e6b2b67fde3c227324f18d93a5b0620a11fb872863891fe4e35c0ab0000000030015103abcdef2903a4bd2db175aa204533a01d26697df306b3380e08f4fae30f488d2985e6449e9bd9bd86849ddbc688fdffffff01d40200000000000017a9145b107712b126b2bedc82ddfd6673c1f946f741d387a4bd2d00
Tx decoded:
Script: