Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                ### Interaction

<script src="https://cdn.cosmic.plus/stellar-sdk"></script>
<script src="https://cdn.cosmic.plus/cosmic-lib@2.x"></script>
<link rel="stylesheet" href="https://cdn.cosmic.plus/cosmic-lib@1.x/cosmic-lib.css">


<form>
  <fieldset><legend>#cosmiclink_description</legend>
    <p id="cosmiclink_description"></p>
  </fieldset>

  <fieldset><legend>#sign</legend>
    <input id="submit" type="button" value="Open in Wallet">
  </fieldset>
</form>
  

### Description

This pen shows how to use `cosmic-lib` to pass an arbitrary transaction request to a compatible user wallet.


### Keypoints

- `#cosmiclink_description` gets automatically updated with the latest _CosmicLink_ description.
- `txParams` accepts the usual StellarSdk transaction parameters, with `source` and `sequence` being optional.
- `txParams` also accepts the following meta parameters: `network`, `callback` and `horizon` (for custom networks only).
- Operations use the same syntax than StellarSdk. For convenience, those syntaxes are also accepted:
  - Memo: `{ type, value }`
  - Asset: `{ code, issuer }`
  - Signer: `{ weight, type, value }`
- You can sign testnet transactions using **Stellar Authenticator guest mode**.

### Challenges

- `[easy]` Edit the transaction request to one that opens a trustline to Cosmic.plus GILS.
- `[hard]` Edit the code to transmit a payment request to the Lobster wallet using SEP-0007.

_Give it a try by editing the code!_


### Documentation

- <a href="https://cosmic.plus/#view:js-cosmic-lib/web/doc/tutorial-10-specs-query.html" target="_blank">CosmicLink specifications</a>
- <a href="https://stellar.github.io/js-stellar-sdk/Operation.html" target="_blank">StellarSdk Operations specification</a>
- [Lobster SEP-0007 support announcement](https://galactictalk.org/d/2047-lobstr-simple-and-secure-stellar-wallet/11)

### Social

- [Discuss that pen on GalacticTalk](https://galactictalk.org/d/2113-pen-of-the-week-cosmic-lib-create-a-transaction-request)
              
            
!

CSS

              
                
              
            
!

JS

              
                // $ npm install cosmic-lib
// const cosmicLib = require("cosmic-lib")
const $ = document.querySelector.bind(document)

/* CosmicLink handler (default) */
cosmicLib.config.page = "https://cosmic.link"

/* Core */

const txParams = {
  network: "test",
  memo: "CosmicLink Demo",
  maxTime: "+3" // Valid for 3 mins
}

const txRequest = new cosmicLib.CosmicLink(txParams)
  .addOperation("setOptions", {
    homeDomain: "Cosmic.plus"
  })

/* Events */

$("#submit").onclick = () => txRequest.open()
              
            
!
999px

Console