Common Provider for PnP React Native 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();
- 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",
};
Post V10 release, Web3Auth PnP Web SDK does not need any additional setup on the code side for other chains. All is handled on the Dashboard.
import { Web3Auth, WEB3AUTH_NETWORK } from "@web3auth/modal";
const web3AuthOptions: Web3AuthOptions = {
clientId,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
};
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
}
Please refer to our Non EVM Connect Blockchain Reference for more information.