moneybutton / bsv

Bitcoin SV javascript library
Other
204 stars 107 forks source link

How to find .addData, .from, .to, .change, .sign, .toASM, etc / add ASM data to script / could use more complete documentation #108

Closed andygolay closed 5 years ago

andygolay commented 5 years ago

In the Money Button Docs there's an example of .toASM https://docs.moneybutton.com/docs/ex-op-return.html

but that is in the context of Money Button, not purely BSV.js.

I don't see anything about .toASM or .buildSafeDataOut or really much at all about transactions in the bsv docs, though they are great for keys / mnemonics / addresses and other features.

I attached a screen shot from bitcore-lib docs showing .from, .sign, and .addData methods on the Transaction object

Screen Shot 2019-09-30 at 10 40 40 PM

but when I run bsv.Transaction in the terminal I don't see .addData or .from or .change anywhere, and I'm at a loss for how to use ASM string formats other than using Money Button.

For example, is there some way to just put ASM data directly into a transaction in BSV?

Looking for properties I'm getting

> Object.getOwnPropertyNames(bsv.Transaction) [ 'length', 'name', 'prototype', 'DUST_AMOUNT', 'FEE_SECURITY_MARGIN', 'MAX_MONEY', 'NLOCKTIME_BLOCKHEIGHT_LIMIT', 'NLOCKTIME_MAX_VALUE', 'FEE_PER_KB', 'CHANGE_OUTPUT_MAX_SIZE', 'shallowCopy', 'Input', 'Output', 'UnspentOutput', 'Signature', 'Sighash', 'sighash' ]

and don't see .addData anywhere when I fish around in the properties.

Is there some place within the BSV documentation where you get into bsv.Script.buildSafeDataOut, .addData, or any transaction kung fu? It seems glossed over in the Examples section of the Money Button Docs and not included in the BSV docs.

I don't blame you for the fragmented nature of the docs, it looks like bitcore-lib's docs were also spotty, but it would be good to have more thorough explanations of the different transaction methods, especially not being able to find .addData documented in the BSV docs is kinda bothersome for me.

Specifically, if you know how to add a script to a transaction output, in ASM format, without Money Button, that would be a helpful example to include. Would that be bsv.Script.fromASM?

I could experiment to brute force some of this info, but I can't seem to find addData or .from or .change by scanning the classes.

Unless I'm missing it, it seems like you only mention ASM once in passing in that Examples section which is not even part of the main BSV docs so it would be good to add a Transactions section and get into ASM more, especially, kinda like how they have here, but even this doesn't really explain all the possible methods: https://github.com/bitpay/bitcore-lib/blob/master/docs/transaction.md

Especially strange to me that I can't find .change .addData .from etc properties... I would think that would be under Transaction.Output but maybe I'm suffering from a newbie blind spot.

breavyn commented 5 years ago

That's not really a good way to get the available methods for the transaction. Try Object.keys(bsv.Transaction.prototype)

andygolay commented 5 years ago

Thanks, I appreciate that.