Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

@branch/rpc-config

A centralized configuration package for Berachain networks, providing chain configurations, RPC URLs, and utility functions for both browser and Node.js environments.

Installation

# Core package
npm install @branch/rpc-config

# With viem support
npm install viem

# With ethers support
npm install ethers

Usage

Basic Usage

import {
  berachainMainnet,
  berachainTestnet,
  berachainLocalnet,
  getChainById,
  getChainByName,
} from "@branch/rpc-config";

// Use predefined chains
const mainnet = berachainMainnet;
const testnet = berachainTestnet;
const localnet = berachainLocalnet;

// Get chain by ID
const chain = getChainById(80085); // Returns berachainMainnet

// Get chain by name
const chainByName = getChainByName("berachain"); // Returns berachainMainnet

Integration Patterns

Browser Integration

For browser-based applications, you can use either Viem or Ethers to create wallet connections:

// Using Viem
import { createBrowserWalletClient } from "@branch/rpc-config/viem";
import { berachainMainnet } from "@branch/rpc-config";

const browserWallet = createBrowserWalletClient({
  chain: berachainMainnet,
  // ... other options
});

// Using Ethers
import { createBrowserEthersSigner } from "@branch/rpc-config/ethers";
import { berachainMainnet } from "@branch/rpc-config";

const browserSigner = createBrowserEthersSigner({
  chain: berachainMainnet,
  // ... other options
});

Security considerations for browser integration:

  • Always use HTTPS in production
  • Implement proper error handling for wallet connection failures
  • Consider implementing wallet connection persistence
  • Handle network switching gracefully
  • Implement proper transaction confirmation handling

Node.js Script Integration

For scripts and backend services, you can use private key-based authentication:

// Using Viem
import { createBerachainWalletClient } from "@branch/rpc-config/viem";
import { berachainMainnet } from "@branch/rpc-config";

const walletClient = createBerachainWalletClient({
  chain: berachainMainnet,
  // ... other options
});

// Using Ethers
import { createBerachainEthersSigner } from "@branch/rpc-config/ethers";
import { berachainMainnet } from "@branch/rpc-config";

const signer = createBerachainEthersSigner({
  chain: berachainMainnet,
  // ... other options
});

Security considerations for Node.js scripts:

  • Never commit private keys to version control
  • Use environment variables for sensitive data
  • Implement proper error handling and retries
  • Consider implementing transaction monitoring
  • Use secure RPC endpoints

Framework Integration

The package works with various development frameworks:

Hardhat

Foundry

Frontend Frameworks

Network Information

Berachain Mainnet

Bepolia Testnet

Adding Networks to MetaMask

To add Berachain networks to MetaMask:

  1. Open MetaMask and click on the network selector dropdown
  2. Click "Add Network"
  3. Click "Add Network Manually"
  4. Use the network information from above to fill in the fields:
    • For Mainnet, use the Berachain Mainnet details
    • For Testnet, use the Bepolia Testnet details
  5. Click "Save"

Additional Resources

Contributing

This package is part of the Berachain Guides repository.