Git Product home page Git Product logo

cryptopokemon's Introduction

Cryptopokemon

alt text

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Things you need to install:

ganache (for testing purpose)
metamask chrome extension
solidity

Running the tests

Firstly you need to deploy the smart contract on a network, for testing purpose I highly recommend you to use ganache (super fast though bug-sensitive)

Using remix

  1. Copy all the contracts to the browser ide
  2. Set up metamask connection and reload the page (make sure you see the right chainId and address in tab Run)
  3. Compile and create the contract
  4. Copy new contract's address to address variable in init.js

Run server

Run a server with django (command below) and play around with the contract with web user interface which built from pure html and javascript.

What is going on?

What is cryptopokemon?

First of all we need to gain basic insight about cryptopokemon.

There are 2 kinds of address:

  • Admin address: belongs to the one who creates the contract (you just did).
  • User address: everyone else.

There are 3 ways to get a pokemon:

  • Choosing one of the three starter pokemons: bulbasaur, squirtle and charmander. You can only do this if you have no pokemon.
  • Capturing a wild pokemon: there are 4 wild pokemons per day for everyone to catch, each of them will belong to the first one to successfully capture it. The capture mechanism is all about the probability which depends on the catchRate and level of each pokemon.
  • Buying one from someone with auction mode.

There are 2 ways to raise stats of a pokemon:

  • Feeding food.
  • Level up (by exp or direct money). There is a special type of leveling up called evolution which can be triggered in some specific pokemons at specific levels.

Last but not least, Pokemon can attack each other. A battle is a serie of turns. In each turn, two pokemons hit each other with a probability of missing depending on its speed stat and cause a damage proportional to its attack and defense stat. Pokemon with higher speed will go first in each turn and the battle ends when one pokemon runs of of hp.

How it works?

All the code will be executed on Ethereum Virtual Machine. Django is used as a back-end server which serves front-end files to build user interface. A quick recap of django usage in this project:

  • All html and javascript code will be linked with a specific url (specified in urls.py).
  • To add a new function to the whole system, we just need to create html files (with javascript included to communicate with smart contracts) and allocate a new url of django to it.
  • We do not need any database in this project so let's drop the model stuff of django.
  • To run a server with django, run:
python manage.py runserver

or (optionally) to allow other node in local network to communicate with your server:

python manage.py runserver 0.0.0.0:8000

The communication between user interface and smart contracts is based on web3.js (which is injected from metamask so don't worry about installization). Basically, all the functions and public variables of smart contract can be called and accessed with web3js. To learn more about it please check out my js code or take a look at lesson 6 of this brilliant course

Deployment

You totally can deploy this app to the main network if you want to. Just replace the ganache network by the main ethereum network. Of course, it take you money to do that :D

Authors

tailongnguyen

This project is licensed under the MIT License - see the LICENSE.md file for details

Acknowledgments

  • Hat tip to anyone who's code was used
  • Inspiration
  • etc

cryptopokemon's People

Contributors

tailongnguyen avatar

Stargazers

 avatar  avatar  avatar

Forkers

nshcore

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.