Blast

Blast

Java / Kotlin

Web3j is the primary JVM library for working with Blast, the ETH-gas Optimistic Rollup with chain ID 81457. It works with Java 8+ and integrates cleanly with Kotlin coroutines out of the box. For Android projects, depend on the web3j-android artifact instead, which excludes desktop-only dependencies that bloat or break an APK build. Add it through Gradle with implementation "org.web3j:core:4.x.x" and point the HttpService at https://blast.therpc.io/YOUR_API_KEY.

Web3j supports Java 8+ and pairs naturally with Kotlin coroutines, so suspending balance and transaction calls against Blast read cleanly. For Android builds, use the web3j-android artifact to drop desktop-only dependencies that would otherwise inflate your APK or trigger packaging conflicts.

Web3j

Create the client with Web3j.build(new HttpService(nodeUrl)), passing your Blast endpoint https://blast.therpc.io/YOUR_API_KEY as nodeUrl. The same call works identically from Java and Kotlin; the examples below show both, reading an ETH balance and signing a raw transfer transaction.

import org.web3j.protocol.Web3j;
import org.web3j.protocol.http.HttpService;
import org.web3j.utils.Convert;
import java.math.BigDecimal;
public class EthereumClient {
private final Web3j web3j;
public EthereumClient(String nodeUrl) {
this.web3j = Web3j.build(new HttpService(nodeUrl));
}
public BigDecimal getBalance(String address) throws Exception {
BigInteger balanceWei = web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST)
.send()
.getBalance();
return Convert.fromWei(balanceWei.toString(), Convert.Unit.ETHER);
}
public String sendTransaction(Credentials credentials, String toAddress, BigDecimal ethAmount) {
BigInteger gasPrice = web3j.ethGasPrice().send().getGasPrice();
BigInteger value = Convert.toWei(ethAmount, Convert.Unit.ETHER).toBigInteger();
RawTransaction rawTransaction = RawTransaction.createEtherTransaction(
nonce, gasPrice, GAS_LIMIT, toAddress, value);
byte[] signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials);
String hexValue = Numeric.toHexString(signedMessage);
return web3j.ethSendRawTransaction(hexValue).send().getTransactionHash();
}
}
import org.web3j.protocol.Web3j
import org.web3j.protocol.http.HttpService
import org.web3j.utils.Convert
import java.math.BigDecimal
class EthereumClient(nodeUrl: String) {
private val web3j = Web3j.build(HttpService(nodeUrl))
suspend fun getBalance(address: String): BigDecimal {
val balanceWei = web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST)
.send()
.balance
return Convert.fromWei(balanceWei.toString(), Convert.Unit.ETHER)
}
suspend fun sendTransaction(
credentials: Credentials,
toAddress: String,
ethAmount: BigDecimal
): String {
val gasPrice = web3j.ethGasPrice().send().gasPrice
val value = Convert.toWei(ethAmount, Convert.Unit.ETHER).toBigInteger()
val rawTransaction = RawTransaction.createEtherTransaction(
nonce, gasPrice, GAS_LIMIT, toAddress, value)
val signedMessage = TransactionEncoder.signMessage(rawTransaction, credentials)
val hexValue = Numeric.toHexString(signedMessage)
return web3j.ethSendRawTransaction(hexValue).send().transactionHash
}
}

Android Support

On Android, never run Blast RPC calls on the main thread — launch them in viewModelScope.launch and switch to Dispatchers.IO so network I/O stays off the UI thread and keeps the app responsive. The client construction is identical to the desktop case: Web3j.build(HttpService("https://blast.therpc.io/YOUR_API_KEY")). The ViewModel example below fetches a balance and is ready to push the result back to your UI state.

// Android example
class EthereumViewModel : ViewModel() {
private val web3j = Web3j.build(HttpService("https://blast.therpc.io/YOUR_API_KEY"))
fun getBalance(address: String) = viewModelScope.launch {
withContext(Dispatchers.IO) {
val balance = web3j.ethGetBalance(address, DefaultBlockParameterName.LATEST)
.send()
.balance
// Update UI
}
}
}

Smart Contract Integration

Use the web3j CLI to generate Java or Kotlin wrapper classes directly from a Solidity ABI, as shown below. The generated wrapper exposes each contract method as a type-safe call, so interacting with a Blast contract — say, a yield-bearing vault — becomes a strongly typed method invocation rather than manual ABI encoding.

web3j solidity generate /path/to/contract.sol -o /path/to/output -p com.your.package
val contract = YourContract.load(
contractAddress,
web3j,
credentials,
gasPrice,
gasLimit
)
// Call contract method
val result = contract.someMethod().send()

Ready to call this in production?

Free tier covers personal projects. Pay-as-you-go scales without a card.