Set up your local environment


Using the Callback method requires that you have an endpoint that can accept application/json content-type and is publicly available. For this tutorial we will setup a local environment using a simple Node.js framework, Express and a hosted public request forwarder. Ngrok.


You’ll need a local development environment setup with;

  • Node.js 13+
  • NPM or Yarn

Set up Express

Express is a web framework for Node.js, install using NPM or Yarn

yarn add express

Express makes use of its own modules (termed middleware) to provide capabilities, body-parser is one we’ll use;

yarn add express body-parser

Either clone the MATTR Sample apps from Github or create a folder and add in a file called callback-express.js with this content:

'use strict'
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
// Use body-parser middleware
// Receive a POST request to /callback & print it out to the terminal'/callback', function (req, res) {
const body = req.body
// listen on port 2000
app.listen(2000, function (err) {
if (err) {
throw err
console.log('Server started on port 2000')

In a terminal window start the app to create a server listening for calls to /callback on the specified port.

node callback-express.js

Express has started

Test it out by making a POST call

In a new terminal window use Curl to make a call and check that it is being returned.

curl --request POST \
--url http://localhost:2000/callback \
--header 'Content-Type: application/json' \
--data '{
"json": "payload"

Express parsed payload

Set up Ngrok

Having a server running locally is fine for calls you generate, however the MATTR Platform needs a publicly resolvable address to send the credential data to. A port forwarding service like Ngrok helps us out here.

Note: Credential data is going to be sent to the external service, please ensure you understand the privacy policy of any 3rd party you decide to go with for the purpose of this tutorial.

In a 3rd terminal window, install and run Ngrok on the port defined in callback-express.js

yarn add global ngrok
ngrok http 2000

using ngrok

Every time you start an instance of Ngrok a new forwarding URL is generated that will last for 8 hours. You will need to use the http version of the Forwarding URL.

Test out your public endpoint

Make another call using Curl but this time swap out localhost for your valid Ngrok domain and for clarity update your payload.

curl --request POST \
--url \
--header 'Content-Type: application/json' \
--data '{
"ngrok": "routed"

Your Ngrok window shows the routing

Ngrok routes the URL

Your Express window shows the parsed payload Payload in Express from Ngrok

Now that you are confident that your Local environment is all working, move on to creating the Presentation Request and use the Mobile App to send a Presentation to be received by your callback server.