💻
Developer Guide
  • Wallet SDK
    • Wallet Overview
    • Getting Started
      • 1. Start the RAILGUN Privacy Engine
      • 2. Build a persistent store for artifact downloads
      • 3. Load a Groth16 prover for each platform
      • 4. Add networks and RPC providers
      • 5. Set up a debug logger
    • Private Wallets
      • RAILGUN Wallets
      • View-Only Wallets
      • Encryption Keys
    • Private Balances
      • Balance and Sync Callbacks
      • Updating Balances
      • QuickSync
    • Transactions
      • Shielding
        • Shield ERC-20 tokens
        • Shield base token
        • Shield NFTs
      • Private Transfers
        • Private ERC-20 Transfers
        • Private NFT Transfers
      • Cross-Contract Calls
      • Unshielding
        • Unshield ERC-20 tokens
        • Unshield base token
        • Unshield NFTs
      • UX: Private Transactions
    • Broadcasters
  • Cookbook SDK
    • Cookbook Overview
    • Recipe Guide: Write a zkApp
      • "Step" — A smart contract call
      • "Recipe" — Steps in series
      • "Combo Meal" — 2+ Recipes
    • Use your zkApp privately
  • Engine SDK
    • Engine Overview
  • ZK Account Abstraction
    • Account Abstraction Overview
    • Getting started with the contracts
    • Wallets
    • State Structure
    • Example Primitives
Powered by GitBook
On this page
  1. Wallet SDK
  2. Getting Started

4. Add networks and RPC providers

Previous3. Load a Groth16 prover for each platformNext5. Set up a debug logger

Last updated 10 months ago

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 section.

We will discuss how to initiate additional merkletree scans to fetch latest private balances in the 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 pollingInterval = 1000 * 60 * 5; // 5 min
  
  const { feesSerialized } = await loadProvider(
    ETH_PROVIDERS_JSON,
    NetworkName.Ethereum,
    pollingInterval,
  );
}

// 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.

Balance and Sync Callbacks
Updating Balances