4. Add networks and RPC providers

Next, you will need to load an RPC provider for each network/chain that you intend to run private transactions on.

The loadProvider function loads the RailgunProxyContract & RelayAdaptContract and returns the RAILGUN fees for the provided network.

Additionally, it kicks off a merkletree balance scan. This is necessary to know the private balances of the available RAILGUN wallets in the local database (set up in Step 1).

We will set up an onMerkletreeScanCallback function (to monitor the scan's progress and status) and an onBalanceUpdateCallback function (to get notifications of the private balances of each available wallet) in the Balance and Sync Callbacks section.

We will discuss how to initiate additional merkletree scans to fetch latest private balances in the Updating Balances section.

To skip merkletree syncs, set skipMerkletreeScans to true in startRailgunEngine from Step 1.

Example: Load Ethereum network

// main.ts
...
import {
  ...
  FallbackProviderJsonConfig,
  NetworkName,
} from '@railgun-community/shared-models';
import {
  ...
  loadProvider
} from '@railgun-community/wallet';

...

const loadEngineProvider = async () => {
  const ETH_PROVIDERS_JSON: FallbackProviderJsonConfig = {
    "chainId": 1,
    "providers": [
      // The following are example providers. Use your preferred providers here.
      {
        "provider": "https://cloudflare-eth.com/",
        "priority": 1,
        "weight": 1
      },
      {
        "provider": "https://rpc.ankr.com/eth",
        "priority": 2,
        "weight": 1
      },
    ]
  }
  
  const shouldDebug = true;
  
  const { feesSerialized } = await loadProvider(
    ETH_PROVIDERS_JSON,
    NetworkName.Ethereum,
    shouldDebug,
  );
}

// App launch
try {
  initializeEngine();
  ...
  await loadEngineProvider();
  ...
} catch (err) {
  // Handle err
}

The return value, feesSerialized, contains the following fields:

  • deposit: hex string, representing shielding fee in basis points. Current default is 25bp (0.25% fee).

  • withdraw: hex string, representing unshielding fee in basis points. Current default is 25bp.

  • nft: hex string, representing fee for NFT shielding/unshielding. Current default is 0bp.

Store these to inform the user of the RAILGUN fee associated with their transaction.

Last updated