Nebulas Dapps — Part 2

Part 2: Of building Dapps on Nebulas. Continuing from Dapps Part 1.

Kafka
Coinmonks
Published in
3 min readMay 13, 2018

--

Nebulas is having a Dapp money give away. Develop a Dapp, Submit it, and get 100 NAS. Link

Lets continuing learning how to build these Dapps.

Code Source and the Dapp

iQuote Dapp Here

In order for an app to be labeled a Dapp it must communicate with a Smart Contract.

For Example: We add iPhone as the Name and iPhone 4, 5, 6, 7, 8, X as the quote. After this we click the Save Forever button which opens up the Web Wallet Extension you see on the left of the picture. Lets Examine the Contract args in the image below.

Contract args: Here we see function save with the Name — iPhone and quote -iPhone 4, 5, 6. The function save is a smart contract feature which saves our text.

Breaking up the frontEnd JavaScript that interacts with a Smart Contract.

The add2Contract function:

The add2Contract function will add a name and a message to the blockchain by interacting with the smart contract with the help of window.postMessage

The window.postMessage communicates to the Smart Contract below

save function

Here the save function allows us to save the key and value to the blockchain. Basically, the save function accepts a key and value string. It checks if the key has been used before if not puts the key and value to the blockchain.

Smart Contract below

The search function

The search function interacts with a Nebulas Smart Contract. Try searching for iphone.

This feature allows you to search names that were entered on Nebulas blockchain. Below is the frontEnd code used to communicate with the smart contract.

The code below is the piece of the smart contract that allow the user to search for a name. The key is the name.

The function below checks if the page was loaded then runs checkNebPay

The checkNebPay checks if you installed the Web Wallet Extension if not gives a warning and a link to download it.

Web app + Smart Contract = Dapp

With this knowledge you could easily build a simple game and save users score + name to the blockchain. That would be an easy way to earn some NAS. Hell you could even use my smart contract as is with no modification.

--

--

Kafka
Coinmonks

“Genius” is 1% inspiration and 99% perspiration. Accordingly, a ‘genius’ is often merely a talented person who has done all of his homework — T.E.