Skip to main content

SFA Node.js SDK to SFA JS SDK Migration Guide

Overview

This migration guide provides steps for updating your existing SFA Node.js SDK integration to the SFA JS SDK. This migration is coming after we have deprecated the SFA Node.js SDK in favour a unified, platform-agnostic solution, the Single Factor Auth JS SDK. This new SDK is an evolution of our popular SFA Web SDK, designed to support all platforms, including React Native, Node.js, and Web.

Key Benefits of the SFA JS SDK:

• Unified API: Simplified and consistent API across platforms.

• Cross-platform Support: One SDK for Web, React Native, and Node.js, reducing integration complexity.

• Feature Enhancements: Incorporates the latest updates and improvements, ensuring a better development experience.

Changes in Detail

Package Changes

Use the @web3auth/single-factor-auth instead of @web3auth/node-sdk

const { Web3Auth } = require("@web3auth/node-sdk");
const { Web3Auth, SDK_MODE } = require("@web3auth/single-factor-auth");
const { CHAIN_NAMESPACES, WEB3AUTH_NETWORK } = require("@web3auth/base");
const { EthereumPrivateKeyProvider } = require("@web3auth/ethereum-provider");

ChainConfig

ChainConfig now requires a logo parameter for the chain's logo and the parameter formerly called blockExplorer has been renamed to blockExplorerUrl. Additionally, isTestnet has been introduced which can be used to define whether the network is testnet or not.

const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: "0x1", // Please use 0x1 for Mainnet
rpcTarget: "https://rpc.ankr.com/eth",
displayName: "Ethereum Mainnet",
blockExplorer: "https://etherscan.io/",
blockExplorerUrl: "https://etherscan.io",
ticker: "ETH",
tickerName: "Ethereum",
decimals: 18,
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
};

Constructor Changes

Pass the privateKeyProvider in the constructor, alongside setting the SDK's mode to SDK_MODE.NODE.

const { Web3Auth, SDK_MODE } = require("@web3auth/single-factor-auth");
const { EthereumPrivateKeyProvider } = require("@web3auth/ethereum-provider");

const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig },
});

const web3auth = new Web3Auth({
clientId, // Get your Client ID from Web3Auth Dashboard
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
privateKeyProvider,
mode: SDK_MODE.NODE,
});

Getting the provider

Now the provider is not returned on the successful login, instead it is always present in the web3auth instance using the provider param.

const web3authNodeprovider = await web3auth.connect({
await web3auth.connect({
verifier: web3authVerifier,
verifierId,
idToken,
});

const ethPublicAddress = await web3authNodeprovider.request({ method: "eth_accounts" });
const ethPublicAddress = await web3auth.provider.request({ method: "eth_accounts" });

Need Help?

If you encounter any issues during migration, please: