ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

support for createAccessList

Open 0xall opened this issue 3 years ago • 7 comments

Describe the Feature

By EIP-2930, transaction containing an access list can reduce gas price. However, it's hard to determine what accessList should be passed when building a transaction. Fortunately, many geth nodes support eth_createAccessList rpc and this method creates accessList based on a given transaction.

It's already issued before in #1364, but it's closed without supporting eth_createAccessList. ethers.js supports accessList in transaction param, but it doesn't support eth_createAccessList rpc to create accessList for the transaction.

According to EIP-2930 - Rationale: Charging less for accesses in the access list, passing accessList to transaction is encouraged since it helps to pre-load data from database (such as by loading the data in parallel). It also helps to reduce gas consumption for transactions.

RPC Documentation

https://geth.ethereum.org/docs/rpc/ns-eth#eth_createaccesslist

eth_createAccessList is similar with eth_estimateGas. It returns the estimated gas like eth_estimateGas, but it also returns accessList for the transaction.

Code Example

const { accessList, gasUsed } = await provider.createAccessList(txReq);
txReq.accessList = accessList;

const tx = await provider.sendTransaction(txReq);

0xall avatar Jun 15 '22 16:06 0xall

At the time it was not supported in any nodes I tried it on. Do you have any examples of it working on INFURA or Alchemy now?

ricmoo avatar Jun 15 '22 16:06 ricmoo

Of course :)

You can test by Alchemy. It isn't in document, but it supports. By sending https://eth-mainnet.alchemyapi.io/v2/{YOUR_ALCHEMY_API_KEY} by POST method.

This is json-rpc body for test.

{
    "method":"eth_createAccessList",
    "params": [
        {
            "from": "0x0000000000000000000000000000000000000001", 
            "to": "0x2be5e8c109e2197D077D13A82dAead6a9b3433C5",
            "data": "0xcae9ca51000000000000000000000000c4a11aaf6ea915ed7ac194161d2fc9384f15bff2000000000000000000000000000000000000000000000039c0885c3cdaeccc000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000004000000000000000000000000056e465f654393fa48f007ed7346105c7195cee4300000000000000000000000039a13a796a3cd9f480c28259230d2ef0a7026033"
            
        }, 
        "pending"
    ],
    "id":1,
    "jsonrpc":"2.0"
}

