- class ape_safe.multisend.MultiSend(safe: SafeAccount | None = None, version: Version | str | None = None)#
Create a sequence of calls to execute at once using
eth_sendTransactionvia the MultiSend contract.Usage example:
from ape_safe import multisend from ape import accounts # load the safe me = account.load("my-alias") safe = accounts.load("my-safe") txn = multisend.MultiSend() txn.add(contract.myMethod, *call_args) txn.add(contract.myMethod, *call_args) ... # Add as many calls as desired to execute txn.add(contract.myMethod, *call_args) # or, using a builder pattern: txn = multisend.MultiSend() .add(contract.myMethod, *call_args) .add(contract.myMethod, *call_args) ... # Add as many calls as desired to execute .add(contract.myMethod, *call_args) # Stage the transaction to publish on-chain # NOTE: if not enough signers are available, publish to Safe API instead receipt = txn(submitter=me)
- add(call: ContractMethodHandler, *args, value: int = 0) MultiSend#
Append a call to the MultiSend session object.
Usage:
batch.add(contract.method1) # Method with no args batch.add(contract.method2, *args) # Method with args batch.add(contract.method3, *args, value=...) # Payable method batch(...)
- Raises:
InvalidOption – If one of the kwarg modifiers is not able to be used.
- Parameters:
call –
ContractMethodHandlerThe method to call.*args – The arguments to invoke the method with.
value – int The amount of ether to forward with the call. Defaults to 0.
- add_call(target: Annotated[ChecksumAddress, _AddressValidator] | str, data: HexBytes = '', value: int = 0) MultiSend#
Append a raw call to the MultiSend session object.
- Raises:
InvalidOption – If one of the kwarg modifiers is not able to be used.
- Parameters:
target – The address to send the message to.
data – The data to send to the target. Defaults to empty.
value – int The amount of ether to forward with the call. Defaults to 0.
- add_from_calldata(calldata: bytes) MultiSend#
Decode all calls from a multisend calldata and add them to this MultiSend.
- Parameters:
calldata – Calldata encoding the
MultiSend.multiSendcall.
Usage:
# NOTE: Previously submitted MultiSend SafeTx receipt = chain.get_receipt("0x...") batch.add_from_calldata(receipt.data) # NOTE: `batch` now has all of the same calls in it as the MultiSend in `receipt` did batch(...)
- add_from_receipt(receipt: ReceiptAPI) MultiSend#
Append a call to the MultiSend session object from a receipt. Especially useful for more complex simulations.
Usage:
with networks.fork(): receipt = contract.method(*args, sender=safe.address) assert contract.viewMethod() == ... batch.add_from_receipt(receipt) # NOTE: `receipt` is no longer on the chain (only in fork) batch(...)
- Parameters:
receipt –
ReceiptAPIThe receipt object to pull information from for the call to add.
- as_transaction(safe: SafeAccount | None = None, impersonate: bool = False, **txn_kwargs) TransactionAPI#
Encode the MultiSend transaction as a
TransactionAPIobject, but do not execute it.- Parameters:
safe (
SafeAccount| None) – The Safe account to use for executing this batch. If not provided, then it uses value provided to__init__().impersonate (bool) – Whether to mock approvals for executing this transaction.
**txn_kwargs – the kwargs to pass through to the transaction handler.
- Returns:
TransactionAPI
- classmethod inject(version: Version | str | None = None)#
Create the multisend module contract on-chain, so we can use it. Must use a provider that supports
debug_setCode.- Parameters:
version (
Version| str | None) – The version ofMultiSend/MultiSendCallOnlycontract to use from SDK. Defaults to max available from SDK.
Usage example:
from ape_safe.multisend import MultiSend @pytest.fixture(scope="session") def multisend(): MultiSend.inject() return MultiSend()