JavaScript SDK

Multibase JS SDK

To integrate off-chain data into your project, you'll need to use the Multibase JS SDK. This SDK allows you to identify users by their wallet address, track product events, and more. Multibase JS is the first JavaScript SDK for merging your user off-chain, product interactions with on-chain transactions and activity.

✅ Getting started

Install the Node Package

To get started with using Multibase JS, you'll need to install the package to your project with NPM/yarn.

# npm
npm install @multibase/js
 
# yarn
yarn add @multibase/js

💻 Usage

Initialize the SDK

Multibase JS must be initialized before you can call any function. You will need your Multibase project's write API key.

import { init } from '@multibase/js'
 
init(YOUR_WRITE_API_KEY)

Identify users

To associate product events with users, you have to use the identify function.

Identify by an address

To connect a user by their on-chain address, we must provide an address parameter.

When you identify user by wallet address, they will automatically be synchronized in your Multibase workspace. Upon import, Multibase will sync all on-chain data on every chain where a user has sent at least one transaction.

import { identify } from "@multibase/js"
 
// Basic identifying call
identify({
    address: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045"
})
 
// Identify with properties
const userProperties = {
    plan: "Premium User",
    email: "vitalik@ethereum.org"
}
identify({
    address: "0xd8da6bf26964af9d7eed9e03e53415d37aa96045",
    properties: userProperties
})

Track events

Tracking product events from your users is the key to understanding product usage over time, and understanding how off-chain activity converts to on-chain transactions. You can track and event with a custom string, or you can track properties along with the string.

In your Multibase dashboard, these events will appear alongside on-chain events.

import { track } from "@multibase/js"
 
// Basic tracking call
track("Link Click")
 
// Track with event properties
const eventProperties = {
    type: "Call to Action",
    timeToClick: 10
}
track("Link Click", eventProperties)