bitcoinjs / bitcoinjs-lib

A javascript Bitcoin library for node.js and browsers.
MIT License
5.65k stars 2.09k forks source link

Can PSBT be used to create P2FKH output? #1598

Closed mctrivia closed 4 years ago

mctrivia commented 4 years ago

Can PSBT be used to create P2FKH output?

I am looking to create colored coin transaction and need to be able to create 1 of 3 P2FKH transaction.

junderw commented 4 years ago

Yes. addOutput param accepts script or address... so if you just make the Buffer for the P2FKH and put it in the script of the output you're fine.

junderw commented 4 years ago

To make the Buffer just build a Payment object and access its output attribute for the Buffer of the outputScript.

junderw commented 4 years ago

See this example: Notice the first addOutput uses script to pass the embed.output (Which is a Buffer)

https://github.com/bitcoinjs/bitcoinjs-lib/blob/c0718a9f7c41f8235e46e2d015ada2c32021e0c7/test/integration/transactions.spec.ts#L162-L191

junderw commented 4 years ago

The example is kind of bad. an OP_RETURN (embed) should have value: 0 and not 1000

mctrivia commented 4 years ago

Yes an op_return script would be 0. P2FKH wouldn't so for a generic example it is actually very good. Thank you for your help.