SPSP: Simple Payment Setup Protocol

SPSP is a application-layer protocol designed for making Interledger payments. It uses an HTTPS endpoint to securely exchange payment details, and then allows the user to send one or more Interledger packets. This tutorial will show you how to:

  • Use an SPSP client to make a payment
  • Use an SPSP server to receive a payment
  • Learn how to use SPSP in your application

Prerequisites

This tutorial assumes that you’re running Moneyd on your computer, and that it’s connected to the Interledger testnet. You can read about how to set up Moneyd here.

If you’re not yet set up, it should only take a minute. You don’t need to register any accounts or use any cryptocurrency to use the Interledger testnet.

Making an SPSP Payment

Make sure that you have permissions to install node modules globally.

npm install -g ilp-spsp
ilp-spsp send --amount 10 --receiver '$spsp.ilp-test.com'

If you were successful, you’ll see:

paying 10 to "$spsp.ilp-test.com"...
sent!

To see it in again with more output, run:

DEBUG=ilp* ilp-spsp send --amount 10 --receiver '$spsp.ilp-test.com'

Don’t worry about understanding all of this output for now. It’s just so that you can see what the actual packets going over the wire look like.

Receiving an SPSP Payment

You need an SPSP server to receive SPSP payments. Fortunately, you can install one on NPM. It uses Localtunnel so that you don’t need to expose your machine publicly.

npm install -g ilp-spsp-server
ilp-spsp-server --subdomain my_subdomain

Replace my_subdomain with your name or a random string. If the subdomain you’re trying is already taken, then the server won’t work.

In a different terminal, run:

ilp-spsp send --amount 10 --receiver '$my_subdomain.localtunnel.me'

The payment will show up in your server’s logs.

SPSP in Your Applications

You can use the ilp-protocol-spsp module in your applications, in order to send SPSP payments programmatically. One great use-case for this is writing an application that tips the developer every time you run it, creating a passive income stream.

To connect your application to ILP, we’ll use the ilp-plugin module. ilp-plugin will automatically connect to your local Moneyd instance, allowing your applications to work on both the testnet and the livenet.

First, create a project and install the necessary modules.

mkdir ilp-spsp-tutorial
cd ilp-spsp-tutorial
npm init
npm install --save ilp-protocol-spsp ilp-plugin
vim index.js # open this in your editor of choice

This snippet below is equivalent to the ilp-spsp command that you ran in the previous section. Add the following code to your index.js.

const plugin = require('ilp-plugin')()
const SPSP = require('ilp-protocol-spsp')
async function run () {
console.log('paying $spsp.ilp-test.com...')
  await SPSP.pay(plugin, {
receiver: '$spsp.ilp-test.com',
sourceAmount: '10'
})
  console.log('paid!')
}
run().catch(e => console.error(e))

Finally, you can run your script. This will pay to the same identifier that you used in the first section. You can play around with the code: try to get it to send to your local SPSP receiver.

DEBUG=ilp* node index.js