If I had the following app, but would like it to be called when someone sends an Algo payment to the app address rather than a regular app call, how would I implement that?
#pragma version 8
// deploy on creation
txn ApplicationID
int 0
==
bnz deploy
itxn_begin
int pay
itxn_field TypeEnum
int 20000
itxn_field Amount
txn Sender
itxn_field Receiver
itxn_submit
deploy:
int 1
return
As far as I understand, app/smart contract code is only “triggered by a specific type of transaction called an Application Call transaction”. (source: Introduction - Algorand Developer Portal)
In theory you could create a smart signature to authorize spending from an account, but it would also need a special transaction, not just a plain send. It is hard to know if it would help you. What do you want to achieve? What are the requirements to fulfill? (missing the big picture)
You can do this with stateless apps… you do not have to deploy app. the hash of the stateless app is the address and it can have its balance
so the code would be just
#pragma version 8
itxn_begin
int pay
itxn_field TypeEnum
int 20000
itxn_field Amount
txn Sender
itxn_field Receiver
itxn_submit
int 1
return
The problem with this code is:
anyone can rekey this stateless app
anyone can call this app, so whatever balance is there anyone can steal it
The stateless apps or logic sigs is old name for this… The current name is smart sig account.
Also I feel that algorand tries to not continue with the stateless apps as it does not have currently all features of the standard deployed apps… You cannot check the current round or time, or you cannot do app calls to it from other apps.
Also nowadays it is much better to create ABI compatible apps. Just check the pyteal, beaker, or tealscript which can create all artifacts for you. It is quite easy… depends on wheater you prefer the python (go with beaker) or if you prefer typescript (go with typescript)