Full Linea RPC APIs Support in Web3j

Full Linea RPC APIs Support in Web3j

Web3j, an LF Decentralized Trust project, is a lightweight, highly modular Java library for integrating Ethereum-based applications. It allows developers to interact with Ethereum smart contracts, transactions, and accounts seamlessly. With growing adoption of Layer 2 solutions, Web3j has expanded its support for Layer 2 EVM-compatible chains like Linea, enabling developers to leverage cost-efficient and scalable blockchain interactions.

Introduction to Linea

Linea is a Layer 2 solution built on Ethereum that leverages zero-knowledge rollups (ZK-rollups) to provide fast, cost-efficient transactions. As part of its infrastructure, Linea offers a set of RPC APIs that developers can use to interact with the network, retrieve blockchain data, estimate transaction fees, and verify proofs.

With the latest updates in Web3j, we now support full integration of Linea RPC APIs, enabling developers to seamlessly interact with the Linea network using Java and Kotlin.

Linea RPC APIs in Web3j

Web3j now supports the following Linea-specific RPC methods:

1. linea_estimateGas

This API estimates the gas required for a transaction to be successfully executed on the Linea network.

  • Returns the recommended gas limit, base fee per gas, and priority fee per gas.
  • Uses the same inputs as `eth_estimateGas`, but provides more accurate results tailored for Linea.

Sample Code for `linea_estimateGas` in Hyperledger Web3j

2. linea_getProof

This API retrieves the account and storage values, including Merkle proof verification, for a given account at a specific block.

  • Provides Merkle proof of an account’s existence or non-existence.
  • Includes account balance, nonce, code hash, and storage proof.
  • The block parameter must reference an L2 block that has been finalized on L1.

Sample Code for `linea_getProof` in Web3j


3. linea_getTransactionExclusionStatusV1

This API checks whether a transaction was rejected by the Linea sequencer or RPC nodes.

  • Can only query transactions attempted within the past 7 days.
  • If rejected, it returns the reason for rejection.
  • If the transaction was not rejected, the response is null.

Sample Code for `linea_getTransactionExclusionStatusV1` in Web3j




Testing and Feedback

Developers can now test these APIs using Web3j by connecting to a Linea RPC endpoint. We encourage users to test and provide feedback on this integration to improve usability and reliability.

The PR - https://github.com/hyperledger-web3j/web3j/pull/2150 - has been merged into the main branch and will be available in Web3j v4.13.0, the next major release.

Conclusion

With full support for Linea’s RPC APIs, Web3j provides developers with a seamless experience for interacting with the Linea network. By leveraging these features, developers can efficiently estimate gas costs, verify transaction proofs, and handle transaction exclusion scenarios.

We look forward to your feedback on this integration and any suggestions for additional features!

If you are interested in contributing to Web3j’s ongoing development, feel free to check out our GitHub repository and join the discussions! You can also find us here on the LF Decentralized Trust Discord.

 

Back to all blog posts