it returns like below.

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "accessList": [
            {
                "address": "0x56e465f654393fa48f007ed7346105c7195cee43",
                "storageKeys": [
                    "0x0000000000000000000000000000000000000000000000000000000000000002",
                    "0x0000000000000000000000000000000000000000000000000000000000000003",
                    "0xefe4edd12afaf9d0df1308bccd25b316134b8b7e9d5dc80456660dd940653bc8",
                    "0xb45820386466a8e01597d6e1efaf8f11ba4467972de5ca6c1f8aa3544ac2888e",
                    "0xdfd283c4a34e8de29bc07af805b3667f5746d0442cb14f4f37d3c03083e0f0df",
                    "0x0b6fac705b1aacab15c916e75cdc725433f2eb42a1e3631dc34204d624fa5954",
                    "0xb39221ace053465ec3453ce2b36430bd138b997ecea25c1043da0c366812b828",
                    "0x0000000000000000000000000000000000000000000000000000000000000004",
                    "0xec646dc6d4c93e86591cb8725f06e50158b413031b568ac64820b172699c5e86"
                ]
            },
            {
                "address": "0x710936500ac59e8551331871cbad3d33d5e0d909",
                "storageKeys": [
                    "0x0000000000000000000000000000000000000000000000000000000000000005",
                    "0x0000000000000000000000000000000000000000000000000000000000000004",
                    "0xc1f26453137327c2a2ff78e92170202e5076ee5e43826ec9b8eba1906a6a9113",
                    "0x000000000000000000000000000000000000000000000000000000000000000a"
                ]
            },
            {
                "address": "0x39a13a796a3cd9f480c28259230d2ef0a7026033",
                "storageKeys": [
                    "0x0000000000000000000000000000000000000000000000000000000000000000"
                ]
            },
            {
                "address": "0x6fc20ca22e67aab397adb977f092245525f7aeef",
                "storageKeys": [
                    "0x000000000000000000000000000000000000000000000000000000000000000a",
                    "0x000000000000000000000000000000000000000000000000000000000000000c",
                    "0x000000000000000000000000000000000000000000000000000000000000000d",
                    "0x1af71f306103cb287906d7605db78592676f824849578ba9c353b7ae6124f571",
                    "0xc1f26453137327c2a2ff78e92170202e5076ee5e43826ec9b8eba1906a6a9115",
                    "0xc1f26453137327c2a2ff78e92170202e5076ee5e43826ec9b8eba1906a6a9113",
                    "0xc1f26453137327c2a2ff78e92170202e5076ee5e43826ec9b8eba1906a6a9114",
                    "0x000000000000000000000000000000000000000000000000000000000000000f"
                ]
            },
            {
                "address": "0xcf8b6843271bff848c707c143ccca4b6325e854e",
                "storageKeys": [
                    "0x72c6bfb7988af3a1efa6568f02a999bc52252641c659d85961ca3d372b57d5cf",
                    "0x72c6bfb7988af3a1efa6568f02a999bc52252641c659d85961ca3d372b57d5d0",
                    "0x000000000000000000000000000000000000000000000000000000000000000f",
                    "0x000000000000000000000000000000000000000000000000000000000000000a",
                    "0x000000000000000000000000000000000000000000000000000000000000000c",
                    "0x000000000000000000000000000000000000000000000000000000000000000d",
                    "0x1af71f306103cb287906d7605db78592676f824849578ba9c353b7ae6124f571",
                    "0x72c6bfb7988af3a1efa6568f02a999bc52252641c659d85961ca3d372b57d5d1"
                ]
            },
            {
                "address": "0x85ca9f611c363065252ea9462c90743922767b55",
                "storageKeys": [
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69b1",
                    "0x7dc88232ebe0ae6d18d0e2dcee8a74db82e814af197078f88be684ba5142c746",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69b0",
                    "0x020ce710971eace59270c3ed49d71d24bede9c03862696d2ba399e12c811e8ad",
                    "0x414201aa84770f4663c24f3bd43d38fe8d05d8e40b10cbdf4e51d2fefb023ac5",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69ac",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69af",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69b2",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69b3",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69b4",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69b5",
                    "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
                    "0x000000000000000000000000000000000000000000000000000000000000000f",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69ad",
                    "0xff5f91f0631625fc8731830e5809ae86c29a8096cd75e8c36e0b8978e93a69ae"
                ]
            },
            {
                "address": "0x2be5e8c109e2197d077d13a82daead6a9b3433c5",
                "storageKeys": [
                    "0x55ee4194132ce545daf749c35054fd31bdc9b252a26dd07032ea1ab096f70ab9",
                    "0xada5013122d395ba3c54772283fb069b10426056ef8ca54750cb9bb552a59e7d",
                    "0xfcd201047cfacadd26d3a935a8c59e5e5a6d4c4ac6ba2eac61dbb8bffb48273b",
                    "0x0000000000000000000000000000000000000000000000000000000000000007"
                ]
            },
            {
                "address": "0xc4a11aaf6ea915ed7ac194161d2fc9384f15bff2",
                "storageKeys": [
                    "0x000000000000000000000000000000000000000000000000000000000000000a",
                    "0x0000000000000000000000000000000000000000000000000000000000000003",
                    "0xcc69885fda6bcc1a4ace058b4a62bf5e179ea78fd58a1ccd71c22cc9b688792f",
                    "0x0000000000000000000000000000000000000000000000000000000000000008",
                    "0x021848d60c9b0964bd4b8333f226c3739cb52935e1cddece863426482881a346",
                    "0x5bc7e6e0f57427079be172bab0e1156129b10396bfe7a9534f75b3d9840f1644",
                    "0x1bf90da8867850ea82f59d299d537edc1366afe0d59a76b2dfbb35dcad558bab",
                    "0xfa2c07fb56eb4bdc4a13debe7fca735e802a86b3daf43e4ecb3e264c19517fb2",
                    "0x2adf98e1062af6c87ec98055eb6814dd1008ac078b405302ce5ff5826e29e97d"
                ]
            },
            {
                "address": "0x03140e1e254a4840c4983b20267a5c391e3fdb19",
                "storageKeys": []
            },
            {
                "address": "0x10f5f22d53415ba10f0e3b0fb0999b2928f20822",
                "storageKeys": []
            },
            {
                "address": "0x0b3e174a2170083e770d5d4cf56774d221b7063e",
                "storageKeys": [
                    "0xb0797f3f7c537a57ff12a32c3fbe25b0df09e3510e4041396e717f44f8c4285a"
                ]
            },
            {
                "address": "0x970298189050abd4dc4f119ccae14ee145ad9371",
                "storageKeys": [
                    "0x0000000000000000000000000000000000000000000000000000000000000003",
                    "0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc",
                    "0x0000000000000000000000000000000000000000000000000000000000000000",
                    "0x1618681d376ee0c838fc4fbb5c7d0312014e16d111443fa59ad619b85ff4edc6",
                    "0x0000000000000000000000000000000000000000000000000000000000000005"
                ]
            }
        ],
        "gasUsed": "0x55112"
    }
}

Request Type

It's same with eth_estimateGas.

https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L1151 https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L1367

eth_createAccessList RPC Result Type

https://github.com/ethereum/go-ethereum/blob/master/internal/ethapi/api.go#L1359 https://github.com/ethereum/go-ethereum/blob/master/core/types/access_list_tx.go#L28

Transaction with access list example

https://etherscan.io/tx/0xfbf20efe99271206c0f5b497a92bee2e66f8bf9991e07648935194f17610b36e#accesslist

0xall avatar Jun 15 '22 18:06 0xall

Cool cool. I’ll try it out and figure out the best way to add it to the API. We don’t want to include it by default (like we do for estimate gas, which is required) since the reads and writes may not be consistent, which could make transactions wildly more expensive as you would pre-pay for slots you end up not accessing.

But maybe it makes sense in v6 to add a pseudo-property, like the planned gasMultiplier which is part of the porcelain API to hint to fill in the accessList.

ricmoo avatar Jun 15 '22 19:06 ricmoo

You're right. Access lists are non-deterministic for some transactions. (such as transactions that executes different logic by block hash) In this case, including access list can be more expensive. It should be used for deterministic access list.

Thanks :)

0xall avatar Jun 16 '22 01:06 0xall

Looking forward to this feature as well. @0xall in the meantime, you can still access the create list api using the low level ethers method send from your wallet instance.

CryptoKiddies avatar Jun 29 '22 01:06 CryptoKiddies

I would be happy to help you with this, do you have an idea what the implementation should look like @ricmoo?

imqdee avatar Sep 05 '22 15:09 imqdee