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@3.x"></script>
<script src="https://cdn.cosmic.plus/loopcall@1.x"></script>

    <input type="text" id="pubkey" placeholder="Public key">
    <pre id="transfers"></pre>


### Description

This pen makes use of [stellar-sdk](https://stellar.github.io/js-stellar-sdk/) and [@cosmic-plus/loopcall](https://cosmic.plus/#view:js-loopcall) to implement a Lumen distribution explorer that has the genesis account for starting point.

### Concepts

- [Lumen distribution](https://www.stellar.org/foundation/programs): A process that used to have a [clear mandate](https://web.archive.org/web/20190429213554/https://www.stellar.org/about/mandate/).
- [Genesis account](https://stellar.stackexchange.com/a/1123/1351): The first Stellar account, initially holding all Lumens.

### Keypoints

- `GAAZI...CCWN7` is the genesis account. It received 100 billion Lumens at network creation.
- **#transfers** list outgoing payments worth at least one million Lumens.
- Click on **#transfers** destination pubkeys to follow the track.
- `loopcall()` fetches the operation history for **#pubkey** and passes it to `ingest()` on-the-fly.
- `ingest()` filters, formats and displays the records.
- When **#pubkey** changes, `breaker()` returns true & the previous `loopcall()` stops.

### Challenges

- **easy/** Edit this pen to add a **#previous** button that can go back one step at a time until the genesis account. `(1000 GILS)`
- **hard/** Edit this pen to let the user to define **#minAmount**, **#maxAmount**, and **#asset**. `(3000 GILS)`

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

### Documentation

- [@cosmic-plus/loopcall documentation](https://cosmic.plus/#view:js-loopcall)
- [stellar-sdk OperationCallBuilder documentation](https://stellar.github.io/js-stellar-sdk/OperationCallBuilder.html)
- ['Operations for Account' on Stellar laboratory](https://www.stellar.org/laboratory/#explorer?resource=operations&endpoint=for_account&values=eyJhY2NvdW50X2lkIjoiR0FBWkk0VENSM1RZNU9KSENUSkMyQTRRU1k2Q0pXSkg1SUFKVEdLSU4yRVI3TEJOVktPQ0NXTjcifQ%3D%3D&network=public)

### Social

- [Discuss that pen on GalacticTalk](https://galactictalk.org/d/2171-pen-of-the-week-loopcall-lumen-distribution-explorer)
              // $ npm install stellar-sdk @cosmic-plus/loopcall
// const StellarSdk = require("stellar-sdk")
// const loopcall = require("@cosmic-plus/loopcall")
const $ = document.querySelector.bind(document)

/* Configuration */
const horizon = "https://horizon.stellar.org"
const server = new StellarSdk.Server(horizon)
const minAmount = 1000000

/* Core */
function iterateOperations (pubkey, filter, breaker)  {
  const callBuilder = server.operations().forAccount(pubkey)
  loopcall(callBuilder, { filter, breaker })

function matchRecord (record) {
  return record.type === "payment"
    && record.asset_type === "native"
    && record.from === $("#pubkey").value
    && record.amount >= minAmount

/* Interface */
function refresh (pubkey) {
  $("#pubkey").value = pubkey
  $("#transfers").innerHTML = ""
  const breaker = () => pubkey !== $("#pubkey").value
  iterateOperations(pubkey, processRecord, breaker)

function processRecord (record) {
  if (!matchRecord(record)) return
  const destination = makeLink(record.to)
  const date = record.created_at.substr(0, 10)
  const amount = record.amount.split(".")[0]
  const text = ` | ${date} | ${amount}\n`
  const details = document.createTextNode(text)

function makeLink (pubkey) {
  const a = document.createElement("a")
  a.onclick = () => refresh(pubkey)
  a.textContent = pubkey.substr(0, 5) + "..." + pubkey.substr(-5)
  return a

/* Events */
$("#pubkey").oninput = () => refresh ($("#pubkey").value)

/* Init */
🕑 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.