Introducing the PyTEAL debugger

Jonathan Rivera
Web Zero
Published in
3 min readJul 20, 2022
Photo by Markus Spiske on Unsplash

At least I did when I was starting, but I remember imagining I was building the new Facebook or Twitter when I learned how to code. I imagined that all it took was a couple lines of code and then…. boom! There I was with a new Twitter. Then reality had another humble reminder. Bugs! See like any other engineer or creator, when we build something with a whole ecosystem of its own, its bound to have some sort of hurdles along the way. we create something and expect nothing to pop up along the road? How about a new bike we built and assembled. Was I really expecting that there wouldn’t be a missing part or screw that falls off AFTER I assembled it? What was I thinking? But don’t worry, keep reading. See, just like mechanics, we have tools which can help the tools when the tool doesn’t work. In the world of software development, we have these tools. One of the best ways to fix these ‘missing bolts’ or as we refer to them, Bugs. We have a great tool for fixing these bugs. This is where Algorand steps in.

Teal Debugger

Smart contracts are built using the versatile language called Teal. We built these programs to interact and execute a certain actions based on conditions. These programs very often run into bugs and kinks along the road. When we are building on the Algorand blockchain, there are actually 2 eays we can debug smart contracts. thr Interactive debugger is the first method, we use this with the tealdbg command line tool. Once we start the debug, the smart contract is checked to see what we can find that needs to be fixed. the second method is to check line by line frather then the whole smart contract at once. This command line is goal clerk dryrun-remote

Please refer to the Readme below for more details:

So how do we get started? Im guessing you have found a couple little buggers if you’re reading this. Well lets get to it then! First thing we have to do is run the Debugger, like show below.

$ tealdbg debug myprog.teal
$ tealdbg debug samples/calls_count.teal --balance samples/calls_count_balance.json --txn samples/calls_count_txn.json --proto=future
$ tealdbg debug samples/calls_count.teal --proto=future --painless

It will create a URL to follow. Like shown below. You want to open it on Google Chrome or Chrome DevTools. Refreshing the page will be needed.

devtools://devtools/bundled/js_app.html?...

Another great resource for more detail, please refer to the below link:

This will launch the debugger process, it will be connected automatically to the Chrome Developer Tools. Then use the chrome://inspect/ into the address bar and click CONFIGURE. Use the example below to launch the debugger.

tealdbg debug program.teal --remote-debugging-port 9393

So lets evaluate what we have done thus far. Please refer to reference below. We use thecommandDebugger

type DebuggerHook interface {
// Register is fired on program creation
Register(state *DebugState) error
// Update is fired on every step
Update(state *DebugState) error
// Complete is called when the program exits
Complete(state *DebugState) error
}

One other great resource is a YouTube tutorial on debugging from Algorand itself. Refer to video below:

https://www.youtube.com/watch?v=_CMsyv4yjhE

So this is a gateway to the arsenal of tools of the Debugger. This alone will eliminate headaches and get you back on the building road. Refer to the links provided and use the examples to start the launcher. I can now imagine myself when I was learning to code, thinking all I did was build and then I had a Twitter. Little did I know that Algorand PyTeal Debugger was the tool that helped the tool when the other tools were down.

--

--