Skip to content

Instantly share code, notes, and snippets.

@0xASK
Last active June 12, 2019 07:46
Show Gist options
  • Save 0xASK/59bf8110ab81b657b262a4d3cabe721b to your computer and use it in GitHub Desktop.
Save 0xASK/59bf8110ab81b657b262a4d3cabe721b to your computer and use it in GitHub Desktop.

Interledger Testnet

Welcome!

It’s awesome that you’re interested in building on the Interledger Protocol (ILP). Here are some resources to get you started and if you have any questions feel free to ask questions over the Interledger gitter chat.

What is the Interledger Protocol (ILP)?

The Interledger Protocol (ILP) is a protocol to send payments between financial ledgers. This means that you can send money between blockchains, banks and any other type of ledger. Payments on the Interledger are composed of thousands to millions of miniscule payments -- the current average payment size on the network is $0.00001. You can thus stream micropayments between currencies, allowing you to build things that were simply impossible to build before. Check out some of ideas at the bottom of this document for inspiration.

How to connect to the interledger network

Set up a local node with moneyd

Moneyd is a daemon that acts as your local access point to the Interledger network, think of it like your home router providing connection to the internet. You can configure your Moneyd to connect to the network using either XRP or Ethereum, depending on which currency you would like to send/receive payments in. To do so, you need to install Moneyd along with the appropriate uplink which connects you to the greater network. The instructions below explain how to connect to the Interledger testnet, and get your XRP/Ethereum accounts funded with testnet money.

Connecting to the Testnet using the XRP Uplink

Before you start, make sure you have Node.js (version 8.9.4 or higher) installed and that you have also set up Node to install modules globally. Now, run the following command to install Moneyd and the XRP uplink:

npm install -g moneyd moneyd-uplink-xrp

Now that you have your local node and uplink installed you’ll be able to connect to the Interledger testnet. You can initialize your new node through running:

moneyd xrp:configure --testnet

Once you’ve run that, you should see that it created a testnet account for you and funded your wallet. To start your local node run:

moneyd xrp:start --testnet

You are now connected to the Interledger testnet! To confirm everything is running properly, let’s send a test payment. Open a new terminal window and enter:

DO NOT WORRY if you get logs that you are not sending and receiving routes. You are running a local moneyd which is not supposed to send or receive routes so all is normal.

npm install -g ilp-spsp

If you're on Linux or Mac run:

ilp-spsp send --receiver ‘$spsp.strata-ilsp-3.com:8084' --amount 100

But if you're on Windows run:

ilp-spsp send --receiver "$spsp.strata-ilsp-3.com:8084" --amount 100

The command above sends a payment to the payment pointer $spsp.strata-ilsp-3.com:8084. A payment pointer is like a user handle. The currency scale is: 10^9 units = 1 XRP. Therefore, the payment above of 100 units is 10^(-7) XRP, which is roughly $0.000001, quite the micropayment! Once you see ‘sent!’ you have successfully sent your first interledger payment, and you are ready to build.

Connecting to the testnet using the Ethereum uplink

Alternatively, if you would like to send an receive payments using Ethereum, you can install the Ethereum uplink. It’s important to note, that the uplink determines the currency that you want to send and receive in. If you send a payment from your Moneyd with an Ethereum uplink to a receiver that has their Moneyd configured with an XRP uplink, you will send the payment in Ethereum and they will receive it in XRP!

With Ethereum, you will have to get your own Kovan testnet account and fund it before using Moneyd. The easiest way to do so is to use Metamask, an Ethereum browser extension for Google Chrome.

  1. Install the Metamask extension here
  2. Walk through the instructions to get set up with an account
  3. When you are set up with an account, you should see an Ethereum account with 0 ETH.
  4. Copy your Ethereum public key from your account and follow the instructions here to fund your account with 1 - 4 Kovan ETH. Make sure you use your public key, and not your private key!

