Skip to main content
Brane uses a Provider to communicate with Ethereum nodes via JSON-RPC.

Chain Profiles

The easiest way to configure a provider is using ChainProfiles.
import io.brane.core.chain.ChainProfiles;

// Mainnet
var mainnet = ChainProfiles.ETH_MAINNET;

// Sepolia
var sepolia = ChainProfiles.ETH_SEPOLIA;

// Anvil (Localhost)
var anvil = ChainProfiles.ANVIL_LOCAL;

Custom RPC URL

You can override the default RPC URL for any chain profile.
import io.brane.rpc.BranePublicClient;

var client = BranePublicClient.forChain(ChainProfiles.ETH_MAINNET)
    .withRpcUrl("https://eth-mainnet.g.alchemy.com/v2/YOUR-API-KEY")
    .build();

Custom Chain

If you are connecting to a custom network (e.g., a private testnet), you can define a custom ChainProfile.
import io.brane.core.chain.ChainProfile;
import io.brane.core.types.Wei;

ChainProfile myChain = ChainProfile.of(
    12345L,                       // Chain ID
    "https://my-custom-rpc.com",  // RPC URL
    true,                         // Supports EIP-1559?
    Wei.gwei(2)                   // Default Gas Price (fallback)
);

var client = BranePublicClient.forChain(myChain).build();

HttpBraneProvider

Under the hood, clients use HttpBraneProvider. You can instantiate it directly if needed for low-level access.
import io.brane.rpc.HttpBraneProvider;
import java.util.List;

var provider = HttpBraneProvider.builder("https://...")
    .build();

// Raw JSON-RPC call
var response = provider.send("eth_chainId", List.of());