@@ -253,10 +253,10 @@ def SetFields(cls, fields: dict[TxnField, Expr | list[Expr]]) -> Expr:
253253 def ExecuteMethodCall (
254254 cls ,
255255 * ,
256- app_id : Expr ,
256+ app_id : Expr | None ,
257257 method_signature : str ,
258258 args : list [abi .BaseType | Expr | dict [TxnField , Expr | list [Expr ]]],
259- extra_fields : dict [TxnField , Expr | list [Expr ]] = None ,
259+ extra_fields : dict [TxnField , Expr | list [Expr ]] | None = None ,
260260 ) -> Expr :
261261 """Performs a single app call transaction formatted as an ABI method call.
262262
@@ -277,6 +277,7 @@ def ExecuteMethodCall(
277277
278278 Args:
279279 app_id: An expression that evaluates to a `TealType.uint64` corresponding to the application being called.
280+ If the call is meant to create an application, the value `None` should be passed
280281 method_signature: A string representing the method signature of the method we're calling. This is used to do
281282 type checking on the arguments passed and to create the method selector passed as the first argument.
282283 args: A list of arguments to pass to the application. The values in this list depend on the kind of argument you wish to pass:
@@ -310,10 +311,10 @@ def ExecuteMethodCall(
310311 def MethodCall (
311312 cls ,
312313 * ,
313- app_id : Expr ,
314+ app_id : Expr | None ,
314315 method_signature : str ,
315316 args : list [abi .BaseType | Expr | dict [TxnField , Expr | list [Expr ]]],
316- extra_fields : dict [TxnField , Expr | list [Expr ]] = None ,
317+ extra_fields : dict [TxnField , Expr | list [Expr ]] | None = None ,
317318 ) -> Expr :
318319 """Adds an ABI method call transaction to the current inner transaction group.
319320
@@ -323,6 +324,7 @@ def MethodCall(
323324
324325 Args:
325326 app_id: An expression that evaluates to a `TealType.uint64` corresponding to the application being called.
327+ If the call is meant to create an application, the value `None` should be passed
326328 method_signature: A string representing the method signature of the method we're calling. This is used to do
327329 type checking on the arguments passed and to create the method selector passed as the first argument.
328330 args: A list of arguments to pass to the application. The values in this list depend on the kind of argument you wish to pass:
@@ -344,14 +346,16 @@ def MethodCall(
344346
345347 from pyteal .ast .abi .util import type_spec_is_assignable_to
346348
347- require_type (app_id , TealType .uint64 )
348-
349- # Default, always need these
349+ # Start collecting the fields we'd like to set
350350 fields_to_set = [
351351 cls .SetField (TxnField .type_enum , TxnType .ApplicationCall ),
352- cls .SetField (TxnField .application_id , app_id ),
353352 ]
354353
354+ # In the case of an app create, the `app_id` arg may be `None`
355+ if app_id is not None :
356+ require_type (app_id , TealType .uint64 )
357+ fields_to_set .append (cls .SetField (TxnField .application_id , app_id ))
358+
355359 # We only care about the args
356360 arg_type_specs : list [abi .TypeSpec ]
357361 arg_type_specs , _ = abi .type_specs_from_signature (method_signature )
0 commit comments