Hi everyone, I’m new to PyTeal and Algorand and I would like to bring to Algorand a project written in Solidity concerning a voting system.
In short words, a smart contract allows admins to create surveys and add a certain number of participants to the survey vote.
An NFT representing the voting form of that survey is minted and transferred to each user account.
To keep track of individual votes when a user votes, the voting data is saved in the NFT metadata.
Problem n.1: Users do not need to have algos in order to use the system.
My solution: I will use a central account to make transactions and hold NFTs and will insert a proxy system so that votes are only accepted if previously signed by the user’s private wallet key.
Please tell me if you know other solutions and if my idea is feasible, thank you!
Problem n.2: In Solidity it is easy to save the associations between accounts, nft and survey with the smart contract but in PyTeal I don’t understand how could that be possible. Having only unsigned int and bytes as data types to store, how could I use a struct, a mapping, an array and a combination of them like in Solidity?
I would also like to know what are the reasons that led the Algorand team to only support uint and bytes for the data to be stored.
On problem 2, most structs, lists, etc can be converted to byte arrays which can be stored in local or global state. That said, writing teal or Pyteal to manipulate or read the structs inside the contract can be difficult. The Beaker project implements some key functionality that makes handling this a lot easier. Note that with any smart contract you are limited to Global or Local state. This is not much (global 64 k/v pairs, local 16 k/v pairs). That said Boxes will be coming to Algorand smart contracts very soon and you will be able to use as much storage as you want in your contract, if you are willing to up your minimum balance requirements. I would suggest you look at the beaker project which is documented here: https://algorand-devrel.github.io/beaker/html/usage.html
And a specific example of storing structs in local state here: