Skip to content

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

License

Notifications You must be signed in to change notification settings

ceo777/diesel-attack-nft

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published