The SingularityNET command line interface (CLI) is the primary tool for interacting with the platform’s smart contracts, managing deployed services, and managing funds. It is aimed at service providers. In the near future, it will be supplemented by a web-based dashboard and control panel.
The CLI provides commands to interface with the Blockchain in the following ways:
The CLI also provides service development and deployment support. It can set up new services by generating service metadata, Protobuf specs, and code templates provided by the SingularityNET Foundation. The CLI interacts with daemons for each service. Security-wise, the CLI follows the same guidelines as provided by Ethereum for storing the private keys. When user identities are created and registered with a client, the CLI safely stores the details on the local machine and retrieves them only when it needs to interact with the Blockchain.
The CLI requires and connects to four critical components:
This tool is used extensively in our tutorials and guides, to install it, follow the setup guide.
See the CLI documentation for full details of actions the tool allows.
While protocol buffers are used for communication, call parameters are represented as JSON on the command line.
There are three ways of passing this JSON:
For example, in this platform example we need to pass the following JSON as a parameter for the “add” method to our service:
{"a": 10, "b": 32}
We can use three ways:
# via cmdline parameter
snet client call 0 0.1 localhost:8080 add '{"a":10,"b":32}'
# via json file
echo '{"a":10,"b":32}' > p.txt
snet client call 0 0.1 localhost:8080 add p.txt
# via stdin
echo '{"a":10,"b":32}' | snet client call 0 0.1 localhost:8080 add
We’ve implemented several modifiers for this JSON parameter in order to simplify passing big files and to have the possibility to pass binary data (and not only base64 encoded data).
There are 3 possible modifiers:
For example, if you pass the following JSON as a parameter, then as an “image” parameter we will use the base64 encoded content of “1.jpeg”
'{"image_type": "jpg", "file@b64encode@image": "1.jpeg"}'
If we remove the b64encode modifier from the previous example, then we will pass 1.jpeg image in binary format without base64 encoding.
#snet-sdk-python SingularityNET SDK for Python ##Getting Started These instructions are for the development and use of the SingularityNET SDK for Python. ###Usage The SingularityNET SDK allows you to import compiled client libraries for your service or services or choice and make calls to those services programmatically from your application by setting up state channels with the providers of those services and making gRPC calls to the SingularityNET daemons for those services by selecting a channel with sufficient funding and supplying the appropriate metadata for authentication. Once you have installed the snet-sdk in your current environment and it’s in your PYTHONPATH, you should import it and create an instance of the base sdk class:
from snet_sdk import Snet
import config
snet = Snet(private_key=config.private_key)
Now, the instance of the sdk can be used to instantiate clients for SingularityNET services. To interact with those services, the sdk needs to be supplied the compiled client libraries and a reference to their path on your file system.
To generate the client libraries, you need the SingularityNET Command Line Interface, or CLI, which you can download from PyPi, see https://github.com/singnet/snet-cli#installing-with-pip
Once you have the CLI installed, run the following command:
snet sdk generate-client-library python <org_id> <service_id>
snet sdk generate-client-library python
Optionally, you can specify an output path; otherwise it’s going to be ./client_libraries/python/
Now, by default the sdk is going to look for those client libraries in the ./grpc/
Once you have the generated client libraries in place, you can create an instance of a SingularityNET service client:
client = snet.client("<org_id>", "<service_id>")
The client exposes the following properties and methods:
stub = client.grpc.example_service_pb2_grpc.CalculatorStub(client.grpc_channel)
request = calculator.grpc.example_service_pb2.Numbers(a=10, b=12)
result = stub.add(request)
print(result)
If you have no open state channels with the service provider, you can create one by calling the following function: client.open_channel()
By default, this will create a channel with the shortest possible expiration date and the necessary amount to make 100 service calls.
Once an open channel is created and funded, the sdk will automatically find and use a funded, non-expired channel.
For more information about gRPC and how to use it with Python, please see:
###Prerequisites
$ git clone git@github.com:singnet/snet-sdk-python.git
$ cd snet-sdk-python
• Install development/test Blockchain dependencies
$ ./scripts/Blockchain install
• Install the package in development/editable mode
$ pip install -e .
###Versioning We use SemVer for versioning. For the versions available, see the tags on this repository. ###License This project is licensed under the MIT License - see the LICENSE file for details.
snet-sdk-java
###How to build Integration testing is enabled by default. To run full build including integration tests use:
mvn install
Running integration tests is a time consuming process so to make fast build running unit tests only use:
mvn install -DskipITs
#snet-sdk-js
##Getting Started This repo hosts multiple SDKs for JavaScript. Currently supported platforms
You can find more details about each sdk within the respective package folders.
These SDKs are under active development and not ready for production use yet. If you find any bug or something doesn’t work as expected, please create an issue.
##Usage All the SDKs assume that there is enough eth balance to cover the gas cost and AGI tokens in the wallet to cover the service execution cost.
The SDKs chose a default Payment Channel Management Strategy, which is the simplest form of picking an existing Payment Channel if any or creates a new Payment Channel if no channel is found.
This can be easily overridden by providing your own strategy to the SDK at the time of construction. Documentation on creating custom strategies will be available soon. ##Development This is a monorepo which is setup a little differently. It does not use any external tools like lerna or any other popular tool.
There are 3 packages out of which only 2 of them are published to npm
The way the core package is shared across nodejs and web is by creating a symlink to core under each package. This setup has been tested on macOS and should work on any standard Linux distribution but it has not been tested on Windows OS.
Navigate to the specific package which needs to be build and then run the following command npm run build
Navigate to the specific package which needs to be published and then run the following command npm run publish LICENSE file for details.
#snet-sdk-Java
Class diagram Image
##How to build
Integration testing is enabled by default. To run full build including integration tests use:
mvn install
Running integration tests is a time consuming process so to make fast build running unit tests only use:
mvn install -DskipITs
Last modified on : 11-Feb-20