Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

Commit 3a3cb32

Browse files
eth_createAccessList - Closes #4081 (#4332)
* Init web3.eth.createAccessList * Init e2e test for createAccessList * Add createAccessList method to method wrappers for contracts * Update failing tests to use dynamic address * Add check to not run tests if ENV not Geth * Add createAccessList to docs * Update CHANGELOG.md * Update docs/web3-eth-contract.rst * Update docs/web3-eth-contract.rst * Update docs/web3-eth-contract.rst * Update docs/web3-eth-contract.rst * Update docs/web3-eth-contract.rst * Update docs/web3-eth.rst * Remove duplicate line in CHANGELOG * Move CHANGELOG addition to 1.6.1
1 parent dbb4350 commit 3a3cb32

File tree

7 files changed

+286
-1
lines changed

7 files changed

+286
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,10 @@ Released with 1.0.0-beta.37 code base.
458458

459459
## [1.6.1]
460460

461+
### Added
462+
463+
- Support for `eth_createAccessList` as both an rpc call (`web3.eth.createAccessList`) and property of contract method wrappers (`contractInstance.methods.getValue().createAccessList`) (#4332)
464+
461465
### Changed
462466

463467
- Not considering `tx.chainId` if `tx.common.customChain.chainId` is provided for `web3.eth.accounts.signTransaction` function (#4293)
@@ -466,3 +470,4 @@ Released with 1.0.0-beta.37 code base.
466470
- Emit subscription id with connect event when creating a subscription (#4300)
467471
- Introduced new configuration "blockHeaderTimeout" for waiting of block headers for transaction receipt (#3891)
468472
- Format `block.baseFeePerGas` to number (#4330)
473+
- Updated README to include Webpack 5 angular support instructions (#4174)

docs/web3-eth-contract.rst

+70-1
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,7 @@ Returns
613613
- ``Function`` - :ref:`send <contract-send>`: Will deploy the contract. The promise will resolve with the new contract instance, instead of the receipt!
614614
- ``Function`` - :ref:`estimateGas <contract-estimateGas>`: Will estimate the gas used for deploying. Note: You must specify a ``from`` address otherwise you may experience odd behavior.
615615
- ``Function`` - :ref:`encodeABI <contract-encodeABI>`: Encodes the ABI of the deployment, which is contract data + constructor parameters
616+
- ``Function`` - :ref:`createAccessList <contract-createAccessList>`: Returns an EIP-2930 access list for specified contract method Note: You must specify a ``from`` address and possible ``gas``
616617

617618
-------
618619
Example
@@ -684,7 +685,7 @@ methods
684685
685686
myContract.methods.myMethod([param1[, param2[, ...]]])
686687
687-
Creates a transaction object for that method, which then can be :ref:`called <contract-call>`, :ref:`send <contract-send>`, :ref:`estimated <contract-estimateGas>`, or :ref:`ABI encoded <contract-encodeABI>`.
688+
Creates a transaction object for that method, which then can be :ref:`called <contract-call>`, :ref:`send <contract-send>`, :ref:`estimated <contract-estimateGas>`, :ref:`createAccessList <contract-createAccessList>` , or :ref:`ABI encoded <contract-encodeABI>`.
688689

689690
The methods of this smart contract are available through:
690691

@@ -711,6 +712,7 @@ Returns
711712
- ``Function`` - :ref:`send <contract-send>`: Will send a transaction to the smart contract and execute its method (Can alter the smart contract state).
712713
- ``Function`` - :ref:`estimateGas <contract-estimateGas>`: Will estimate the gas used when the method would be executed on chain. Note: You must specify a ``from`` address otherwise you may experience odd behavior.
713714
- ``Function`` - :ref:`encodeABI <contract-encodeABI>`: Encodes the ABI for this method. This can be send using a transaction, call the method or passing into another smart contracts method as argument.
715+
- ``Function`` - :ref:`createAccessList <contract-createAccessList>`: Returns an EIP-2930 access list for specified contract method Note: You must specify a ``from`` address and ``gas`` if it's not specified in ``options`` when instantiating parent contract object (e.g. ``new web3.eth.Contract(jsonInterface[, address][, options])``).
714716

715717
-------
716718
Example
@@ -1038,6 +1040,73 @@ Example
10381040
> '0x58cf5f1000000000000000000000000000000000000000000000000000000000000007B'
10391041
10401042
1043+
------------------------------------------------------------------------------
1044+
1045+
.. _contract-createAccessList:
1046+
1047+
methods.myMethod.createAccessList
1048+
=====================
1049+
1050+
.. code-block:: javascript
1051+
1052+
myContract.methods.myMethod([param1[, param2[, ...]]]).createAccessList(options, blockHashOrBlockNumber [, callback])
1053+
1054+
Will call to create an access list a method execution will access when executed in the EVM.
1055+
Note: Currently `eth_createAccessList` seems to only be supported by Geth.
1056+
Note: You must specify a ``from`` address and ``gas`` if it's not specified in ``options`` when instantiating parent contract object (e.g. ``new web3.eth.Contract(jsonInterface[, address][, options])``).
1057+
1058+
----------
1059+
Parameters
1060+
----------
1061+
1062+
1. ``options`` - ``Object``: The options used for calling.
1063+
* ``from`` - ``String``: The address the call "transaction" should be made from.
1064+
* ``gas`` - ``Number`` (optional): The maximum gas provided for this call "transaction" (gas limit). Setting a specific value helps to detect out of gas errors. Access list response will return amount of gas used.
1065+
2. ``block`` - ``String|Number|BN|BigNumber`` (optional): The block number or hash. Or the string ``"earliest"``, ``"latest"`` or ``"pending"`` as in the :ref:`default block parameter <eth-defaultblock>`.
1066+
3. ``callback`` - ``Function`` (optional): This callback will be fired with the result of the access list generation as the second argument, or with an error object as the first argument.
1067+
1068+
-------
1069+
Returns
1070+
-------
1071+
1072+
``Promise`` returns ``Object``: The generated access list for transaction.
1073+
1074+
.. code-block:: javascript
1075+
1076+
{
1077+
"accessList": [
1078+
{
1079+
"address": "0x00f5f5f3a25f142fafd0af24a754fafa340f32c7",
1080+
"storageKeys": [
1081+
"0x0000000000000000000000000000000000000000000000000000000000000000"
1082+
]
1083+
}
1084+
],
1085+
"gasUsed": "0x644e"
1086+
}
1087+
1088+
1089+
-------
1090+
Example
1091+
-------
1092+
1093+
.. code-block:: javascript
1094+
1095+
// using the callback
1096+
myContract.methods.myMethod(123).createAccessList({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe', gas: 5000000}, function(error, accessList){
1097+
...
1098+
});
1099+
1100+
// using the promise
1101+
myContract.methods.myMethod(123).createAccessList({from: '0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe', gas: 5000000})
1102+
.then(function(accessList){
1103+
...
1104+
})
1105+
.catch(function(error){
1106+
...
1107+
});
1108+
1109+
10411110
------------------------------------------------------------------------------
10421111

10431112

docs/web3-eth.rst

+59
Original file line numberDiff line numberDiff line change
@@ -2153,3 +2153,62 @@ Example
21532153
}
21542154
21552155
------------------------------------------------------------------------------
2156+
2157+
createAccessList
2158+
=====================
2159+
2160+
.. code-block:: javascript
2161+
2162+
web3.eth.createAccessList(callObject [, callback])
2163+
2164+
Will call to create an access list a method execution will access when executed in the EVM.
2165+
Note: Currently `eth_createAccessList` seems to only be supported by Geth.
2166+
Note: You must specify a ``from`` address and ``gas`` if it's not specified in ``options`` when instantiating parent contract object (e.g. ``new web3.eth.Contract(jsonInterface[, address][, options])``).
2167+
2168+
----------
2169+
Parameters
2170+
----------
2171+
2172+
1. A transaction object, see :ref:`web3.eth.sendTransaction <eth-sendtransaction-return>` with the difference that this method is specifically for contract method executions.
2173+
2. ``block`` - ``String|Number|BN|BigNumber`` (optional): The block number or hash. Or the string ``"earliest"``, ``"latest"`` or ``"pending"`` as in the :ref:`default block parameter <eth-defaultblock>`.
2174+
3. ``callback`` - ``Function`` (optional): This callback will be fired with the result of the access list generation as the second argument, or with an error object as the first argument.
2175+
2176+
2177+
-------
2178+
Returns
2179+
-------
2180+
2181+
``Promise`` returns ``Object``: The generated access list for transaction.
2182+
2183+
.. code-block:: javascript
2184+
2185+
{
2186+
"accessList": [
2187+
{
2188+
"address": "0x00f5f5f3a25f142fafd0af24a754fafa340f32c7",
2189+
"storageKeys": [
2190+
"0x0000000000000000000000000000000000000000000000000000000000000000"
2191+
]
2192+
}
2193+
],
2194+
"gasUsed": "0x644e"
2195+
}
2196+
2197+
-------
2198+
Example
2199+
-------
2200+
2201+
2202+
.. code-block:: javascript
2203+
2204+
web3.eth.createAccessList({
2205+
from: '0x3bc5885c2941c5cda454bdb4a8c88aa7f248e312',
2206+
data: '0x20965255',
2207+
gasPrice: '0x3b9aca00',
2208+
gas: '0x3d0900',
2209+
to: '0x00f5f5f3a25f142fafd0af24a754fafa340f32c7'
2210+
})
2211+
.then(console.log);
2212+
2213+
2214+
------------------------------------------------------------------------------

packages/web3-eth-contract/src/index.js

+21
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,7 @@ Contract.prototype._createTxObject = function _createTxObject(){
819819
txObject.send.request = this.parent._executeMethod.bind(txObject, 'send', true); // to make batch requests
820820
txObject.encodeABI = this.parent._encodeMethodABI.bind(txObject);
821821
txObject.estimateGas = this.parent._executeMethod.bind(txObject, 'estimate');
822+
txObject.createAccessList = this.parent._executeMethod.bind(txObject, 'createAccessList');
822823

823824
if (args && this.method.inputs && args.length !== this.method.inputs.length) {
824825
if (this.nextMethod) {
@@ -916,6 +917,26 @@ Contract.prototype._executeMethod = function _executeMethod(){
916917
}
917918

918919
switch (args.type) {
920+
case 'createAccessList':
921+
922+
// return error, if no "from" is specified
923+
if(!utils.isAddress(args.options.from)) {
924+
return utils._fireError(errors.ContractNoFromAddressDefinedError(), defer.eventEmitter, defer.reject, args.callback);
925+
}
926+
927+
var createAccessList = (new Method({
928+
name: 'createAccessList',
929+
call: 'eth_createAccessList',
930+
params: 2,
931+
inputFormatter: [formatters.inputTransactionFormatter, formatters.inputDefaultBlockNumberFormatter],
932+
requestManager: _this._parent._requestManager,
933+
accounts: ethAccounts, // is eth.accounts (necessary for wallet signing)
934+
defaultAccount: _this._parent.defaultAccount,
935+
defaultBlock: _this._parent.defaultBlock
936+
})).createFunction();
937+
938+
return createAccessList(args.options, args.callback);
939+
919940
case 'estimate':
920941

921942
var estimateGas = (new Method({

packages/web3-eth/src/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,12 @@ var Eth = function Eth() {
584584
params: 0,
585585
outputFormatter: formatter.outputTransactionFormatter
586586
}),
587+
new Method({
588+
name: 'createAccessList',
589+
call: 'eth_createAccessList',
590+
params: 2,
591+
inputFormatter: [formatter.inputTransactionFormatter, formatter.inputDefaultBlockNumberFormatter],
592+
}),
587593

588594
// subscriptions
589595
new Subscriptions({

test/e2e.eth.createAccessList.js

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
var assert = require('assert');
2+
var Basic = require('./sources/Basic');
3+
var Misc = require('./sources/Misc');
4+
var utils = require('./helpers/test.utils');
5+
var Web3 = utils.getWeb3();
6+
7+
describe('method.call [ @E2E ]', function () {
8+
var web3;
9+
var accounts;
10+
var basic;
11+
var instance;
12+
var options;
13+
14+
var basicOptions = {
15+
data: Basic.bytecode,
16+
gasPrice: 1000000000, // Default gasPrice set by Geth
17+
gas: 4000000
18+
};
19+
20+
var miscOptions = {
21+
data: Misc.bytecode,
22+
gasPrice: 1000000000, // Default gasPrice set by Geth
23+
gas: 4000000
24+
};
25+
26+
describe('http', function () {
27+
before(async function () {
28+
web3 = new Web3('http://localhost:8545');
29+
accounts = await web3.eth.getAccounts();
30+
31+
basic = new web3.eth.Contract(Basic.abi, basicOptions);
32+
instance = await basic.deploy().send({from: accounts[0]});
33+
})
34+
35+
it('returns expected access list for getValue', async function () {
36+
// Currently only Geth supports eth_createAccessList
37+
if (process.env.GANACHE || global.window ) return
38+
39+
var expected = {
40+
accessList: [
41+
{
42+
address: instance.options.address.toLowerCase(),
43+
storageKeys: ["0x0000000000000000000000000000000000000000000000000000000000000000"]
44+
}
45+
],
46+
gasUsed: '0x644e'
47+
};
48+
49+
assert.deepEqual(
50+
await instance.methods.getValue().createAccessList({from: accounts[0]}),
51+
expected
52+
);
53+
});
54+
55+
it('returns expected access list for setValue', async function () {
56+
// Currently only Geth supports eth_createAccessList
57+
if (process.env.GANACHE || global.window ) return
58+
59+
var expected = {
60+
accessList: [
61+
{
62+
address: instance.options.address.toLowerCase(),
63+
storageKeys: ["0x0000000000000000000000000000000000000000000000000000000000000000"]
64+
}
65+
],
66+
gasUsed: '0xb2f5'
67+
}
68+
69+
70+
assert.deepEqual(
71+
await instance.methods.setValue(1).createAccessList({from: accounts[0]}),
72+
expected
73+
);
74+
});
75+
});
76+
});

test/eth.createAccessList.js

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
var testMethod = require('./helpers/test.method.js');
2+
3+
var method = 'createAccessList';
4+
5+
var tests = [{
6+
args: [{
7+
from: '0x3bc5885c2941c5cda454bdb4a8c88aa7f248e312',
8+
data: '0x20965255',
9+
gasPrice: '0x3b9aca00',
10+
gas: '0x3d0900',
11+
to: '0x00f5f5f3a25f142fafd0af24a754fafa340f32c7'
12+
}],
13+
formattedArgs: [
14+
{
15+
from: '0x3bc5885c2941c5cda454bdb4a8c88aa7f248e312',
16+
data: '0x20965255',
17+
gasPrice: '0x3b9aca00',
18+
gas: '0x3d0900',
19+
to: '0x00f5f5f3a25f142fafd0af24a754fafa340f32c7'
20+
},
21+
'latest'
22+
],
23+
result: {
24+
"accessList": [
25+
{
26+
"address": "0x00f5f5f3a25f142fafd0af24a754fafa340f32c7",
27+
"storageKeys": [
28+
"0x0000000000000000000000000000000000000000000000000000000000000000"
29+
]
30+
}
31+
],
32+
"gasUsed": "0x644e"
33+
},
34+
formattedResult: {
35+
"accessList": [
36+
{
37+
"address": "0x00f5f5f3a25f142fafd0af24a754fafa340f32c7",
38+
"storageKeys": [
39+
"0x0000000000000000000000000000000000000000000000000000000000000000"
40+
]
41+
}
42+
],
43+
"gasUsed": "0x644e"
44+
},
45+
call: 'eth_'+ method
46+
}];
47+
48+
testMethod.runTests('eth', method, tests);
49+

0 commit comments

Comments
 (0)