Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

Quickstart

Overview

Brane is a modern, type-safe Java SDK for Ethereum. It provides a clean, fluent API for interacting with EVM, with a focus on correctness and performance.

Installation

Brane is available on Maven Central. Add the dependencies to your project:

Maven
<dependencies>
    <dependency>
        <groupId>sh.brane</groupId>
        <artifactId>brane-core</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>sh.brane</groupId>
        <artifactId>brane-rpc</artifactId>
        <version>0.3.0</version>
    </dependency>
    <dependency>
        <groupId>sh.brane</groupId>
        <artifactId>brane-contract</artifactId>
        <version>0.3.0</version>
    </dependency>
</dependencies>

Usage

1. Connect to a Chain

Create a Brane client to read from the blockchain.

import sh.brane.rpc.Brane;
 
public class Example {
    public static void main(String[] args) {
        // Connect to an RPC endpoint
        var client = Brane.connect("https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY");
 
        // Get the latest block number
        var block = client.getLatestBlock();
        System.out.println("Current Block: " + block.number());
    }
}

2. Send a Transaction

Create a Brane.Signer client to sign and send transactions.

import sh.brane.rpc.Brane;
import sh.brane.core.crypto.PrivateKeySigner;
import sh.brane.core.builder.TxBuilder;
import sh.brane.core.types.Wei;
import sh.brane.core.types.Address;
import java.math.BigDecimal;
 
// 1. Create a signer from a private key
var signer = new PrivateKeySigner(System.getenv("SEPOLIA_PRIVATE_KEY"));
 
// 2. Connect with signing capability
var client = Brane.connect("https://rpc.sepolia.org", signer);
 
// 3. Build and send a transaction
var request = TxBuilder.eip1559()
    .to(new Address("0x..."))
    .value(Wei.fromEther(new BigDecimal("0.01")))
    .build();
 
var receipt = client.sendTransactionAndWait(request);
 
System.out.println("Tx Hash: " + receipt.transactionHash());