SingularityNET: Setting up Snet-Daemon with a Hosted Service on Local Machine

Pratik Prajapati
3 min readSep 25, 2020
credits: SingularityNET

In this article we will walk through the process of publishing service on SingularityNET and consuming it using SnetCLI with local Ethereum Blockchain.

If you don’t know what SingularityNET is about! You can go through the Core Concepts and you will get the idea what SingularityNET platform is about.

So let’s get started!!

We will use local IPFS node, Local Ethereum blockchain using ganache-cli and SingularityNET Daemon.

Requirements

  • Node >= 10.16.0 < 12.0.0
  • Python 3.6+

If the machine is Linux, You will need to install additional packages,

$ sudo apt-get install libudev-dev libusb-1.0-0-dev

We will start with creating our working directory!

$ mkdir ~/snet-setup

Installation of tools

Installing IPFS

Download the latest IPFS Daemon from here.

We will export it to the PATH so that we can use it without absolute path of IPFS binary.

$ export PATH=$PWD/go-ipfs:$PATH

Now Install SingularityNET platform contracts in local Ethereum blockchain using ganache.

We will bring up the IPFS node, with the endpoint http://127.0.0.1:5002

Start ganache and migrate platform-contracts

The address 127.0.0.1:8545 is the rpc endpoint of local Ethereum blockchain.

Now we will migrate SingularityNET platform contracts to local blockchain.

$ ./node_modules/.bin/truffle migrate --network local

This will give you an output like

...
...
SingularityNetToken: 0x296e52b3d92498b181e3a6fabc18b13283400f9e
...
MultiPartyEscrow: 0xdca2ddecf7af9011dd385d568b461c23c6257d41
...
Registry: 0xf210ff3e859c48b318c704b7377eaedec351c8d2
...
...

These are the address where our contracts are published, We will use these addresses later so better note it down somewhere.

Snet-Cli

Now we are all to publish our own organization and service into our Local Ethereum Blockchain,

Let’s start with Snet-cli!

Snet-Cli is a client to publish SingularityNET Services onto blockchain and communicate with SingularityNET services using the Multi-Party Escrow payment channels.

Install snet-cli

$ pip install snet-cli

Setting configs of snet-cli,

To interact with contract will need balance in MPE wallet. Let’s deposit 10000000 gwei into MPE wallet.

$ snet account deposit 10000000 -y -q

Publish a Service

First of all we will create an organization with name “Awesome Organization” and org ID “awesome-org”, And group with name “default_group” and payment address 0x52653A9091b5d5021bed06c5118D24b23620c529.

Let’s Publish service with name “Awesome Calculator” and service ID “awesome-calc” under organization “awesome-org”.

For that we will use Calculator as a service to publish into blockchain. We already have calculator service as example service in SingularityNET Github repo here.

Following commands will run the service.

Publish service with name “Awesome Calculator” and service ID “awesome-calc” under organization “awesome-org”.

You can check metadata of the organization and service you published using print-metadata command

Daemon is the application which will help client to call our service!

We will use the current latest Snet-Daemon 4.0.0. Please get the latest version and the system compatible binary from releases here.

Create snetd.config.json file in ~/snet-setup/snet-daemon-v4.0.0-linux-amd64 and add following json in it. You will have to change the Registry address.

Now run snet-deamon

$ nohup ./snetd > snetd.log 2>&1 &

Now let’s wait for ~20 secs to make sure Daemon is up and running!

We will now call our service using snet-cli and “Pay for it”! (sounds weird but let’s put ourselves in shoes of consumer)

Now we will need to add fund to our channel from escrow wallet to consume service

$ snet channel open-init awesome-org default_group 1 +2days

Calling Service with one of the methods from mul, div, sub, add defined in proto file here. It will take two input parameters ‘a’ and ‘b’, And we will give these parameters as json string.

$ snet client call awesome-org awesome-cal default_group mul "{\"a\": 2, \"b\": 5}"

Bazinga!! Service will return 10!!!

The offline setup is pretty straight forward, It becomes little complex when we are hosting service on remote servers, You can find more about it at SingularityNET Dev Protal.

Happy Coding! Peace!

--

--