Announcing Web3j support for EIP-1559

The most anticipated Ethereum London fork upgrade is here! It includes the improvement proposal EIP-1559. The upgrade is scheduled to go live on mainnet at block number 12,965,000, and expected to complete August 5.

The legacy transaction model on Ethereum uses an  auction style where highest bidders are going first on blocks which have a limited size. This auction style has caused trouble for many users as they will often wait for gas prices to go down, which can take hours or even days!

Another downside of this model is the vulnerability of high prices of gas being created by artificial demand from malicious miners. We’ve also seen the network become congested, the success of DeFi during the Summer of 2020 saw Ethereum gas prices soar with total fees sometimes reaching as high as $500 for a single transaction.

EIP-1559 aims to improve upon this old model by aiming to make transaction fee more predictable, and calculate the fee algorithmically instead of the miner’s based auction system. To achieve this, the protocol introduces two key changes:

  1. A Market Rate for transactions called BASEFEE: A known price for gas which helps users to estimate gas prices and avoid overpaying. Additional tips can be provided to miners to give priority for your transactions.

  2. Dynamic block sizes: Now a block size has the same limit as before (15M gas in size) but with a flexibility to increase to 30M gas in size.

Web3j 4.8.7 release includes the changes to support new transaction types with additional fields required for the JSON RPC API. 

The following section is a walkthrough of how to send EIP-1559 with Web3j.

EIP-1559 with Web3j

Getting started with adding library to project using Maven:-

<dependency>

  <groupId>org.web3j</groupId>

  <artifactId>core</artifactId>

  <version>4.8.7</version>

</dependency>

Or using Gradle:-

dependencies {

   implementation "org.web3j:core:4.8.7",

          ……

}

Configure http service and credentials:-

Web3j web3 = Web3j.build(new HttpService());

Credentials credentials = 

WalletUtils.loadCredentials("password", "/path/to/walletfile");

Use the Transfer class for sending Ether with EIP-1559 new fields:-

TransactionReceipt transactionReceipt = Transfer.sendFundsEIP1559(

        web3j, credentials,

        "0x<address>|<ensName>", //toAddress

        BigDecimal.ONE.valueOf(1), //value

        Convert.Unit.ETHER, //unit

        BigInteger.valueOf(8_000_000), gasLimit

        DefaultGasProvider.GAS_LIMIT,//maxPriorityFeePerGas

        BigInteger.valueOf(3_100_000_000L)//maxFeePerGas

  ).send();

Access new attributes effectiveGasPrice and type through TransactionReceipt:-

transactionReceipt.getType();

transactionReceipt.effectiveGasPrice();

Use Web3j to get block and access new fields:-

  EthBlock.Block block = web3j.ethGetBlockByNumber(

            DefaultBlockParameter.valueOf(“<block number>”),

            true  //returnFullTransactionObjects

            ).send().get().getBlock();

  block.getBaseFeePerGas();

Other options to get block or get uncle like:-

EthBlock.Block block = web3j.ethGetBlockByHash(String blockHash, boolean returnFullTransactionObjects);

EthBlock.Block block = web3j.ethGetUncleByBlockHashAndIndex(String blockHash, BigInteger transactionIndex);

EthBlock.Block block = web3j.ethGetUncleByBlockNumberAndIndex(

DefaultBlockParameter defaultBlockParameter, BigInteger transactionIndex);

Access Transactions new field through Web3j:-

EthTransaction ethTransaction = web3j.ethGetTransactionByHash(String transactionHash).send();

EthTransaction ethTransaction =   web3j.ethGetTransactionByBlockHashAndIndex(String blockHash,        BigInteger transactionIndex).send();

EthTransaction ethTransaction =     web3j.ethGetTransactionByBlockNumberAndIndex(DefaultBlockParameter defaultBlockParameter, BigInteger transactionIndex).send();

Access new transaction:- 

ethTransaction .getTransaction().get().getType();

ethTransaction .getTransaction().get().getMaxFeePerGas();

ethTransaction .getTransaction().get().getMaxPriorityFeePerGas();

ethTransaction.getTransaction().get().getAccessList();

Please refer to web3j documentation for more details.

EIP-1559 is considered to be one of the most important Ethereum Improvement Proposals. It’s expected to have a big impact on the user experience as well as the economics of the network. The gas fee is likely to be reduced by 90% and the burning mechanism is said to make Ethereum deflationary. 

As Etheruem moves from Proof-of-Work to Proof-of-Stake, this upgrade is also important for the security of the network and energy consumption. To find out more, read our blog here which explains the consensus algorithm called Proof of Work and its competitor, Proof of Stake. 

Thanks to all who contributed to Web3j and helped the development of EIP-1559. We encourage all users and developers to contribute to our Web3j github repo.


What are your thoughts on EIP-1559? Let us know in the comments! In the meantime, to stay abreast of all blockchain trends, listen or watch This Week in Blockchain through (watch.)weekinblockchain.com, or through your preferred podcast platform.