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 🙏

© 2025 – Pkg Stats / Ryan Hefner

layagcs

v0.0.16

Published

Block Chain Game Engine SDK

Downloads

7

Readme

LayaGCS ( Laya Game Chain SDK)

LayaGCS是一个基于ETH的链互SDK,内置了钱包功能,智能合约调用,web3实例,以及一些基础界面,可以非常方便的让H5游戏接入。

LayaGCS运行需要Laya Air环境(请参阅https://www.layabox.com/)

Updates

加入了签名算法库,用于签名Laya.Cloud前端的前后包关联

    LayaGCS.ethSign.verifySignature
    LayaGCS.ethSgin.sign

Installation

npm install layagcs

Hello LayaGCS

初始化


    var LayaGCS = require('layagcs');

    //初始化Laya Air环境
    var SCREEN_WIDTH = 1136;
	var SCREEN_HEIGHT = 640;
    Laya.init(SCREEN_WIDTH, SCREEN_HEIGHT,Laya.WebGL);
     
    //初始化LayaGCS
    LayaGCS.initlize({
        laya_stage_node:laya.stage,     //Laya Air根节点
        network:0                       //ETH区块链网络(0位测试网络ropstenTestNet , 1为正式网络MainNet)
        auto_load_last_account:false    //自动读取上次登入的账户
    })

使用例子

调用智能合约


    var web3 = LayaGCS.web3;
	var wei = 1000000000000000000; // 10^18
	var gooAbi = require('./gooabi');

	var gooContract = web3.eth.contract(gooAbi).at('0x57b116da40f21f91aec57329ecb763d29c1b2355');

	if(LayaGCS.get_current_account() == undefined){
		LayaGCS.show_login_ui(Laya.stage);
		return;
	}

	/*
		测试读取合约数据
	*/	
	gooContract.getGameInfo(function (err, result) {
		var time = result[0].toNumber() * 1000;
		var totalPot = result[1].toNumber() / wei;
		var totalProduction = result[2].toNumber();
		var nextSnapshot = result[3].toNumber();
		var goo = result[4].toNumber();
		var ether = result[5].toNumber() / wei;
		var gooProduction = result[6].toNumber();
		var units = result[7];
		var upgrades = result[8];

		console.log('时间',time,"总pot",totalPot,"总生产",totalProduction,'下次快照',nextSnapshot,'Goo',goo,'Ether',ether.toFixed(8),'gooProduction',gooProduction)
		
	});

在调用写操作智能合约时,请务必保证LayaGCS.web3.eth.defaultAccount不为空

Documentation

以下为LayaGCS的一些基础API,文档不断更新,详情关注 Laya.one 官网

LayaGCS.initlize()

初始化SDK以及设置LayaGCS以哪种ETH网络工作,同时会少量加载一些LayaGCS的资源,此处必须传入 LayaAir的根节点

    LayaGCS.initlize({
        laya_stage_node:laya.stage,     //Laya Air根节点
        network:0                       //ETH区块链网络(0位测试网络ropstenTestNet , 1为正式网络MainNet)
        auto_load_last_account:false    //自动读取上次登入的账户
    })

初始化成功后,游戏会出现LayaGCS的浮层游标,如图

LayaGCS.get_current_account

得到当前ETH账户地址

LayaGCS.set_inited_callback

设定加载完成回调

LayaGCS.show_login_ui

弹出账号生成导入界面,在LayaGCS没有defualt_account时,会弹出导入界面,不然则弹出账户主页面

if(LayaGCS.get_current_account() == undefined){
    LayaGCS.show_login_ui(Laya.stage);
    return;
}

LayaGCS.web3

这是一个完整的web3实例。LayaGCS的web3有一些改动。

由于LayaOne提供了一个全节点,所以游戏前端无需同步区块数据

为了更好的游戏体验,LayaGCS.web3不再提供同步方法,例如

var web3 = LayaGCS.web3
//原来同步的写法
var balance = web3.eth.getBalance(LayaGCS.get_default_account()); //同步的写法,LayaGCS不再支持
//异步调用方法co
co(function*(){
    var balance = yield function(done){
        web3.eth.getBalance(LayaGCS.get_default_account(),done)
    }

    console.log('账户余额为',balalnce)
})
//同样也支持async/await
//await web3.eth.getBlance() ...

LayaGCS.web3会拦截所有的method为eth_sendTransaction的异步方法,并自动为用户弹出交易确认界面

还是以etherGoohttps://ethergoo.io/game/ 这个游戏举例,我们做一个白色按钮调用其合约【购买基础单位】

    /*
		测试调用合约函数 - 购买基础单位
    */
    function test_call_contract(){
        gooContract.buyBasicUnit(1,1,function(err,res){
            if(err){
                console.log('购买失败',err);
            }
	    })
    }
	

当用户点击确认交易后,LayaGCS会将本次Transaction签名后,以sendRawTransaction发送至eth节点,然后由节点广播

相关合约您可以查阅0x57b116da40f21f91aec57329ecb763d29c1b2355

GCS 运行截图

其他结构

LayaGCS是整个Laya.one环节中的一部分

LayaOne由Laya.cloud, laya.chain, laya.air, laya.maker等多个大模块组成

使用LAYA GSC开发的游戏结构

Laya IDE

Laya IDE集成了Truffle.js,可以非常方便的创建和部署智能合约,并提供了相应的智能合约模板

LayaIDE界面

创建游戏(合约)

编译合约

校验签名

部署合约

关于Laya.One

IDE的发布以及更多模块请关注https://laya.one以及https://layabox.com