Skip to main content

XRPL Private Key Provider for PnP React Native SDK

@web3auth/xrpl-provider

The @web3auth/xrpl-provider is a Web3Auth provider that simplifies interaction with the XRPL Blockchain by serving as a wrapper around the XRPL JSON RPC API. It is used to interact with the XRPL blockchain and perform various operations like getting user's account, balance, signing a transaction, sending a transaction etc.

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

Installation

@web3auth/xrpl-provider

npm install --save @web3auth/xrpl-provider

Initialisation

Import the XrplPrivateKeyProvider class from @web3auth/xrpl-provider.

import { XrplPrivateKeyProvider } from "@web3auth/xrpl-provider";

Assign the XrplPrivateKeyProvider class to a variable

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

const privateKeyProvider = new XrplPrivateKeyProvider({ config: XrplPrivKeyProviderConfig });

This constructor takes an object with a config of XrplPrivKeyProviderConfig as input.

Arguments

XrplPrivKeyProviderConfig

export interface XrplPrivKeyProviderConfig extends BaseProviderConfig {
chainConfig: Omit<CustomChainConfig, "chainNamespace"> & Pick<CustomChainConfig, "wsTarget">;
}
export type CustomChainConfig = {
chainNamespace: ChainNamespaceType;
/**
* The chain id of the chain
*/
chainId: string;
/**
* RPC target Url for the chain
*/
rpcTarget: string;
/**
* web socket target Url for the chain
*/
wsTarget?: string;
/**
* Display Name for the chain
*/
displayName: string;
/**
* Url of the block explorer
*/
blockExplorer: string;
/**
* Default currency ticker of the network (e.g: ETH)
*/
ticker: string;
/**
* Name for currency ticker (e.g: `Ethereum`)
*/
tickerName: string;
/**
* Number of decimals for the currency ticker (e.g: 18)
*/
decimals?: number;
};
export interface BaseProviderConfig extends BaseConfig {
chainConfig: Partial<CustomChainConfig>;
networks?: Record<string, CustomChainConfig>;
skipLookupNetwork?: boolean;
}
export interface BaseConfig {
/**
* Determines if this controller is enabled
*/
disabled?: boolean;
}

Getting the chainConfig

  • Chain Namespace: OTHER
  • Chain ID: 0x1
  • Public RPC URL: https://ripple-node.tor.us (Avoid using public rpcTarget in production, use services like Infura)
  • WebSocket URL: wss://s2.ripple.com
  • Ticker: XRP
  • Ticker Name: XRPL
  • Display Name: xrpl mainnet
  • Block Explorer Link: https://livenet.xrpl.org

Initializing Provider

Post V10 release, Web3Auth PnP Web SDK does not need any additional setup on the code side for XRPL. All is handled on the Dashboard.

import { Web3Auth, WEB3AUTH_NETWORK } from "@web3auth/modal";

const web3AuthOptions: Web3AuthOptions = {
clientId,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
};

const web3auth = new Web3Auth(web3AuthOptions);

await web3auth.init();

await web3auth.connect();
// await web3auth.connectTo(); // For custom flow

const provider = web3auth.provider;

Usage


After configuring the provider, you may utilize various functions from the @web3auth/xrpl-provider library for tasks such as obtaining the user's account, executing transactions, and signing messages.

info

All the RPC methods which are available by default on XRPL Blockchain are also available on the XRPL Provider.

Please refer to our XRPL Connect Blockchain Reference for more information.