Skip to main content

@djuno/web3auth-sdk

A TypeScript/JavaScript SDK for authenticating users via blockchain wallets with the Web3 Auth API.

Djuno Support avatar
Written by Djuno Support
Updated today

๐Ÿš€ Installation

npm install @djuno/web3auth-sdk 
# or
yarn add @djuno/web3auth-sdk


โœจ Quickstart

import { Client } from '@djuno/web3auth-sdk';

const client = new Client({ accessKey: 'your-access-key', });
const networks = await client.networks();
console.log(networks.data);


๐Ÿงฉ Constructor

new Client(configs?: ClientConfigs)

ClientConfigs type:

type ClientConfigs = { 
endpointUrl?: string; // Defaults to https://web3auth.djuno.cloud
accessKey?: string; // Required
version?: string; // Defaults to 'v1'
headers?: Record<string, string>;
}


๐Ÿ“š Methods

networks

client.networks(): Promise<{ data: Network[] }>

Fetches the list of supported blockchain networks and wallets.


handshake

client.handshake(networkId: string, walletAddress: string)

Starts the authentication flow by requesting a signable message.

Returns:

{ 
data: string; // Message to sign
status: boolean;
}


verify

client.verify(networkId: string, walletAddress: string, signature: string)

Verifies the signed message and returns a JWT token.

Returns:

{ 
data: string; // JWT Token
status: boolean; message: string;
}


getProfile

client.getProfile(token: string)

Retrieves the authenticated user's profile.


updateProfile

client.updateProfile(token: string, data: object)

Updates the user's profile with the provided data.


getProfileAvatar

client.getProfileAvatar(token: string)

Returns the userโ€™s avatar as a Blob URL (browser-compatible only).

const { data: blobUrl } = await client.getProfileAvatar(token);
const img = new Image();
img.src = blobUrl;

Automatically revokes the blob URL after 5 seconds.


saveProfileAvatar

client.saveProfileAvatar(token: string, formData: FormData)

Uploads a profile avatar image.

const formData = new FormData();
formData.set('img', file);

await client.saveProfileAvatar(token, formData);

Node.js compatible (form-data headers handled automatically).


setAccessKey

client.setAccessKey(newKey: string)

Dynamically updates the API key for the SDK instance.


๐Ÿงพ Types

Network

type Network = { 
Id: number;
NetworkName: string;
ChainId: string;
WalletResponses: NetworkWallet[];
}

NetworkWallet

type NetworkWallet = { 
Id: number;
WalletName: string;
NetworkId: number;
}
Did this answer your question?