Pen Settings

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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              ### Interaction

<script src="https://cdn.cosmic.plus/stellar-sdk"></script>
<script src="https://cdn.cosmic.plus/cosmic-lib@2.x"></script>

    <select id="network">
      <option value="test" selected>Test</option>
      <option value="public">Public</option>
    <input id="memo" type="text" placeholder="28 chars max.">
    <input id="destination" type="text" placeholder="Pubkey / Federated address">
    <input id="amount" type="number" min="0" placeholder="Amount">
    <input id="submit" type="button" value="Open signing frame">
    <pre id="error"></pre>


### Description

This pen makes use of `cosmic-lib` to create a transfer request that you can sign with your wallet.

### Keypoints

- The payment request accepts a number of optional parameters, such as `memo`, `callback`, `source`, and `asset`.
- **#memo** accepts those type prefixes: `text:`, `base64:`, `id:`, `hash:` & `return:`.
- `asset` syntax is `{code}:{issuer}`, where issuer can be a federated address.
- It is possible to use a custom network by setting `network` to its passphrase and `horizon` to its horizon URL.
- `txRequest.page` can be set to any compatible service, such as _https://stellar-authenticator.org_ or _https://cosmic.plus/js-cosmic-lib/web/demo_.
- `txRequest.open()` optionally accepts a **target** argument: `"frame"`, `"tab"`, `"current"`, or `"sep7"`.

### Challenges

- `[Easy]` Add a **#service** editable selectors with several default options.
- `[Hard]` Add a **#submitSep7** button that builds & transmit the request through the SEP-0007 protocol.

_Give it a try by editing the code!_

### Documentation

- <a href="https://cosmic.plus/#view:js-cosmic-lib/web/doc/CosmicLink.html" target="_blank">CosmicLink documentation</a>
- <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#.payment" target="_blank">StellarSdk payment operation documentation</a>

### Social

- [Discuss that pen on GalacticTalk](https://galactictalk.org/d/2098-pen-of-the-week-cosmic-lib-transfer-request)

              // $ npm install cosmic-lib
// const cosmicLib = require("cosmic-lib")

const $ = document.querySelector.bind(document);
const service = "https://cosmic.link";

/* Core */
function makeTxRequest() {
  return new cosmicLib.CosmicLink({
    network: $("#network").value,
    memo: $("#memo").value || null
  }).addOperation("payment", {
    destination: $("#destination").value,
    amount: $("#amount").value

/* Interface */
function submitTxRequest() {
  const txRequest = makeTxRequest();

  if (!txRequest.status) {
    txRequest.page = service;
  } else {
    const errors = JSON.stringify(txRequest.errors, null, 2);
    $("#error").textContent = errors;

/* Events */
$("#submit").onclick = submitTxRequest;

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.