Coder Social home page Coder Social logo

ceo777 / diesel-attack-nft Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 313 KB

Diesel Attack game backend server deploying smart contract on the NEAR blockchain to mint NFTs for players. Created on the NEAR Rust SDK.

License: Apache License 2.0

JavaScript 39.40% Shell 2.88% Rust 57.72%
api blockchain near near-protocol nft nodejs rust wasm

diesel-attack-nft's Introduction

Diesel Attack NFT Game Backend API Server

Welcome to the cyberpunk post-apocalyptic world of Diesel Attack

Diesel Attack NFT Game Gameplay

To earn and collect NFTs during the game you need a NEAR Wallet Account (on the testnet). We never ask you for keys.

Table of Contents

About

This is the source of the backend API server of the RPG 2D-sidescroller game Diesel Attack. It implements smart contract on the NEAR blockchain to mint NFTs for players during the game on the fly. When a game client app sends a request to the server using API, a player gets a new weapon or ship as NFT based on the weighted random algorithm. Created on NEAR RUST SDK. NFT arts are hosted on IPFS. The server itself is running on Fastify (Node.js framework).

API Usage

API methods

Status

GET /api/ returns greetings message (server status check)

Production server endpoint:

https://v1.dieselattack.com/api/

Mint NFT

GET /api/mint-nft?nearid=<username.testnet> mints NFT for player and returns a code of the collectible to a game client app. Where <username.testnet> is the player's NEAR account on the testnet.

Production server endpoint:

https://v1.dieselattack.com/api/mint-nft?nearid=username.testnet

You can check it by yourself and mint NFT to your NEAR testnet account. No authentication needed. Just put your Testnet account address instead of username, browse it and check your NEAR wallet Collectibles section.

Server's NFT contract address: nfts.dieselattack.testnet (See in Explorer)

Security

โš ๏ธ For the duration of the NEAR MetaBUILD III Hackathon we left the possibility to check and mint NFT via API link for everyone intentionally. But minting NFT is a non-free operation and there is a vulnerability. Users can abuse the contract, and it may run out of Gas. To prevent this in production on the mainnet you SHOULD use the secret appkey token, where secret_token is something like QmFzZTY0IGVuY29kaW5nIG9:

GET /api/mint-nft?nearid=<username.testnet>&appkey=<secret_token>

How To Build

Prerequisites

References to the original documentation:

Installing the prerequisites
  1. Sign up to the NEAR Testnet Wallet and follow the instructions: https://wallet.testnet.near.org

  2. Install Rust with Rustup tool (recommended):

    curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
  3. Install Wasm32:

    rustup target add wasm32-unknown-unknown
  4. On Ubuntu you may need to install Build-essential:

    sudo apt install build-essential
  5. Install NVM (Node.js version manager):

    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash
  6. Add these lines to your ~/.bashrc, ~/.profile, or ~/.zshrc file to have it automatically sourced (you may need to restart the session):

    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
    
  7. Install the latest LTS version of Node.js:

    nvm install --lts
  8. Install NPM package manager:

    npm install -g npm@latest
  9. Install Near-cli globally:

    npm install -g near-cli
  10. Install Corepack (Yarn version manager):

    Node.js >=16.10:

    corepack enable

    Node.js <16.10:

    npm i -g corepack
  11. Activate the latest global Yarn version:

    Node.js ^16.17 or >=18.6:

    corepack prepare yarn@stable --activate

    Node.js <16.17 or <18.6:

    Take a look at the latest Yarn release, note the version number, and run:

    corepack prepare yarn@<version> --activate

Build the contract

  1. Install all the dependencies:

    yarn
  2. Build the smart-contract into WebAssembly:

    yarn build

Deploy to the Dev account

  1. Deploy the contract to the dev account:

    yarn deploy:dev
  2. Run the local server:

    yarn start:dev

Deploy to the Testnet account

  1. Login to the testnet account:

    near login
  2. Set your values for CONTRACT and MASTER_ACCOUNT in the deploy script ./scripts/deploy.sh.

  3. Make sure you have the executable permissions on the deploy script:

    sudo chmod +x ./scripts/deploy.sh
  4. Deploy the contract to the testnet account:

    yarn deploy
  5. Set your value for CONTRACT_NAME in the account config file ./config/testnet-account.env

  6. Run the local server:

    yarn start

Tests

  • Run the testnet account test:

    yarn test
  • Run the dev account test:

    yarn test:dev
  • Run the local server test:

    yarn test:server

diesel-attack-nft's People

Contributors

ceo777 avatar

Watchers

 avatar

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.