Skip to main content

Initialization


After Installation, the next step to use XRPL Embed is to Initialize the SDK and that is achieved by init() function.

Please note that these are the most critical steps where you need to pass on different parameters according to the preference of your project. Additionally, Whitelabeling and Custom Authentication have to be configured within this step, if you wish to customise your XRPL Instance.

Instantiating XRPL Embed

Import the Torus class from @toruslabs/xrpl-embed.

import { Torus } from "@toruslabs/xrpl-embed";

Assign the Torus class to a variable

const torus = new Torus(Options);

The Torus constructor takes an object with TorusCtorArgs as input.

Arguments

Options

ParameterTypeDescriptionMandatoryDefault
options objectTorusCtorArgsmodalZIndex: Z-index of the modal and iframe.No99999

Initializing XRPL Embed

init() function is used to initialize the XRPL Embed SDK. It takes an object with TorusParams as input.

Arguments

TorusParams

ParameterTypeOptionsDescriptionMandatory
buttonPositionBUTTON_POSITION_TYPEbottom-left, top-left, bottom-right, top-rightDetermines where the torus widget is visible on the page.No
networkNetworkInterfaceXRPL Network ObjectNo
buildEnvTORUS_BUILD_ENV_TYPEproduction, development, testingBuild Environment of Torus.No
enableLoggingbooleanEnables or disables logging.No
showTorusButtonbooleanwhether to show/hide torus widget.No
useLocalStoragebooleanPrefers to use localStorage instead of sessionStorage for torus iframe. Allows longer lived sessions.No

network

ParameterTypeDescriptionMandatory
blockExplorerUrlstringBlock explorer url for the chainYes
logostringLogo url for the base tokenYes
tickerNamestringName for tickerYes
tickerstringSymbol for tickerYes
rpcTargetstringRPC target Url for the chainYes
chainIdstringUse 0x1 as chainId for xrpl mainnet, 0x2 for testnet and 0x3 for devnet.Yes
displayNamestringDisplay name for the networkYes
networkKeystringxrpl Network KeyYes

Example

await torus.init({
buildEnv: "developement", // "production", or "developement" are also the option
enableLogging: true, // default: false
network: {
chainId: "0x1",
logo: "", // TODO
rpcTarget: "https://ripple-node.tor.us",
wsTarget: "wss://s2.ripple.com",
ticker: "XRP",
tickerName: "XRPL",
displayName: "xrpl mainnet",
blockExplorerUrl: "https://livenet.xrpl.org",
networkKey: "mainnet",
},
showTorusButton: false, // default: true
useLocalStorage: true, // default: false to use sessionStorage
buttonPosition: "top-left", // default: bottom-left
});