How to store/retrieve data from a Smart Contract

Hi everyone, first post here.

I’ve been an Ethereum developer for more than 2 years and this weekend I found Algorand and it seems to be very promising!
So I started to read the developers’ docs and I’ve also put a node online (mainnet) on one of my DigitalOcean droplets.
To keep playing around I’ve opted to use the Docker sandbox on my local machine (testnet).

One thing that I didn’t get it right is the proper way to set and get data from a Smart Contract (account).
I understand that a user can leverage the note field of a txn to insert some data there.
But I’m still not able to figure out how another user can interact with this note.

Let me try to elaborate better using an example:

1 - Alice wants to “create” a game in the real world and using virutal prize (ALGO).
So she initiates a Smart Contract with 100 ALGO and a note with the participants of the game:

note = {
        "amount": 100,
        "participants": "",
        "winner": "",
        "rules": "BlaBlaBla",
        "expiration": 7000000
}

2 - Alice then invites Bob to join her game, in order to do that, Bob needs to send 1 ALGO to the Smart Contract and update its notes.
But first Alice needs Bob’s account to make him able to participate:

3 - Alice adds Bob to her game’s note:

note = {
        "amount": 100,
        "participants": "[BobAddr]",
        "winner": "",
        "rules": "BlaBlaBla",
        "expiration": 7000000
}

4 - Now Bob is able to interact with the Smart Contract (game) <— here is my question!
My goal is to make the Smart Contract read the “participants” list and validate that Bob’s Address can participate and by that accept his txn.
Bob’s txn has to, besides send 1 ALGO, insert his account as the “current” winner:

note = {
        "amount": 101,
        "participants": "[BobAddr]",
        "winner": "BobAddr",
        "rules": "BlaBlaBla",
        "expiration": 7000000
}

5 - So the next players can do the same and even Bob can send more ALGO to keep his account as the current winner.

How can I proper handle this data set/get workflow?

PS1: I know that the game is dummy! :sweat_smile:
PS2: Maybe I’m still to biased with Ethereum’s Solidity… :sweat_smile: :sweat_smile:

PS2: Maybe I’m still to biased with Ethereum’s Solidity… :sweat_smile:
Yes, you are.
Algorand Smart Contracts can’t handle the txn note field.

Thanks @Maugli!
Yeah, the note field is a transaction field only, I thought that it is also a Smart Contract field =/

Algorand Smart Contracts can’t handle the txn note field.

So to achieve what I want I need a central component to keep tracking the current “participants” list and “winner” etc values, right?

“So to achieve what I want I need a central component to keep tracking the current “participants” list and “winner” etc values, right?”

Yes, I think so.

Indeed, current (stateless) TEAL contracts on Algorand only allows you to accept or reject a transaction based on the fields of the current transaction. In particular they can read the value of the note field of the transaction to be accepted or rejected. But they cannot read any note field from a previously committed note field.

Using a central component out-of-chain is indeed a possibility.

Another possibility is to combine smart contracts (ASC1) with assets (ASA, https://developer.algorand.org/docs/features/asa/) and group transaction / atomic transfers (https://developer.algorand.org/docs/features/atomic_transfers/).

What makes ASC1 / TEAL much more powerful than what it looks like at first glance is that a TEAL script can also check the fields of the transactions in the current group of transaction to be accepted or rejected. You can then use ASA to “store” some data.

For example, it is possible to do a Dutch auction in TEAL (https://github.com/algorand/pyteal/blob/master/examples/dutch_auction.py) and I am almost sure your example is also possible in TEAL using multiple ASAs in creative ways.

1 Like

Got it, @fabrice…will take a look on these links.
Thanks!