diff --git a/packages/jellyfish-api-core/src/category/rawtx.ts b/packages/jellyfish-api-core/src/category/rawtx.ts index fcfcde770c..61703aa522 100644 --- a/packages/jellyfish-api-core/src/category/rawtx.ts +++ b/packages/jellyfish-api-core/src/category/rawtx.ts @@ -20,10 +20,8 @@ export class RawTx { } /** - * Create a transaction spending the given inputs and creating new outputs. - * Returns hex-encoded raw transaction. - * Note that the transaction's inputs are not signed, and - * it is not stored in the wallet or transmitted to the network. + * Create a transaction spending the given inputs and creating new outputs that returns a hex-encoded raw transaction. + * Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network. * * @param {CreateRawTxIn[]} inputs array of inputs * @param {CreateRawTxOut[]} outputs array with outputs @@ -45,11 +43,9 @@ export class RawTx { } /** - * Sign inputs for raw transaction (serialized, hex-encoded). - * The second argument is an array of base58-encoded private - * keys that will be the only keys used to sign the transaction. - * The third optional argument (may be null) is an array of previous transaction outputs that - * this transaction depends on but may not yet be in the block chain. + * Sign inputs for raw transaction (serialized, hex-encoded), Providing an array of base58-encoded private keys that + * will be the keys used to sign the transaction. An optional array of previous transaction outputs that this + * transaction depends on but may not yet be in the blockchain. * * @param {string} rawTx unsigned raw transaction * @param {string[]} privKeys array of base58-encoded private keys for signing (WIF) @@ -72,7 +68,8 @@ export class RawTx { /** * Returns result of mempool acceptance tests indicating if raw transaction would be accepted by mempool. - * This checks if the transaction violates the consensus or policy rules. + * This checks if the transaction violates the consensus or policy rules. The fee rate is expressed is DFI/kB, + * using the vSize of the transaction. * * @param {string} signedTx signed raw transaction * @param {BigNumber} maxFeeRate Reject transactions whose fee rate is higher than the specified value. in DFI/kB @@ -89,10 +86,9 @@ export class RawTx { } /** - * Submit a raw transaction (serialized, hex-encoded) to connected node and network. - * Note that the transaction will be sent unconditionally to all peers, so using this - * for manual rebroadcast may degrade privacy by leaking the transaction's origin, as - * nodes will normally not rebroadcast non-wallet transactions already in their mempool. + * Submit a raw transaction (serialized, hex-encoded) to the connected node and network. The transaction will be sent + * unconditionally to all peers, so using this for manual rebroadcast may degrade privacy by leaking the transaction's + * origin, as nodes will normally not rebroadcast non-wallet transactions already in their mempool. * * @param {string} signedTx signed raw transaction * @param {BigNumber} maxFeeRate Reject transactions whose fee rate is higher than the specified value. in DFI/kB diff --git a/website/docs/jellyfish/api/rawtx.md b/website/docs/jellyfish/api/rawtx.md new file mode 100644 index 0000000000..1bbaa0c69d --- /dev/null +++ b/website/docs/jellyfish/api/rawtx.md @@ -0,0 +1,121 @@ +--- +id: rawtx +title: Raw Transaction API +sidebar_label: RawTx API +slug: /jellyfish/api/rawtx +--- + +```js +import {Client} from '@defichain/jellyfish' +const client = new Client() + +// Using client.rawtx. +const something = await client.rawtx.method() +``` + +## createRawTransaction + +Create a transaction spending the given inputs and creating new outputs that returns a hex-encoded raw transaction. +Note that the transaction's inputs are not signed, and it is not stored in the wallet or transmitted to the network. + +```ts title="client.rawtx.createRawTransaction()" +interface rawtx { + createRawTransaction ( + inputs: CreateRawTxIn[], + outputs: CreateRawTxOut, + options: CreateRawTxOptions = {} + ): Promise +} + +interface CreateRawTxOptions { + locktime?: number + replaceable?: boolean +} + +interface CreateRawTxIn { + txid: string + vout: number + sequence?: number +} + +interface CreateRawTxOut { + [address: string]: BigNumber +} +``` + + +## signRawTransactionWithKey + +Sign inputs for raw transaction (serialized, hex-encoded), Providing an array of base58-encoded private keys that will +be the keys used to sign the transaction. An optional array of previous transaction outputs that this transaction +depends on but may not yet be in the blockchain. + +```ts title="client.rawtx.signRawTransactionWithKey()" +interface rawtx { + signRawTransactionWithKey ( + rawTx: string, + privKeys: string[], + prevTxs?: SignRawTxWithKeyPrevTx[], + options: SignRawTxWithKeyOptions = {} + ): Promise +} + +interface SignRawTxWithKeyPrevTx { + txid: string + vout: number + scriptPubKey: string + redeemScript?: string + witnessScript?: string + amount?: BigNumber +} + +interface SignRawTxWithKeyOptions { + sigHashType?: SigHashType +} + +enum SigHashType { + ALL = 'ALL', + NONE = 'NONE', + SINGLE = 'SINGLE', + ALL_ANYONECANPAY = 'ALL|ANYONECANPAY', + NONE_ANYONECANPAY = 'NONE|ANYONECANPAY', + SINGLE_ANYONECANPAY = 'SINGLE|ANYONECANPAY', +} +``` + +## testMempoolAccept + +Returns result of mempool acceptance tests indicating if raw transaction would be accepted by mempool. +This checks if the transaction violates the consensus or policy rules. The fee rate is expressed is DFI/kB, using the +vSize of the transaction. + +```ts title="client.rawtx.testMempoolAccept()" +interface rawtx { + testMempoolAccept ( + signedTx: string, + maxFeeRate: BigNumber = new BigNumber('0') + ): Promise +} + +interface TestMempoolAcceptResult { + txid: string + allowed: boolean + 'reject-reason'?: string +} + +``` + +## sendRawTransaction + +Submit a raw transaction (serialized, hex-encoded) to the connected node and network. The transaction will be sent +unconditionally to all peers, so using this for manual rebroadcast may degrade privacy by leaking the transaction's +origin, as nodes will normally not rebroadcast non-wallet transactions already in their mempool. + +```ts title="client.rawtx.sendRawTransaction()" +interface rawtx { + sendRawTransaction ( + signedTx: string, + maxFeeRate: BigNumber = new BigNumber('0') + ): Promise +} +``` diff --git a/website/sidebars.js b/website/sidebars.js index d0ee0e9559..f7ac3e13df 100644 --- a/website/sidebars.js +++ b/website/sidebars.js @@ -10,6 +10,7 @@ module.exports = { items: [ 'jellyfish/api/blockchain', 'jellyfish/api/mining', + 'jellyfish/api/rawtx', 'jellyfish/api/wallet' ] }