Base Blockchain Anchor Integration

This guide covers the Base (Coinbase L2) blockchain anchor client integration for TrustWeave. The Base adapter provides fast and low-cost anchoring with Ethereum security.

Overview

The chains/plugins/base module provides a complete implementation of TrustWeave’s BlockchainAnchorClient interface using Base, Coinbase’s Ethereum L2. This integration enables you to:

  • Anchor credential digests on Base with lower fees than Ethereum
  • Benefit from Coinbase’s backing and ecosystem
  • Use EVM-compatible transaction data storage
  • Leverage Ethereum security with L2 scalability

Installation

Add the Base adapter module to your dependencies:

1
2
3
4
5
6
7
8
9
dependencies {
    implementation("org.trustweave:anchors-plugins-base:0.6.0")
    implementation("org.trustweave:anchors-anchor-core:0.6.0")
    implementation("org.trustweave:common:0.6.0")
    implementation("org.trustweave:distribution-all:0.6.0")

    // Web3j for Base blockchain (EVM-compatible)
    implementation("org.web3j:core:5.0.1")
}

Configuration

Basic Configuration

1
2
3
4
5
6
7
8
9
10
11
12
13
import org.trustweave.anchor.*
import org.trustweave.base.*

// Create Base anchor client for mainnet
val options = mapOf(
    "rpcUrl" to "https://mainnet.base.org",
    "privateKey" to "0x..." // Optional: for signing transactions
)

val client = BaseBlockchainAnchorClient(
    BaseBlockchainAnchorClient.MAINNET,
    options
)

Pre-configured Networks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
// Base mainnet
val mainnetClient = BaseBlockchainAnchorClient(
    BaseBlockchainAnchorClient.MAINNET,
    mapOf(
        "rpcUrl" to "https://mainnet.base.org",
        "privateKey" to "0x..."
    )
)

// Base Sepolia testnet
val sepoliaClient = BaseBlockchainAnchorClient(
    BaseBlockchainAnchorClient.BASE_SEPOLIA,
    mapOf(
        "rpcUrl" to "https://sepolia.base.org",
        "privateKey" to "0x..."
    )
)

SPI Auto-Discovery

When the module is on the classpath, Base adapter is automatically available:

1
2
3
4
5
6
7
8
9
10
11
12
13
import org.trustweave.anchor.*
import org.trustweave.anchor.spi.*
import java.util.ServiceLoader

// Discover Base provider
val providers = ServiceLoader.load(BlockchainAnchorClientProvider::class.java)
val baseProvider = providers.find { it.name == "base" }

// Create client
val client = baseProvider?.create(
    BaseBlockchainAnchorClient.MAINNET,
    mapOf("rpcUrl" to "https://mainnet.base.org")
)

Usage Examples

Anchoring Data

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import org.trustweave.anchor.*
import org.trustweave.base.*
import kotlinx.serialization.json.*

val client = BaseBlockchainAnchorClient(
    BaseBlockchainAnchorClient.BASE_SEPOLIA,
    mapOf(
        "rpcUrl" to "https://sepolia.base.org",
        "privateKey" to "0x..."
    )
)

// Anchor a JSON payload
val payload = buildJsonObject {
    put("digest", "uABC123...")
    put("timestamp", System.currentTimeMillis())
}

val result = client.writePayload(payload, "application/json")
println("Anchored to Base: ${result.ref.txHash}")

Chain IDs

Network Chain ID RPC URL
Base Mainnet eip155:8453 https://mainnet.base.org
Base Sepolia Testnet eip155:84532 https://sepolia.base.org

Advantages

  • Lower fees: Significantly cheaper than Ethereum mainnet
  • Fast confirmations: Optimistic rollup with fast finality
  • Coinbase ecosystem: Access to Coinbase’s user base and tools
  • EVM compatible: Same tools and patterns as Ethereum
  • Ethereum security: Secured by Ethereum mainnet

Integration with TrustWeave

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import org.trustweave.trust.TrustWeave
import org.trustweave.base.*
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.buildJsonObject
import kotlinx.serialization.json.put

val trustWeave = TrustWeave.build {
    did { method("key") { algorithm("Ed25519") } }
    anchor {
        chain(BaseBlockchainAnchorClient.MAINNET) {
            provider("base")
            options { "rpcUrl" to "https://mainnet.base.org" }
        }
    }
}

val digest = "uABC123..."
val payload = buildJsonObject { put("digest", digest) }
val result = trustWeave.blockchains.anchor(
    data = payload,
    serializer = JsonElement.serializer(),
    chainId = BaseBlockchainAnchorClient.MAINNET
)
println("Anchored: ${result.ref.txHash}")

Best Practices

  1. Use Base Sepolia for testing: Always test on Base Sepolia before using mainnet
  2. Coinbase ecosystem: Leverage Coinbase’s infrastructure and tools
  3. Lower fees: Take advantage of Base’s cost savings
  4. Bridge assets: Use Base’s official bridge for ETH transfers

Next Steps

References

  • Base Documentation](https://docs.base.org/)
  • Base Network](https://base.org/)
  • Coinbase Base](https://www.coinbase.com/base)

This site uses Just the Docs, a documentation theme for Jekyll.