In an exciting development for the Ethereum and blockchain developer community, Web3j has become the first web3 library to implement support for sending EIP-4844 blob transactions to Ethereum clients. This update brings us closer to the future of Ethereum's scalability and efficiency, providing a glimpse of what full data sharing for the network could eventually look like.
Understanding EIP-4844 and its impact
EIP-4844, known for introducing “blob-bearing transactions” to Ethereum, is designed to support large amounts of data that the EVM runtime cannot access, but commit can. This innovative approach allows important data to be temporarily stored on the beacon node, improving the network's ability to handle large information.
Full data sharing will still take considerable time to complete implementation and deployment. This EIP provides an interim solution until then by implementing the transaction format that would be used in partitioning, but without actually partitioning those transactions. Instead, data in this transaction format simply becomes part of the beacon chain and is fully uploaded by all consensus nodes (but can be deleted after only a relatively short time). Compared to full data sharing, this EIP has a reduced cap on the number of such transactions that can be included, corresponding to a target of approximately 0.375 MB per block and a limit of approximately 0.75 MB.
Currently, L2 or Rollups networks spend a lot to ensure that their transaction data is available to all of their nodes and validators. Most rollups do this by writing their data to Ethereum as call data. This costs around $1,000 per megabyte at current prices. Good rollups reduce this amount to $300 per megabyte using advanced data compression. However, data publication costs account for the largest portion of L2 transaction costs. With EIP4844 blob data, Ethereum addresses the data availability needs of rollups, so they provide a new, hopefully cheaper way for rollups to save their data, which would help significantly reduce transaction fees on Layer 2 networks like Optimism, Polygon zkEVM. , Arbitrum, Starknet, etc.
New transaction type specification in EIP-4844
EIP-4844 transactions follow the new EIP-2718 transaction type, “blob transaction”, where TransactionType is BLOB_TX_TYPE = Bytes1 (0x03). The fields string_id, occasionally, max_priority_fee_per_gas, max_fee_per_gas, gas_limit, value, dataAnd access_list follow the same semantics as EIP-1559.
There are two more fields added max_fee_per_blob_gas is a uint256 and the field blob_versioned_hashes represents a list of hash outputs from kzg_to_versioned_hash.
Networking
We can send a signed EIP-4844 transaction using web3j to eth_sendRawTransaction The API and raw form must be the network form. This means it includes the tx_payload_body, blobs, KZG commits and KZG proofs.
Each of these elements is defined as follows:
- tx_payload_body – is the TransactionPayloadBody of the standard EIP-2718 blob transaction
- blobs – list of Blob elements
- commitments – list of KZGCommitment of corresponding blobs
- evidence – KZGProof list of blobs and corresponding commitments
Code Example: Sending a Blob Transaction with Web3j
Before moving on to the next code example, make sure that the network you are working with has EIP-4844 support enabled.
To use the EIP-4844 blob transaction feature in Web3j, developers can follow this example:
public class Web3jEIP4844 Example {
public static empty main(Chain() arguments) throws Exception {
// Initialize Web3j and credentials
Web3j web3j = Web3j.build(new HttpService(“
Credentials credentials = Credentials.create(“
// Get the current nonce for the account
LargeWhole occasionally = web3j.ethGetTransactionCount(
credentials.getAddress(), DefaultBlockParameterName.LATEST)
.send()
.getTransactionCount();
// Get the current value of the base fee per gas Blob
LargeWhole blobBaseFee = web3j.ethGetBaseFeePerBlobGas();
System.out.println(“blobBaseFee = “ + blobBaseFee);
// Multiply baseFeePerBlobGasValue by the appropriate number to set it as our maxFeePerBlobGas value
LargeWhole maxFeePerBlobGas = GrandEntire.value((long) (web3j.ethGetBaseFeePerBlobGas().longValue() * 1.1));
// Create a blob transaction
Raw transaction raw transaction = createEip4844Transaction(
casual, maxFeePerBlobGas);
// Sign the transaction
byte() signed message = TransactionEncoder.signMessage(rawTransaction, identifying information);
Chain hexadecimal value = Numeric.toHexString(signedMessage);
// Send the transaction
EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(hexValue).send();
System.out.println(“Transaction Hash:” + ethSendTransaction.getTransactionHash());
System.out.println(“Transmission receipt = “ + web3j.ethGetTransactionReceipt(ethSendTransaction.getTransactionHash()).send().getTransactionReceipt());
}
private static Raw transaction createEip4844RawTransaction(BigInteger casual, BigInteger maxFeePerBlobGas) {
List
blobs.add(new Drop(“
back RawTransaction.createTransaction(
drops,
11155111L,
from time to time,
GrandEntire.value(10_000_000_000L),
GrandEntire.value(50_000_000_000L),
GrandEntire.value(3_00_000L),
“<à l'adresse>“,
GrandEntire.value(0),
“”,
maxFeePerBlobGas);
}
}
If we simply want to calculate KZG Commitment and KZG Proofs from a blob, we can do so using the BlobUtils class functions.
Drop drop = new Drop(
Numeric.hexStringToByteArray(
loadResourceAsString(“blob_data.txt”)));
Bytes commitment = BlobUtils.getCommitment(blob);
Bytes evidence = BlobUtils.getProof(blob, commitment);
Bytes versionedHashes = BlobUtils.kzgToVersionedHash(commitment);
BlobUtils.checkProofValidity(blob, commitment, evidence)
For developers interested in viewing PRs related to EIP-4844 in web3j –
- Implementing Blob Transactions – https://github.com/web3j/web3j/pull/2000
- Implemented a new block header format, got Blob base fees and a new transaction receipt format – https://github.com/web3j/web3j/pull/2006
These PRs are included in the web3j version >=4.11.0
Conclusion
Web3j's recent integration of EIP-4844 blob transactions as the first web3 library to adopt this innovation shows its commitment to blockchain development and the latest advancements.
This blog post delved into the technical intricacies of EIP-4844, from its potential impact on Ethereum's scalability to the specifics of the new transaction type it introduces.
Additionally, practical information on using Web3j for sending EIP-4844 transactions provides developers with the tools needed to explore this new frontier.