2️Integrate Backend SDK

The Backend SDK is fit for all JavaScript frameworks (NextJS, ExpressJS, Festify, etc). We use ExpressJS below.


Backend SDK Installation and Setup


Step 1: Installation

The SDK can be installed using either npm or yarn.

npm install --save @paytweed/backend-sdk

Step 2: Setup

The only thing required to set up the backend SDK is to implement a way to pass a message from the frontend SDK to the handleMessageFromFrontend method.

You need to pass in your API key and secret in the setup function. You can get your API keys here.

Setup Example

import { TweedBackendSDK } from '@paytweed/backend-sdk'
import express from 'express'

const tweed = await TweedBackendSDK.setup({
  apiKey: 'YOUR_API_KEY',
  apiSecret: 'YOUR_API_SECRET',
  defaultBlockchainIds: ['ethereumSepolia'],
})

const app = express()
app.use(express.json())
app.post('/message', async (req, res) => {
  const userEmail = 'a@a.com' // email of an authenticated user
  const userId = '1' // id of an authenticated user
  const answer = await tweed.handleMessageFromFrontend(req.body.message, userId, userEmail)
  res.send({ answer })
})

app.listen(3000, () => console.log('Example app listening on port 3000'))

Last updated