Setup

Utility Functions

Setup

Description

Initializes Tweed's backend SDK

Parameters

NameTypeRequiredDescription

apiKey

String

✔️

API key

apiSecret

String

✔️

API secret

callbacks

TweedBackendSdkCallbacks

Configuring callbacks for the checkout products: getNftPurchaseData - Will be called when a NFT checkout request will be initiated by the frontend getTokenPurchaseData - Will be called when a Token checkout request will be initiated by the frontend

defaultBlockchainIds

String[]

✔️

The blockchains that will be used in the lifecycle of the integration

Return type

Promise<TweedBackendSDKApi>

Usage Example

You can get your API keys here.

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

const tweed = await TweedBackendSDK.setup({
  apiKey: 'YOUR_API_KEY', //Taken from your account at console.paytweed.com
  apiSecret: 'YOUR_API_SECRET', //Taken from your account at console.paytweed.com
  callbacks: { getNftPurchaseData }, //Used for the NFT checkout
  defaultBlockchainIds: ['ethereumGoerli'], //Taken from the supported blockchain list
})

Handle message from Frontend

Description

Handles a message that was sent by the frontend SDK

Parameters

NameTypeRequiredDefaultDescription

message

String

✔️

Message that came from the frontend

userId

String

✔️

Id of the authenticated user

userEmail

String

✔️

Email of the authenticated user

Return type

Promise<string>

Usage Example

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

Last updated