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


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


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.


                ### Interaction

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

    <pre id="template"></pre>

    <input id="amount" type="number" step="1" placeholder="Amount (in Lumens)">

    <input id="alice" type="text" placeholder="Public Key or Federated Address">

    <input id="bob" type="text" placeholder="Public Key or Federated Address">

    <input id="submit" type="submit" value="Submit">
    <pre id="cosmiclink_description"></pre>

### Description

This pen fills a contract template with user-entered inputs and uses `cosmic-lib` to build and pass the transaction request to the user's wallet.

### Concepts

- [Stellar Transactions]( commands that modify the Stellar ledger.
- [CosmicLink]( a protocol that passes transaction requests from applications to wallets.

### Keypoints

- By signing this contract, the user sends an equal **#amount** of Lumens to both **#alice** and **#bob**.
- **#alice** and **#bob** are just convenient variable names that can be set to any valid account.
- This kind of transaction is called "contract" because both operations either succeed or fail together. This is also known as _atomic transactions_.
- Strictly speaking, this is not a _smart contract_ yet, but a mere contract that source parties can either sign or reject.
- Nonetheless, this is a solid foundation for more sophisticated constructs.

### Challenges

- **easy/** Change this pen to make **#template** editable.
- **hard/** Edit this pen to have **#bob** opening a trustline for an `XYZ` asset emitted by **#alice**, then have **#alice** sends **#amount** `XYZ` to **#bob**. 

_Give it a try by editing the code, and be the first to post a solution on GalacticTalk!_

### Documentation

- [cosmic-lib documentation](
- [Stellar Multisig]( (for advanced constructs)
- [Stellar Smart Contracts]( (for advanced constructs)

### Social

- [Discuss that pen on GalacticTalk](




                // $ npm install stellar-sdk cosmic-lib
// const cosmicLib = require("cosmic-lib")
const { CosmicLink } = cosmicLib
const $ = document.querySelector.bind(document)

/* Contract Template */
const template = `{
  "network": "test",
  "operations": [{
    "type": "payment",
    "destination": "#alice",
    "amount": "#amount"
  }, {
    "type": "payment",
    "destination": "#bob",
    "amount": "#amount"

/* Logic */
function applyContract (template, parameters) {
  const bindings = Object.entries(parameters)
  const json = fillTemplate(template, bindings)
  const cosmicLink = new CosmicLink(json)

/* Helper */
function fillTemplate (template, bindings) {
  bindings.forEach(([name, value]) => {
    template = template.split(`#${name}`).join(value)
  return template

/* Interface */
$("#template").textContent = template
$("#submit").onclick = event => {
    applyContract(template, {
      amount: $("#amount").value,
      alice: $("#alice").value,
      bob: $("#bob").value