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

Packages

Add 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 or require. We'll also process your JavaScript with Babel.

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

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.

Editor Settings

Code Indentation

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

Visit your global Editor Settings.

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

<form action="https://cosmic.link">
  <input name="type" type="hidden" value="manageBuyOffer">
  
  <fieldset><legend>#network</legend>
    <input name="network" value="test" readonly>
  </fieldset>
  
  <fieldset><legend>#buying</legend>
    <input name="buying" value="GILS:gils*cosmic.plus" readonly>
  </fieldset>
  
  <fieldset><legend>#price</legend>
    <input name="price" value="20" readonly>
  </fieldset>
  
  <fieldset><legend>#buyAmount</legend>
    <input name="buyAmount" type="number" min="0" step="1" required>
  </fieldset>
  
  <fieldset><legend>#submit</legend>
    <input id="submit" type="submit" value="Submit">
  </fieldset>

</form>
  

### Description

This pen shows how to make an HTML-only widget that buys a token on the distributed exchange. It uses the CosmicLink protocol.

### Concepts

- [Distributed Exchange](https://www.stellar.org/developers/guides/concepts/exchange.html): The decentralized currency exchange embedded into the Stellar protocol.
- [CosmicLink](https://cosmic.plus/#view:js-cosmic-lib/#what-are-cosmiclinks): A protocol that encodes Stellar transactions into URIs.
- [GILS](https://codepen.io/cosmic-plus/full/eYOeoWZ): An asset that rewards people who solve Pen of the Week challenges.

### Keypoints

- The CosmicLink protocol has initially been designed for this exact purpose.
- `GILS:gils*cosmic.plus` means the asset `GILS` emitted by the account `gils*cosmic.plus`.
- You can validate the transaction on testnet by clicking on "Submit" => "Go to Stellar Authenticator" => "Guest Mode" => "Sign & Send".
- For the transaction to succeed, you'll need to [open a trustline](https://codepen.io/cosmic-plus/pen/QWLQLBG?editors=1010#0) first.

### Challenges

- **easy/** Edit this pen to let the user select a network and an asset among a predefined list. Let her pick the price as well.
- **hard/** Add buy-sell radio buttons to let the user choose the trade direction. Make sure to update #price when switching. You'll need to use JavaScript.

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

### Documentation

- [CosmicLink Specifications](https://cosmic.plus/#view:js-cosmic-lib/web/doc/tutorial-10-specs-query.html)
- [List of Operations](https://www.stellar.org/developers/guides/concepts/list-of-operations.html)
- [Stellar Laboratory account viewer](https://www.stellar.org/laboratory/#explorer?resource=accounts&endpoint=single&network=test)

### Social

- [Discuss that pen on GalacticTalk](https://galactictalk.org/d/2141-pen-of-the-week-html-only-sell-token-form)
            
          
!
            
              // Helpers for the hard challenge
const $ = document.querySelector.bind(document)

            
          
!
999px

Console