Skip to main content

Configure webhooks

The ConsenSys NFT (CNFT) platform lets you easily add webhooks to subscribe to events linked to your account. For example, a webhook can notify your app when an NFT sells or has updated prices, and thus enabling your app to perform some actions.

To create a webhook, go to Settings > Webhooks, and select Add Webhook.

webhook-1-add-webhook

Add a name for your identification and a destination endpoint where the message should be sent. Include a common secret token to secure your webhooks and be confident that the message is from CNFT. When an event is triggered, an HTTP POST payload is sent to the webhook's configured URL.

Let's test if the webhook works with a Token Transfer event, using a local server to receive the test message from CNFT. To expose the local development environment, you'll use ngrok, a free tool that exposes local servers to the public internet over secure tunnels.

Download and install ngrok.

Unzip ngrok from the terminal:

sudo unzip ~/Downloads/ngrok-stable-darwin-amd64.zip -d /usr/local/bin

Sign up for an authtoken and add it to the configuration file:

ngrok authtoken <token>

Start a HTTP tunnel forwarding to your local port 4567:

ngrok http 4567

You should see something similar to:

Forwarding  http://8148-100-37-254-15.ngrok.io -> http://localhost:4567

Set up a simple Sinatra app to receive the request, named webhook-test.rb:

require 'sinatra'
require 'json'

post '/payload' do
push = JSON.parse(request.body.read)
puts "I got some JSON: #{push.inspect}"
end

Start the server:

ruby webhook-test.rb

Because you want the server to listen to the POST requests at /payload, add the ngrok forwarding address + /payload to the Test Webhook section in the Settings > Webhooks tab.

webhook2-test-webhook

Select Test Webhook.

In your terminal, you should see something similar to:

I got some JSON: {"id"=>"6d3fee94-317b-4cbc-b071-2eb043bcfbd1", ...

This means your webhook is working properly!