Skip to main content

Common Provider for SFA Web SDK

@web3auth/base-provider

For connecting to blockchains other than EVM, Solana, and XRPL, you need to use the private key from Web3Auth and manually make RPC calls to the blockchain. This flow is facilitated by @web3auth/base-provider package.

In this section, we'll explore more about how you can use this provider with our SDKs.

Installation

@web3auth/base-provider

npm install --save @web3auth/base-provider

Initialisation

Import the CommonPrivateKeyProvider class from @web3auth/base-provider.

import { CommonPrivateKeyProvider } from "@web3auth/base-provider";

Assign the CommonPrivateKeyProvider class to a variable

After creating your Web3Auth instance, you need to initialize the CommonPrivateKeyProvider and add it to a class for further usage.

const privateKeyProvider = new CommonPrivateKeyProvider();
Note
  • The common private key provider only exposes one RPC method (i.e. 'private_key') to get the private key of the logged-in user.

Chain Configuration

const chainConfig = {
chainNamespace: "other",
chainId: "Algorand", //
rpcTarget: "https://api.algoexplorer.io",
// Avoid using public rpcTarget in production.
// Use services like PureStake, AlgoExplorer API, etc.
displayName: "Algorand Mainnet",
blockExplorerUrl: "https://algoexplorer.io",
ticker: "ALGO",
tickerName: "Algorand",
};
import { Web3Auth } from "@web3auth/modal";
import { CommonPrivateKeyProvider } from "@web3auth/base-provider";
import { WEB3AUTH_NETWORK, CHAIN_NAMESPACES } from "@web3auth/base";

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

const web3auth = new Web3Auth({
// Get it from Web3Auth Dashboard
clientId,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
privateKeyProvider: privateKeyProvider,
});

Usage

On connection, you can use this provider as a private key provider to expose the user's private key in the frontend context

//Assuming the user is already logged in.
async getPrivateKey() {
const privateKey = await web3authSfaprovider.request({
method: "private_key"
});
//Do something with privateKey
}
tip

Please refer to our Non EVM Connect Blockchain Reference for more information.