📄Spect API

How to create apps on top of Spect API

Introduction

To interact with our server, we need to first authenticate with it using the SIWE protocol.

Once authenticated, you can use any of our APIs.

Also to allow anyone to use our api, we have created a proxy server which you have to use to call our apis, as our main server is restricted only to our domain.

Authentication

The authentication flow is as follows

  1. Query the /nonce endpoint to get a nonce

  2. Sign a message with the nonce

  3. Send the message and signature as payload to /connect

  4. And you are authenticated!

You need to have SIWE and Wagmi installed, it can work with rainbowKit as well

Getting Nonce

const response = await fetch(`proxy.spect.network/api/auth/nonce` , {
    credentials: "include",
});
const nonce = await response.text();

Signing message with nonce

import { SiweMessage } from "siwe";
import { useSignMessage } from "wagmi";

const { signMessageAsync } = useSignMessage();

const message = new SiweMessage({
              domain: window.location.host,
              address: "0x6304CE63F2EBf8C0Cc76b60d34Cc52a84aBB6057",
              statement: "Sign in with Ethereum to the app.",
              uri: window.location.origin,
              version: "1",
              chainId: activeChain?.id,
              nonce,
            });
const signature = await signMessageAsync({
              message: message.prepareMessage(),
            });

Connect

const connect = await fetch("proxy.spect.network/api/auth/login", {
              method: "POST",
              credentials: "include",
              body: JSON.stringify({
                  message,
                  signature,
              }),
            });
const user = await connect.json();

If you wish to use rainbowKit follow these docs https://www.rainbowkit.com/docs/custom-authentication

Next steps

Now you can query all our endpoints with ease, the docs for which can be found on our swagger endpoint: https://apistaging.spect.network/api#/

You have to query the endpoints on

https://proxy.spect.network/api/<endpoint>

Last updated