Skip to content
This repository was archived by the owner on Jul 10, 2020. It is now read-only.

Repository files navigation

Laksa-Node-Example

Usage

  1. git clone
  2. yarn install && yarn watch:hot
  3. open browser and access: http://localhost:3000/laksa/isConnected
  4. or you can curl in your bash command
$bash curl http://localhost:3000/laksa/isConnected
true#if return ture, your local node server is connected to Zilliqa

or like this

$bash curl curl http://localhost:3000/laksa/getBalance\?address\=9bfec715a6bd658fcb62b0f8cc9bfa2ade71434a
{"balance":0,"nonce":0} # return the balance of requested address

Edit your restful API

There are 2 places you need to edit.

  1. /src/services/restful/laksa.js
  2. /src/router/restful.js

If you are familiar with laksa, you can see laksa.js is pretty simple

exportconstisConnected=async()=>{constresult=awaitlaksa.isConnected()returnresult}exportconstgetBalance=asyncreq=>{const{ query }=reqconstresult=awaitlaksa.zil.getBalance({address: query.address})returnresult}// try to add thisexportconstgetNetworkId=async()=>{constresult=awaitlaksa.zil.getNetworkId()returnresult}

Then , in the resful.js

constrouterTable=[{method: 'get',name: '/isConnected',exec: laksa.isConnected},{method: 'get',name: '/getBalance',exec: laksa.getBalance},// add this{method: 'get',name: '/getNetworkId',exec: laksa.getNetworkId}]

Save both files, and the server will build rebuild itself

then you can see if the restful API works:

$bash curl http://localhost:3000/laksa/getNetworkId
TestNet # if the api works, it will return the result

About

wrap up laksa to restful service for nodejs

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages