Not too long ago I tuned into a twitch session hosted by the two main developers in charge of Solana's smart contract compiler. While extolling the virtues of the Solana compiler they mentioned their latest creation: a smart contract that implemented a vending machine. This smart contract holds a variety of different tokens and offers them for sale. Each type of token is offered at fixed price and can be purchased until the local supply of that particular token is exhausted.
The full specs of this vending machine were not discussed in this session but they did mention that the implementation ended up being a rather short contract of about 600 lines of Rust code. That caught my attention. I asked them on the twitch chat why it took 600 lines since that seemed rather a lot to me. They explained that it took about 125 lines of logic and about 475 lines to setup security for the contract. They suggested that this split of 80% security code to 20% functionality code was pretty standard for Solana smart contracts. That was interesting to learn!
I made a note to make my own vending machine in Scrypto when I got the chance. That day came in mid-October when I got invited to take a quick peek at an early snapshot of Scrypto as they prepared for the APE event in November. This version was missing a number of things including badges but it was working well enough to allow me to take a stab at creating a vending machine.
Now if you have been around Radix for awhile like I have and watched and read everything they posted, you may know that they like to use a gumball machine as an example when introducing Scrypto. Way back in February Head of Product Matt Hine made two videos about the conceptual design of Scrypto and the basic model that you would use to implement a gumball and how that implementation was entirely different from how you would go about making the same thing in Ethereum or Solana. Sure enough you will find 'gumball' as a core example when you install Scrypto. It is a great little blueprint to review when you are learning the basics of the language. (I will be hosting an interactive screen share event to do just this in the very near future so join our free Rust & Scrypto Forum on discord if you want to participate.)
Building a vending machine is very much like a souped up gumball machine. For my version I decided to allow new vending machine "slots" to be added dynamically. Also slots could be refilled in case they ran out of tokens to sell. Also I added the ability to manage the machine by changing prices, emptying slots and, of course, grabbing the collected proceeds. This all worked and it took about 120 lines of code. The problem was that, without badges, there was no security for my vending machine. Accordingly it is too soon to compare my version with the Solana version. Still my preliminary test suggests that coding with Scrypto (which is practically the same as writing with Rust) can save a lot of time just based on looking at the respective line counts.
So my next step with my vending machine project is to incorporate badges and thereby add in the security that this blueprint needs. I plan to do this work during yet another interactive screen share event on my Forum and so perhaps you will join me then and help me make sure that the security is rock solid. If someone can track down the basic specs on the Solana vending machine implementation for me then I can try to make sure and match them. At that point we can start to see how Scrypto really stacks up against Solana from a programmer's perspective.
Photo by Erik Mclean from Pexels