With a funded Ethereum account, you are ready to set up your uplink. The instructions for the Ethereum uplink are very similar to the XRP uplink. First you will need to install node-gyp as a global dependency. Be sure to follow the instructions here for your specific operating system.

You will also need to extract the private key from your testnet account using Metamask. You can do so by clicking on the three dots in the top right, and then clicking Account Details and Export Private Key.

Assuming you have already installed Moneyd and node-gyp, you can just run:

npm install -g moneyd-uplink-eth
moneyd eth:configure --testnet

If the moneyd eth:configure command says that the moneyd-uplink-eth module cannot be found, you will need to rebuild the moneyd-uplink-eth package by running:

# only run this if moneyd eth:configure failed

cd $(npm config get prefix)/lib/node_modules/moneyd-uplink-eth
npm rebuild

Enter the your Ethereum private key when prompted. Then start Moneyd by running:

DEBUG=ilp* moneyd eth:start --testnet

You’ll see:

ilp-plugin-ethereum-client:info Successfully opened new channel for 0.01 eth with account server +0ms

And you’re connected!

Get paid!

In order to get paid over Interledger you’ll need to set up a payment pointer, which is basically the ILP equivalent of an email address. There are two ways to receive money over Interledger. In order to set up your payment pointer run:

npm install -g ilp-spsp-server
ilp-spsp-server --subdomain your-name-here

You should see output confirming your new payment pointer. Other users on the network will now be able to pay you by running:

npm install -g ilp-spsp
ilp-spsp send --receiver ‘$your-name-here.localtunnel.me’ --amount 100

In order to integrate an SPSP payment into your code you can use this repository.

First you’ll need to install the ilp module:

npm install --save ilp

If you get an error because you are missing any modules when you try to run the file, run: npm install <module-name>

Once that is done you can integrate ILP payments into your code. Below is an example of a simple payment function.

'use strict'

const ilp = require('ilp')
const spsp = require('ilp-protocol-spsp')
const debug = require('debug')('ilp-spsp')

// recipient is the payment pointer
// amount is 1 XRP = 10^9 units
async function pay (recipient, amount) {
  try {
    const plugin = ilp.createPlugin()
    debug('connecting plugin')
    await plugin.connect()

    debug('sending payment')
    await spsp.pay(plugin, {
      receiver: recipient,
      sourceAmount: amount
    })
  } catch (e) {
    console.error(e)
    process.exit(1)
  }

  console.log('sent!')
  process.exit(0)
}

// sending 0.0000001 XRP
function run () {
  pay('$spsp.strata-ilsp-3.com:8084', 100)
}

run()

Web Monetization Tutorial

Any site can include Web Monetization. When web monetization is activated, users will begin streaming payments (sending micropayments every second) to the SPSP payment pointer specified by the website. Because these payments are instant, you can handle these payments in your app to give exclusive features or even pay out to other users of your site.

First, you’ll need to enable your browser for web monetization. Read the tutorial below on how to do that. Web Monetization isn’t implemented by the browser, so you’ll need to polyfill it. To do this, include the following <script> tag:

<script src=”https://polyfill.webmonetization.org/polyfill.js”></script>

Web Monetization Scripts has some helpful wrappers to make this API easier to use. Include the script with

<script src=”https://cdn.coil.com/donate.js”></script>

Now call the script with

<script>
    window.WebMonetizationScripts.donate({
        paymentPointer: ‘$spsp.strata-ilsp-3.com:8084’ 
    })
</script>

This will send money continuously to the SPSP pointer that you provide while the user is browsing the page. You can get a payment pointer of your own by running ILP SPSP server. Try running your webpage and you’ll see a counter appear in the corner that continuously ticks up.

Let’s try doing something a little more advanced. We’ll make a message that only displays when the user is paying the site. The donate function returns an object, and we can listen for events to see when payment occured. This gist contains a page that listens for this ‘money’ event and logs a message each time it occurs. Use http-server to host the index.html from the gist.

