--- layout: learn permalink: /:collection/:path.html image: /assets/img/zero-to-dapp.png --- # 3 - Build an Animal Kingdom DApp {:.no_toc} **Zero to DAPP 3 of 4** In this page, you follow a tutorial which builds, runs, modifies, and deploys a DApp called Animal Kingdom. Through this exercise, you'll learn about the components of a Blockstack Dapp. You'll also learn about the technical requirements for submitting a DApp for App.co. This page contains the following topics * TOC {:toc}
It isn't a good idea to skip this page, requirements for DApps that participate in App Mining are covered. So, everyone should at least skim through this page.
Command | What it does |
---|---|
ls |
Lists the files and directories in the current directory. |
cd |
Change directory to navigate to locations in your file system. |
pwd |
Print the working directory, the location you are working in. |
Click to enlarge | Description |
---|---|
Users log in (authenticate) with a Blockstack identity. By authenticating, the user gives the application the ability to get and put data in the user's Gaia storage hub. |
|
The Blockstack login dialogs are part of the Blockstack Browser which is itself a DApp. Once a user authenticates, the DApp code automatically returns them to the Kingdom they were attempting to enter. |
|
First-time visitors to a kingdom are prompted to create an animal persona and a territory to rule. Once they make a selection, users click Done to create a kingdom to rule. Behind the scenes, the data about the user's selection is stored in the user's GAIA hub. |
|
Each kingdom has animals and territories. Users can edit their original persona/animal combination. You'll learn how to modify the Animal Kingdom code to add new animals and territories. |
|
Users can add subjects from territories in their own Animal Kingdom. The DApp updates the user's GAI hub each time the user adds a subject. Users can also visit other Animal Kingdom installations and add subjects from these as well. You'll learn how to modify the Other Kingdoms available in your installation. |
Name | Description |
---|---|
README.md |
Contains a quick reference for building and running Animal Kingdom. |
package.json |
An NPM project file. |
config |
Environment configuration files written in Javascript. |
public |
Files that are copied into the root of the site you are building. |
scripts |
NPM scripts used to do common tasks in the project. |
src |
React source code for the site. This contains configuration files. |
To participate in application mining your application must integrate Blockstack authentication.
putFile()
stores the data provided in the
user's DApp data store. You can view the URL for the data store from a user's
profile. If you tested your Animal Kingdom, you can see this on your profile.
To see your profile, go to the Blockstack explorer and search for your ID:
In the next section, you extend your Kingdom's configuration.
To participate in application mining your application must make use of Gaia storage.
.jpg
extension.
For this example, the territory image is saved in the westeros.jpg
file." %}
4. Use the `ls` command to confirm your file appears in `territories` directory and has the correct name.
```bash
ls public/territories/
forest.jpg tundra.jpg westeros.jpg
```
4. Open the `src/constant.js` file in your favorite editor.
5. Scroll down to the section that defines the **Territories**.
```js
export const TERRITORIES = [
{
id: 'forest',
name: 'Forest',
superpower: 'Trees!'
},
{
id: 'tundra',
name: 'Tundra',
superpower: 'Let it snow!'
}
]
```
6. Add your new territory.
```js
export const TERRITORIES = [
{
id: 'forest',
name: 'Forest',
superpower: 'Trees!'
},
{
id: 'tundra',
name: 'Tundra',
superpower: 'Let it snow!'
},
{
id: 'westeros',
name: 'Westeros',
superpower: 'The Iron Throne!'
}
]
```
7. Save and close the `constant.js` file.
8. Back in a terminal window, restart your application.
```bash
$ npm start
```
9. After the application starts, navigate to the **Territories** page and look for your `Westeros` territory.
### Add the Blockstack kingdom
{:.no_toc}
Your Animal Kingdom has only recognizes two **Other Kingdoms**. In this section,
you add a third, the Blockstack kingdom (`https://animalkingdoms.netlify.com`).
1. Open the `src/constant.js` file in your favorite editor.
On Mac you can use TextEdit or Vim.
2. Scroll down to the section that defines the **Other Kingdoms**
```js
export const OTHER_KINGDOMS = [
{
app: 'https://animal-kingdom-1.firebaseapp.com',
ruler: 'larry.id'
},
{
app: 'http://localhost:3001',
ruler: 'larz.id'
}
]
```
To add a kingdom, you need its URL and the ID of its owner.
3. Edit the file and add the `https://animalkingdoms.netlify.com` which is owned by `moxiegirl.id.blockstack`.
When you are done the file will look like this.
```js
export const OTHER_KINGDOMS = [
{
app: 'https://animal-kingdom-1.firebaseapp.com',
ruler: 'larry.id'
},
{
app: 'http://localhost:3001',
ruler: 'larz.id'
},
{
app: 'https://animalkingdoms.netlify.com',
ruler: 'moxiegirl.id.blockstack'
}
]
```
4. Save and close the `constants.js` file.
5. Back in your browser, navigate to the **Other Kingdoms** page.
7. Got to the `moxiegirl` kingdom by clicking on her kingdom.
8. Try adding a subject from Moxiegirl's kingdom to yours.
## Go live on the Internet
In this section you use a free Netlify account and a free GitHub account to take
your kingdom live on the internet. Netlify provides hosting and serverless
backend services for static websites. GitHub is a code hosting site.
To participate in application mining your application must be available for review. Open source projects must provide the URL to their code. Projects with private repositories can provide their application in a package form.