npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

play2earn

v0.0.10

Published

Convert any web2 game in play2earn game

Downloads

11

Readme

Play2Earn

Play2earn is a package used to convert any Nextjs game into a play2earn game with Solana blockchain integration.

  • Integrate with solo games
  • Integrate with multiplayer games
  • No knowledge of Solana / Rust / Blockchain required
  • Possibility to switch between Devnet and Mainnet easily

You can read the documentation here:

Documentation Web2To3

Demonstration

Solo Game

An example of a 2048 Game (solo) converted into play2earn (if you finish it under a time period) can be found here:

2048 To Earn Demo

The code can be found here:

2048 To Earn - Code

Multiplayer Game

An example of a chess game converted to a chess2earn game (between two players) can be found here:

Chess2Earn Demonstration

The code associated is available here:

Chess2Earn - Code

More examples of integration to come!

Getting Started

Compatibility

Your project needs to use React 17 or later. For deployment and production use cases, you also need to use Nextjs 12.2 or later to secure the transaction.

Backend Set-up

In order to make the transaction secure and verify that no one is cheating, play2earn needs to integrate with the backend of Web2To3. Read the documentation here to see how to create a game and use the API key associated.

Installation

Add Play2Earn modal to your project by executing npm install play2earn or yarn add play2earn.

Usage

Here's an example of basic usage:

import { Play2EarnModal, finishGameAndGetMoneyWebThree } from "play2earn";
<Play2EarnModal gameWebsiteHost="chess2earn.com" 
                gameID={gameID}
                playerUID={user?.uid} 
                handleGameStarting={() => handleGameStarting()}
                secondsBeforeCancellation={60} />

You also need to add the function which is triggers when the game is starting (i.e after the one/two players have bet in case of solo/multiplayer game).

async function handleGameStarting() {
    console.log('Updating when the second player has accepted the bet.');
    // WRITE_YOUR_LOGIC_HERE...
}

Then, you need to add the function to end the game when one player has won.

// Call this function when the game is finished with the winnerID
finishGameAndGetMoneyWebThree(process.env.NEXT_PUBLIC_WEBSITE_HOST, gameID, winnerID, winnerID, false)
    .then(resultSignature => {
        console.log('The money has been transferred to your account, the signature is: ', resultSignature);
    });
}

Props

|Name|Type|Default|Description| |:--|:--:|:-----:|:----------| |gameWebsiteHost|string|required|The ID of your website, needs to match the one added in the backend.| |gameID|string|required|A unique ID to identify each game, you can use the Date().| |playerUID|string|required|The ID or username of the player. Better if it is unique.| |handleGameStarting |function|undefined|Callback when player have bet.| |gameType|string|solo|The game type, solo or multiplayer.| |numberMultiplayers|number|2|The number of players in case of multiplayer game.| |blockchainType|string|solana|The blockchain used for the betting.| |network |string|devnet|The network used, choice between devnet and mainnet.| |amountBet|number|0.1|The amount bet of blockchain's currency.| |secondsBeforeCancellation|number|60|The number of seconds before cancellation of betting in multiplayer game.|

gameWebsiteHost

gameWebsiteHost is the ID to identify your game application. You need to register it in the backend of Web2to3 first and match the one registered there.

gameID

gameID is the identifier of a game started by a player. It needs to be unique. You can use the timestamp to generate unicity.

playerUID

playerUID is the I### onTick onTick is a callback and triggered every time a new period is started, based on what the D or username of the player. In case of multiplayer, make sure that it is unique within the game started.

handleGameStarting

handleGameStarting is a callback and triggered after all players have bet and the game is ready to start.

gameType

gameType specifies the type of game played, i.e solo or multiplayer.

numberMultiplayers

numberMultiplayers is the number of players in case the gameType is set to multiplayer. Default is 2 players.

blockchainType

blockchainType is the type of Blockchain used for currency and transaction. At the moment only solana option is available.

network

devnet network is used for testing or demonstration while mainnet network is used with real cryptocurrencies.

amountBet

In case the solana blockchain network is used, the amount bet is in SOL currency.

secondsBeforeCancellation

The number of seconds the player 1 has to wait before cancelling his bet in case player 2 is not willing to bet.

Memo to update and publish the package

npm login
npm version patch
npm publish

Useful links - Documentation

License

The MIT License.

Author