Basic questions regarding the creation of smart contracts

Hi guys, so I have a couple of questions if I may:

  1. Algorand comes with 4 different programming languages, namely Python, JAVA, Go and JavaScript. My question would be do all these different SDKs implement the same features / functionalities / modules? Is there an SDK which is ahead / is favored over any other in terms of updates?

  2. “Algorand Smart Contracts are implemented using a new language that is stack-based, called Transaction Execution Approval Language (TEAL).”

Does this mean that smart contracts cannot be implemented using only functions from any of the 4 SDKs mentioned above? From what I gather the answer would they CAN be implemented using only the SDK methods but the way to do it would be through TEAL-binding. If that is so, at what level we introduce TEAL’s bytecode?

“TEAL runs in Algorand nodes as part of testing a proposed transaction to see if it is valid and authorized to be committed into a block. (…) SDK native language functions can be used to encode the parameters to the TEAL program correctly.”

So this means that TEAL is a seperate / independent process running inside the network nodes? An independent process from the nodes themselves that are running on the same machine?

  1. “TEAL is essentially an assembly language.”

Isn’t everything essentially assembly language? What can you comment on this remark.

  1. Where does PyTEAL fit into all of this? If I can communicate with TEAL with any of the SDKs by passing arguments in the methods, why would I need PyTEAL at all considereing that I don’t want to create and implement my own fork of Algorand and run a seperate main net. I simply want to use Algorand’s API and its main net to implement smart contracts for my dapp.

I hope I was somewhat clear with my questions and look forward to hear from you guys. Thank you in advance for any clarification.

1 Like
  1. I do not think there is really an SDK that is favored.

  2. Smart contract ASC1 are implemented in TEAL, which is a new language. TEAL scripts are executed by the Algorand node. It is not an independent process.

To write a smart contract:

a. You need to write the TEAL program (or use PyTEAL to generate the TEAL program).
b. Then you need to compile the TEAL program (which can be done using the goal command or the SDK connected to a V2 algod endpoint with compile endpoint enabled). See https://developer.algorand.org/docs/features/asc1/goal_teal_walkthrough/#compiling-teal-options and https://developer.algorand.org/docs/reference/rest-apis/algod/v2/#post-v2tealcompile
c. You need to use the SDK to generate transactions making use of the smart contract.

There are many tutorials, such as https://developer.algorand.org/tutorials/periodic-payment-using-pyteal/ showing all these steps. The official documentation is https://developer.algorand.org/docs/features/asc1/

  1. A TEAL source code almost directly matches the generated bytecode (modulo the way constants are stored). This is a very low-level language. The compiler is more an assembler: just converting the op-code to the correct bytes and doing a little bit of syntax sugar. But there is no complex compilation step, as for any higher-level language such as C, Python, …

  2. PyTEAL is a way to generate more easily a TEAL script. The TEAL language is low-level and require thinking of stack management for example. PyTEAL simplifies the writing of TEAL scripts. But at the end of the day, the Algorand node is only executing TEAL bytecode compiled from TEAL scripts. PyTEAL is never seen by the Algorand node.

Remark: current TEAL is stateless and is different from usual smart contracts on Ethereum for example. You cannot really “interact” with it. TEAL only approves or rejects transactions. Despite this apparent limitation, using TEAL in conjunction with ASA and atomic transfers allows to implement very complex logic, including auctions and small games such as https://developer.algorand.org/solutions/algonim/

2 Likes

Update: TEAL is now stateful.