How do i write to another app's local put

I want to check if a user exists, if not add the user to app User from app A. Or how do I put args to user app from app A?

# get user
user_program = App.localGetEx(Int(0), Tmpl.Int("TMPL_USER_APP_ID"), Bytes("user"))
    on_add_user = Seq([
        Assert(Global.group_size() == Int(1)),
        App.localPut(Bytes('user'), Txn.application_args[5]), # ?????? like localPutEx
   ])
    # add user app if no user app
    on_set_user = Seq([
        Assert(Global.group_size() == Int(1)),
        user_program,
        Assert(Not(user_program.hasValue())),
        App.globalPut(Bytes('user'), Txn.application_args[2]),
        on_add_user,
        Int(1)
    ])

Hi @toad,

Here you have a useful summary of state operations you may execute with an Application Call to a Stateful ASC1.

If I understand correctly the title of your thread, you are asking how to write the Local State of a foreign application, with respect the target of the Application Call. Since the access to Foreign Apps of an Application Call is read only, you should pair a second Application Call to the foreign application with an Atomic Transfer.

Otherwise, if you are just trying to execute some logic within you application based on the fact that an Account has opt-in a foreign one, that you should be able to do it passing the following references through the Application Call: an Account Array and a Foreign Apps Array to let the approval program read what you need.

I already have it paired. I have 3 apps linked, but one needs a proxy app.

thanks, sorry can you give me an example in the second scenario? How would I get the corresponding account and foreign app. I think this is what Im looking for.

Imagine the following situation: I want my app to check if Alice_Account or Bob_Account have opt-in the Panzerotti_App. I can do it with the app_opted_in opcode, that requires:

params: Txn.Accounts offset (or, since v4, an account address that appears in Txn.Accounts or is Txn.Sender), application id (or, since v4, a Txn.ForeignApps offset). Return: 1 if opted in and 0 otherwise.

My pseudo-arrays for the Application Call would be something like:

AccountsArray = [0: AppCallSender_Account, 1: Alice_Account, 2: Bob_Account]
AppsArray = [0: My_AppID, 1: Panzerotti_AppID]

Then my TEAL code would be:

// Pushing Alice_Account as AccountsArray index
int 1

// Pushing Panzerotti_AppID as AppsArray index
int 1

// Popping indexes and checking if Alice_Account opted-in the Panzerotti_AppID
// Return: 1 if opted-in and 0 otherwise.
app_opted_in

// Pushing Bob_Account as AccountsArray index
int 2

// Pushing Panzerotti_AppID as AppsArray index
int 1

// Popping indexes and checking if Bob_Account opted-in the Panzerotti_AppID
// Return: 1 if opted-in and 0 otherwise.
app_opted_in

// Returns 1 if Alice_Account or Bob_Account opted-in the Panzerotti_AppID
||

Please note that I didn’t check the above code, so do not take it for granted in production.

3 Likes

oh i see! thanks for the explanation.