Giter VIP home page Giter VIP logo

crimsonzh / magnachain-dev-master Goto Github PK

View Code? Open in Web Editor NEW

This project forked from magnachain/magnachain-dev-master

1.0 0.0 0.0 15.22 MB

License: MIT License

Dockerfile 0.01% Makefile 0.46% Shell 0.39% M4 0.60% C++ 35.77% C 27.52% Python 6.87% QMake 0.01% Tcl 7.51% HTML 0.68% C# 5.54% Awk 0.02% Java 12.14% CSS 0.01% Perl 1.63% Assembly 0.09% OpenEdge ABL 0.19% XS 0.57% Perl 6 0.01% PHP 0.01%

magnachain-dev-master's Introduction

Getting Started

Download

To publish the game on MagnaChain, you need an RPC client, which can be downloaded at:

Https://developers.magnachain.co/article/downloads/

Choose your own version according to your system environment

Get the address

Run the following command in the MagnaChain directory

For Windows platform, enter:

Magnachain-cli.exe -rpcconnect=nodeIp -rpcuser=user -rpcpassword=pwd -rpcport=port getnewaddress

For Linux / Mac OS platform, enter:

Chmod +x loadlib.sh
./loadlib.sh
./magnachain-cli -rpcconnect=nodeIp -rpcuser=user -rpcpassword=pwd -rpcport=port getnewaddress

The command will return a new address like "XQSD7PUPNCf8psJdfFMjfWXKuaHXFwSFRf"

The nodeIp, user, pwd, port and other parameters in the command need to fill in the corresponding real MagnaChain node parameters.

Write a contract and publish it

In the current directory, create a new file, name it game.lua, and edit:

function init()
    PersistentData = {}
    PersistentData.killNumTbl = {}
end

function killMonster()
    --print("GJ!One monster killed by you!")
    PersistentData.killNumTbl[msg.sender] = (PersistentData.killNumTbl[msg.sender] or 0) + 1
    return true
end

function showNum()
    return PersistentData.killNumTbl[msg.sender]
end
    

For Windows platform, enter:

Magnachain-cli.exe -rpcconnect=nodeIp -rpcuser=user -rpcpassword=pwd -rpcport=port publishcontract game.lua XQSD7PUPNCf8psJdfFMjfWXKuaHXFwSFRf

For Linux / Mac OS platform, enter:

./magnachain-cli -rpcconnect=nodeIp -rpcuser=user -rpcpassword=pwd -rpcport=port publishcontract game.lua XQSD7PUPNCf8psJdfFMjfWXKuaHXFwSFRf

The command returns something like the following:

{
  "txid": "7501667a85d2c35e57258f7f165a72156f7f8d43e9c03c4fe2e59875abacd3c6",
  "contractaddress": "UpcuLWL6HcSSH5Rc5xQy6e6yEMPQZ9xvWs",
  "senderaddress": "XQSD7PUPNCf8psJdfFMjfWXKuaHXFwSFRf"
}

This indicates that your contract has been successfully released, and "UpcuLWL6HcSSH5Rc5xQy6e6yEMPQZ9xvWs" is the contract address.

Call the contract

After our game contract is released, we can play this game by calling this contract.

For Windows platform, enter:

Magnachain-cli.exe -rpcconnect=nodeIp -rpcuser=user -rpcpassword=pwd -rpcport=port callcontract true 0 UpcuLWL6HcSSH5Rc5xQy6e6yEMPQZ9xvWs XQSD7PUPNCf8psJdfFMjfWXKuaHXFwSFRf killMonster

For Linux / Mac OS platform, enter:

./magnachain-cli -rpcconnect=nodeIp -rpcuser=user -rpcpassword=pwd -rpcport=port callcontract true 0 UpcuLWL6HcSSH5Rc5xQy6e6yEMPQZ9xvWs XQSD7PUPNCf8psJdfFMjfWXKuaHXFwSFRf killMonster

Every time we execute a command, we will kill one more monster. Let's take a look at how many we killed.

For Windows platform, enter:

Magnachain-cli.exe -rpcconnect=nodeIp -rpcuser=user -rpcpassword=pwd -rpcport=port callcontract true 0 UpcuLWL6HcSSH5Rc5xQy6e6yEMPQZ9xvWs XQSD7PUPNCf8psJdfFMjfWXKuaHXFwSFRf showNum

For Linux / Mac OS platform, enter:

./magnachain-cli -rpcconnect=nodeIp -rpcuser=user -rpcpassword=pwd -rpcport=port callcontract true 0 UpcuLWL6HcSSH5Rc5xQy6e6yEMPQZ9xvWs XQSD7PUPNCf8psJdfFMjfWXKuaHXFwSFRf showNum

This command will return the number of monsters we killed.

So far, we have initially developed a game on MagnaChain. Isn’t it very easy?
For more usage, please refer to the developer website.

https://developers.magnachain.co/

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.