Skip to content

EIP-2930 Transaction

EIP 2930 Transaction

Adds a transaction type which contains an accessList, a list of addresses and storage keys that the transaction plans to access: these addresses and storage keys are added into the accessed_addresses and accessed_storage_keys global sets. Accesses outside the list are possible, but become more expensive.

Spec

The new EIP-2718 TransactionType = 1(0x01) and TransactionPayload for this transaction is rlp([chainId, nonce, gasPrice, gasLimit, to, value, data, accessList, signatureYParity, signatureR, signatureS]).

Example

public void signedEip2930() throws SignatureException {
        Credentials credentials = Credentials.create("<privateKey>");
        Web3j web3j = Web3j.build(new HttpService("<nodeUrl>"));

        final RawTransaction rawTransaction = createEip2930RawTransaction();

        final byte[] signedMessage =
                TransactionEncoder.signMessage(rawTransaction, credentials);
        final String signedHexMessage = Numeric.toHexString(signedMessage);

        EthSendTransaction ethSendTransaction = web3j.ethSendRawTransaction(signedHexMessage).send();

        System.out.println("Transaction hash: " + ethSendTransaction.getTransactionHash());
        System.out.println("Tx Receipt = " + web3j.ethGetTransactionReceipt(ethSendTransaction.getTransactionHash()).send().getTransactionReceipt());

    }

private static RawTransaction createEip2930RawTransaction() {
        // Test example from https://eips.ethereum.org/EIPS/eip-2930
        List<AccessListObject> accessList = Stream.of(
                                                new AccessListObject(
                                                    "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
                                                    Stream.of(
                                                        "0x0000000000000000000000000000000000000000000000000000000000000003",
                                                        "0x0000000000000000000000000000000000000000000000000000000000000007")
                                                    .collect(toList())),
                                                new AccessListObject(
                                                    "0xbb9bc244d798123fde783fcc1c72d3bb8c189413",
                                                    Collections.emptyList()))
                                            .collect(toList());

        return RawTransaction.createTransaction(
                3L,
                BigInteger.valueOf(0),
                BigInteger.valueOf(30000),
                BigInteger.valueOf(500000),
                "0x627306090abab3a6e1400e9345bc60c78a8bef57",
                BigInteger.valueOf(1000000),
                "0x1000001111100000",
                accessList);
        }