@cosmic-plus/tx-result

1.5.0 • Public • Published

tx-result / ReadmeContributingChangelog

Readme

Licence Dependencies Vulnerabilities Bundle Downloads

Turns Stellar Horizon responses into meaningful descriptions.

(Weekly updates: Reddit, Twitter, Keybase, Telegram)

Introduction

After posting a transaction to the network, most software needs to display comprehensive feedback to the user. This is especially true when an error happens.

This library produces human-readable descriptions for any possible code Stellar Core returns:

const response = await server.submitTransaction(transaction)
const result = new TxResult(response)

Result for successful transactions:

{
 validated: true,
 title: "The transaction has been validated",
 hash: "d89c...007e",
 ledger: 370369,
 offerResults: undefined,
 link: "https://horizon-testnet.stellar.org/transactions/d89c...007e"
}

Note: offerResults is as described in StellarSdk [server.submitTransaction()](https://stellar.github.io/js-stellar-sdk/Server.html#submitTransaction) documentation.

Result for failed transactions:

{
 validated: false,
 title: "The transaction has been rejected",
 errors: [
   "Operation 1: The destination account doesn't exist.",
   "Operation 3: The source does not have enough funds."
 ]
}

Installation

NPM/Yarn

  • NPM: npm install @cosmic-plus/tx-result
  • Yarn: yarn add @cosmic-plus/tx-result

In your script: const txResult = require("@cosmic-plus/tx-result")

Bower

bower install cosmic-plus-tx-result

In your HTML page:

<script src="./bower_components/cosmic-plus-tx-result/tx-result.js"></script>

CDN

In your HTML page:

<script src="https://cdn.cosmic.plus/tx-result@1.x"></script>

Note: For production release it is advised to serve your copy of the library.

Usage

Functions

new TxResult(txResponse)

The TxResult constructor.

Param Type Description
txResponse Object A response returned by StellarSdk server.submitTransaction().

await TxResult.fromPromise(promise) ⇒ TxResult

Returns the TxResult for an unresolved StellarSdk server.submitTransaction() Promise.

Param Type Description
promise Promise An unresolved Horizon response.

TxResult.describeTxCode(code) ⇒ String

Returns a comprehensive description for transaction return code.

See: Transaction possible errors

Param Type Description
code String A Stellar transaction return code.

TxResult.describeOpCode(code) ⇒ String

Returns a comprehensive description for operation return code.

See: Operations possible errors

Param Type Description
code String A Stellar operation return code.

await TxResult.forCosmicLink(cosmicLink) ⇒ TxResult

Submits cosmicLink using cosmicLink.send() then returns its TxResult. The advantage of using this function is that it generates reports for callbacks and StellarGuard submission as well.

Param Type Description
cosmicLink CosmicLink A .lock()ed cosmicLink

Links

Organization: Cosmic.plus | @GitHub | @NPM

Follow: Reddit | Twitter | Medium | Codepen

Talk: Telegram | Keybase

Package Sidebar

Install

npm i @cosmic-plus/tx-result

Weekly Downloads

8

Version

1.5.0

License

MIT

Unpacked Size

34.3 kB

Total Files

10

Last publish

Collaborators

  • misterticot