Developers
DevelopersGuides
  • Introducing Bond
    • Introduction
    • Why we build Bond?
    • Roles In Bond Ecosystem
    • Decentralised Relations/Social Graph
    • Architecture
    • Bond Reward Model
      • Leech Principle
      • Barrel Principle
  • Main Concepts
    • Bond Profile
      • Identity
      • Relationships
      • Content
      • Creator Economy
    • Connection
      • Connection NFTs
    • Bond Social Graph
    • Centralities
      • In/Out Degree Centrality
      • Betweenness Centrality
      • Closeness Centrality
      • PageRank Centrality
    • Reward Models
    • Reward Contracts
    • Off-chain Oracles
    • Gasless Mode
    • Cross Chain Messaging and Pay Gas with Bond Token
  • Bond API
    • Introduction
    • API Urls
    • Getting started with GraphQL
    • Authentication
      • Login
      • Refresh JWT
    • Profile
      • Create Profile
      • SetProfileMetadata
    • Connect
      • Connect a profile
      • Disconnect
  • Smart Contracts
    • BondHub
    • MerkelDistributor
    • TokenDeployer
    • SingleStakePoolDeployer
    • LzTokenDeployer
    • LzSingleStakePoolDeployer
  • Bond SDK
    • Bond JS SDK
      • Authenticate
      • Create Profile
      • Connect
  • Bond Nodes
    • Hardware Requirements
    • Set up and Deploy
    • Node Config (TOML)
    • Secrets Config (TOML)
    • Role-Based Access Control (RBAC)
  • References
    • Deployed Contracts
    • Github
Powered by GitBook
On this page
  1. Bond SDK
  2. Bond JS SDK

Authenticate

Example of how to use Bond JS SDK to authenticate.

import BondHub, { Blockchain, Env } from "@bondlab/client";
import Web3 from "web3";

const apiKey = process.env.BOND_API_KEY;
const appId = process.env.BOND_APP_ID;

const bondHub = new BondHub({
  provider: Web3.givenProvider,
  chain: Blockchain.POLYGON,
  env: Env.STAGING,
  apiKey,
  appId,
})

// get challenge and autheniticate with the signature
await bondHub.login()

Or you can authenticate via seperate steps.

import BondHub, { Blockchain, Env } from "@bondlab/client";

const apiKey = process.env.BOND_API_KEY;
const appId = process.env.BOND_APP_ID;
const privateKey = process.env.WALLET_PRIVATE_KEY

const bondHub = new BondHub({
  provider: Web3.givenProvider,
  chain: Blockchain.POLYGON,
  env: Env.STAGING,
  apiKey,
  appId,
}


const wallet = new ethers.Wallet(privateKey);
const address = await wallet.getAddress();

const challenge = await bondHub.generateChallenge(address);
const signature = await wallet.signMessage(challenge);

await bondHub.authenticate(address, signature);
PreviousBond JS SDKNextCreate Profile

Last updated 1 year ago