Skip to content

Commit 6a3a087

Browse files
committed
added start_multicall method to Web3Advanced to get a new MultiCall instance
1 parent 06f4004 commit 6a3a087

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

IceCreamSwapWeb3/Multicall.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ def main(
325325
usdt_address=to_checksum_address("0x900101d06A7426441Ae63e9AB3B9b0F63Be145F1"),
326326
):
327327
w3 = Web3Advanced(node_url=node_url)
328-
multicall = MultiCall(w3=w3)
329328

330329
with open("abi/Counter.abi") as f:
331330
counter_contract_abi = f.read()
@@ -337,19 +336,18 @@ def main(
337336
counter_contract = w3.eth.contract(bytecode=counter_contract_bytecode, abi=counter_contract_abi)
338337
usdt_contract = w3.eth.contract(address=usdt_address, abi=erc20_abi)
339338

339+
# initializing new multicall
340+
multicall = w3.start_multicall()
341+
340342
# calling an undeployed contract
341-
# '''
342343
multicall.add_undeployed_contract(counter_contract.constructor(initialCounter=13))
343344
multicall.add_undeployed_contract_call(counter_contract.functions.counter())
344345
multicall.add_undeployed_contract_call(counter_contract.functions.updateCounter(newCounter=7))
345346
multicall.add_undeployed_contract_call(counter_contract.functions.counter())
346-
# '''
347347

348-
# '''
349348
for _ in range(10_000):
350349
# calling a deployed contract
351350
multicall.add_call(usdt_contract.functions.decimals())
352-
# '''
353351

354352
multicall_result = multicall.call()
355353
print(multicall_result)

IceCreamSwapWeb3/Web3Advanced.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from web3.middleware import geth_poa_middleware
55

66
from .EthAdvanced import EthAdvanced
7+
from .Multicall import MultiCall
78

89

910
class Web3Advanced(Web3):
@@ -60,6 +61,9 @@ def _construct_provider(node_url):
6061
else:
6162
raise ValueError(f"Unknown protocol for RPC URL {node_url}")
6263

64+
def start_multicall(self) -> MultiCall:
65+
return MultiCall(w3=self)
66+
6367
def _find_max_filter_range(self):
6468
current_block = self.eth.block_number
6569
for filter_range in self.FILTER_RANGES_TO_TRY:

0 commit comments

Comments
 (0)