Visit your page, and you’ll see the message appear every time the browser sends a micropayment. Visit in a private/incognito tab, and neither the payment nor your message will appear. This approach isn’t safe if you want to trigger server-side logic on payment. You can use moneyd and web monetization receiver for these applications. The examples contained within demonstrate how to host paywalled images or even a paywalled video stream.

Web monetization sign up flow

If you would like to use web monetization in your project you’ll need to create an account with Coil to use their Chrome plugin. First, go to coil.com/signup and create a new account. Once you sign in, verify your new account through the email sent to your email address. After clicking the link in the email, download the chrome extension from the coil home page. Sign into the plugin and enter your credit card info. Don’t worry! This is just to make a Coil account, you won’t be charged anything. They’ll actually be streaming free XRP on your behalf. After entering your credit card info, enter the invite code on the card you received at the opening ceremony or the follow up tech talk. If you didn’t get one, reach out in the gitter channel and we’ll get you one.

Now, after you’re done signing up for Coil you can set up a mainnet moneyd instance.

Go to your terminal and run:

npm install -g moneyd
npm install -g moneyd-uplink-coil
moneyd coil:configure

Put in your account credentials

moneyd coil:start

You’ll get logs that it isn’t sending/receiving routes which is the way it should be, now you’ll be able to send and receive money on the live net. Once you have completed this, you can test your web monetization project!

Project ideas!

Interledger.place

Similar to r/place or satoshis.place, but using micropayments to claim pixels. There could be an SPSP server that receives payments, and doles out pixels to the buyers.

Wallet interface

Simple UI that could be used to send and receive funds with ILP. The UI could show:

  • The upstream connector the wallet is connected to
  • How much funds in each currency (XRP/ETH/BTC) are in the accounts
  • The payment pointer (i.e. user handle) to receive funds
  • An input to send a certain amount of money to a specific payment pointer
  • History -- previous payments sent and received
  • Currencies denoted in dollar amounts

Web-monetized site

Using the web monetization provider or a Coil subscription (ask us for an invite code), students can pay for web-monetized sites using ILP. If you would like to web-monetize your own site, take a look at the Web Monetization standard.

ILPoker

Poker that pays out using Interledger. Every bet is a payment to an SPSP server which holds the pot. At the end of the round, the SPSP server pays the aggregate of all of the round’s payments to the winner of the round. Payment channels to the connector where the SPSP server is hosted contain funds amounting to the buy in.

Merchant interface

Wallet UI content providers of web monetizable content (A.K.A. merchant interface). View all your ILP payments, which users they came from, which pages of the website users browsed/payed for the most.

Marketplace to trade virtual goods

A marketplace for virtual micro-goods (the Steam marketplace is an example of something similar) paid for with ILP.

Music streaming service

A music streaming service where users can only listen to music streams if they are paying the creator/poster of the music while they listen to the music using ILP.

Video streaming service

Same as above, but for video streaming. Check out an example of this here.

ILP drink streaming

A drink faucet that is only activated when a customer starts paying with ILP. This is a hardware/software project that would require a Raspberry Pi/Arduino or the like.

Interledger button

Press a button to stream money. This could be a virtual button -- this is an MVP for a point-of-sale device that requires consistent press to stream money over ILP.

ILP sweatcoin

There’s an app called Sweatcoin that pays you for being active, it could look similar to the running app Strava but you get paid in real time out for your activity. For example, the faster you run the more money the stream pays you.

ILP slither.io

Slither.io but you get paid out as your score increases. Every time you kill a worm, they lose their money, which you can then pick up (in the form of the small energy orbs).

ILP agar.io

Like Slither.io. There are open-source implementations of both of these that could be ILP-enabled.

ILP tournament games

Integration into a simple tournament style game. Everybody has a buy in and kills stream money from the killed to the killer (e.g. ILDeathmatch).

Live streaming

1 presenter, n viewers who can tip. Twitch is like this. Here’s a basic example of a livestreaming app built on ILP.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment