Skip to content
A JavaScript implementation of the CosmicLink protocol (bundle)
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

cosmic-lib / DocumentationExamplesContributingChangelog


Licence Dependencies Vulnerabilities Bundle Downloads

cosmic-lib is a JavaScript implementation of the CosmicLink protocol that comes with a few useful additional tools.

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

What are CosmicLinks?

CosmicLinks are normal URL or URI that contains a Stellar transaction encoded in their query. It allows to pass Stellar transaction to any webpage or any software. Here's an example on the website:*

CosmicLinks use a simple syntax that allow to write any arbitrary transaction:

It can be used to pass transaction XDR as well:

While the website provides a convenient way to share transactions over social medias, emails and static documents, any wallet/service can issue or accept CosmicLinks. One big advantage of using queries is that they can be used to pass transactions without having to rely on any particular service.

This is a generalization of tools like Metamask for Ethereum, as it allows any service to communicate with any (compatible) wallet; And users to sign transactions from any service without ever divulging private keys.

The ultimate goal of the CosmicLink protocol is to enable wallet-less applications for Stellar.


Node / Yarn

  • NPM: npm install --save cosmic-lib
  • Yarn: yarn add cosmic-lib

In your script:

const cosmicLib = require("cosmic-lib")
const CosmicLink = cosmicLib.CosmicLink


bower install cosmic-lib

In your HTML pages:

  <script src="./bower_components/stellar-sdk/stellar-sdk.min.js"></script>
  <script src="./bower_components/cosmic-lib/cosmic-lib.js"></script>


  <script src=""></script>
  <script src=""></script>

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

Basic Usage

Create CosmicLinks

New Transaction

The transaction builder is similar to the one provided by StellarSdk. Additionally, it accepts federated addresses and offer syntactic sugar for memos, dates and assets.

const cosmicLink = new CosmicLink({ network: 'test', memo: 'Demo', maxTime: '2019-01' })
  .addOperation('payment', { destination: 'tips*', amount: 10 }) // XLM is implied
  .addOperation('changeTrust', { asset: 'CNY:admin*' }) // Max limit is implied

From an Existing Transaction

  • From a StellarSdk Transaction: new CosmicLink(transaction, { network: "public" | "test" | passphrase })
  • From an XDR: new CosmicLink(xdr, { network: "public" | "test" | passphrase })
  • From a CosmicLink URI/query: new CosmicLink(uri|query)
  • From a SEP-0007 link: new CosmicLink(sep7)

Edit a CosmicLink

  • Change transaction fields: cosmicLink.setTxFields(parameters)
  • Add operation: cosmicLink.addOperation(name, parameters)
  • Set operation: cosmicLink.setOperation(index, name, parameters)
  • Remove operation: cosmicLink.setOperation(index, null)


  .setTxFields({ memo: "newMemo", source: null, sequence: null })
  .addOperation("manageData", { name: "foo", value: "bar" })
  .setOperation(1, "mergeAccount", { destination: "in*" })
  .setOperation(0, null)

Get the Link

  • Get the HTML link element: cosmicLink.htmlLink
  • Get the URI: cosmicLink.uri
  • Get the query: cosmicLink.query

If your webpage contains an HTML link element with id="cosmiclink", it will automatically get updated with the latest CosmicLink URI.

Display the Transaction

You'll probably want to load the StyleSheet for cosmic-lib first:

await cosmicLib.load.styles()

Then, you can get the HTML description element at: cosmicLink.htmlDescription.

If your webpage contains an HTML element with id="cosmiclink_description", it will automatically get updated with the latest CosmicLink description.

Formats conversion

console.log(cosmicLink.tdesc) // The most convenient format to manipulate transactions

// Lock CosmicLink to a network & a source account to compute its Transaction & XDR.
await cosmicLink.lock()

Note: If you parsed CosmicLink from an XDR/Transaction/SEP-0007 link you don't need to use cosmicLink.lock() for conversion purpose.

Sign & Send the Transaction

// Lock CosmicLink to a network & a source account to fetch signers data.
await cosmicLink.lock()
cosmicLink.sign(...(keypair | preimage))
await cosmicLink.send()

Note: the transaction will automatically be transmitted to StellarGuard when relevant.

Global Configuration

 * Fallback network for network-less transaction requests.
 * @default "public"
 */ = "test"

 * Fallback account for source-less transaction requests.
 * @default undefined
cosmicLib.config.source = "tips*" // Undefined by default

 * Base URL to use when building CosmicLinks.
 * @default ""
 */ = ""

Advanced configuration

Setting the Horizon node for a given network:

cosmicLib.config.setupNetwork("test", "")

Adding a custom network:


Other Utilities

cosmic-lib exposes part of its underlying code as additional modules.


  • Get the Server object for a network cosmicLib.resolve.server("public" | "test" | passphrase)
  • Resolve a federated address: await cosmicLib.resolve.address("tips*")
  • Resolve an account: await cosmicLib.resolve.account("tips*")
  • Resolve transaction signers list: await cosmicLib.resolve.txSignersList(transaction)

Signers Utils

Extends a StellarSdk Transaction object with convenient multi-signature utilities:


Additional ressources


cosmic-lib packs more that showed in this brief presentation. Please take a look at the manual:

Related tools

Related articles

Services that uses CosmicLinks


Organization: | @GitHub | @NPM

Follow: Reddit | Twitter | Medium | Codepen

Talk: Telegram | Keybase

You can’t perform that action at this time.