dApp Development Workshop part 1/3 — Solidity++

Wes Erickson
4 min readSep 11, 2021

This writeup is a supplement to a live Gitcoin hackathon workshop (see video here on youtube). There may be additional information in the video workshop. Writeups for parts 2 and 3 will be released along with the next live workshops.

In this workshop series we’re going to build a full dApp for the Vite blockchain from scratch. This includes the on-chain smart contract (part 1, Solidity++), the javascript glue used to interact with this smart contract (part 2, Vite.js), and a very basic front-end (part 3, Frontend).

For those new to Vite, transactions are free and take around 1 second, which also applies to calling a smart contracts. This makes it an ideal platform from a user’s perspective, while also making possible a variety of applications which simply are not feasible on the gas-based economic model used in Ethereum and similar EVM platforms.

This workshop is only meant to get you started learning the platform, and so I will try to make each part of our project simple, while still giving you some ideas on how you can improve the design. If you get stuck, come to the Vite Discord for help or read through the documentation or other references at the end.

1. What are we buidling?

For this workshop we’re going to create a very simple guessing game! In the early days of Ethereum there were actually a lot of small dApp games that have all disappeared, but Vite’s feeless design makes this possible again.

Our game will be extremely simple: secret “answers” along with a reward will be submitted by whoever deploys the contract, and users will attempt to guess the answers to earn the rewards.

Simple Guessing Game

So how will the game work?

The game has only two functions we need to implement:

  • Fund: The owner of the contract must be able to submit secret answers along with a reward for each.
  • Guess: Users of the contract must be able to guess the secret answers, and will earn the posted reward when they guess correctly.

But how do you have secrets on a blockchain?

We must be careful, as all data on a blockchain, including contract data, is public. To overcome this we can make use of a hash function. Cryptographic hash functions are one-way functions that input data of arbitrary size and output a fixed size “hash”. They have some important properties such as the same message always results in the same hash, and it is infeasible to generate a message that yields a given hash value (here’s a nice introduction).

So the contract owner can now submit a hash of the secret answer instead of the answer, and we have that:

  • Even knowing the hash (public on the blockchain), it is virtually impossible to derive the secret answer.
  • While knowing the answer, it is easy to check that it has the correct hash.

2. Setup Solidity++ Environment

Let’s get started. You’ll first want to follow the VSCode installation Guide for Solidity++. I recommend following all the steps including compiling and deploying the basic HelloWorld contract to familiarize yourself with the environment.

3. Write the Contract

Here’s the full contract we’ll be using, I’ll walk through the logic writing it in the video.

4. Test the Contract

How do we test this contract? To test on a local debug node, all we need to do is start the debugger (F5 in VSCode), deploy the contract, fund a hash, and try guessing.

We will need a test guess/hash pair for testing. The hash function used in Vite is the BLAKE2b-256 Hash (blake2b algorithm with a 256 bit digest). To generate this hash for the word “password” we can use the following shell command

echo -n password | b2sum -l 256

which returns the hash

344b8a854221bd1eaf9382daaea1996fbcd496f158e983f8835c7ef5084c55bb

Or you can use an online tool such as this one here: https://www.toolkitbay.com/tkb/tool/BLAKE2b_256

5. Deploy To Testnet

So far we have been testing on a local debug node, but this does not allow us to test Quota consumption, balance checks on transactions, and operation in a more realistic setting. Here’s an outline of deploying onto the testnet:

  • Copy your Mnemonic Words from the debug settings and set up a wallet at https://buidl.vite.net/.
    Careful: This is not recommended for accounts with real Vite. We’ll cover a more secure approach in a later session.
  • Go to the #faucet channel in the Vite Discord and request some test Vite with the command !send YourViteAddress
  • Lock Vite to generate Quota for your account.
  • Deploy your contract onto the testnet and record the contract address.
  • Lock Vite to generate Quota for the deployed contract.

Once this is complete, we can test the contract like we did earlier.

6. Closing / Recommended Reading

Thanks for participating! I’ll be hanging around Discord if you have any more questions, feel free to ping me (wes_is_ok#3196).

If you’re new to Vite there’s a lot we didn’t cover, so you may find it interesting and helpful to read some of the following pages:

Resources

--

--