Overview

Overview

Docker image is similar to the one from the tutorials page but contains source code of example-service and all main SingularityNET components in addition.

SingularityNet Docker image

You can download or build it from scratch:

Download

docker pull vsbogd/snet-platform:latest
docker tag  vsbogd/snet-platform:latest snet-amsterdam-meetup

Build

docker build -t snet-amsterdam-meetup https://github.com/singnet/dev-portal.git#master:/workshops/amsterdam-meetup-20190321

Run Docker container

docker run --name snet-amsterdam-meetup -p 7000:7000 -ti snet-amsterdam-meetup bash

Tutorial steps

Setup Ethereum identity

# Create Ethereum identity
snet identity create --mnemonic '<my mnemonic>' publisher mnemonic
# Switch to Ropsten network
snet network ropsten
# Look at current snet-cli settings
snet session
# Look at identity balance
snet account balance

Review & build service

cd example-service
# Review service API
cat ./service/service_spec/*.proto
# Install dependencies
pip3 install -r requirements.txt
# Build gRPC stubs
sh buildproto.sh

Publish service

# Create organization
snet organization create --org-id <my-org-id> '<my organization name>'
# Initialize service metadata
snet service metadata-init ./service/service_spec "Example service" 0x89E58AF872b225d3ef94Ee7524880a57d014C826 --endpoints http://<my.ip>:7000 --fixed-price 0.00000001
# Add service description
snet service metadata-add-description --json {"description": "<my service descrition>", "url": "<my service url>"}'
# Review metadata
cat service_metadata.json
# Publish service
snet service publish <my-org-id> example-service
# Review organization
snet organization info

Start service

# Prepare config for Ropsten
cp snetd_configs/snetd.ropsten.json snetd.config.json
# Edit config
# - set port in daemon_end_point to 7000
# - set organization_id to <my-org-id>
# - set log.type to "stdout"
vim snetd.config.json
# Start service and daemon
python3 run_example_service.py --daemon-config snetd.config.json

Call service

Open new console and execute:

# Switch to the new docker instance
docker exec -it snet-amsterdam-meetup bash
# Review account balance
snet account balance
# Deposit AGI tokens to MPE wallet
snet account deposit 0.0000001
# Open payment channel
snet channel open-init <my-org-id> example-service 0.0000001 +10days
# Channel id is returned
# Look at the channel state
snet client get-channel-state <channel-id> http://localhost:7000
# Call method
snet client call <my-org-id> example-service mul '{"a": 7, "b": 6}'
# Look how channel state was changed
snet client get-channel-state <channel-id> http://localhost:7000
# Check account balance
snet account balance

Claim money

# Claim all money as service publisher
snet treasurer claim-all --endpoint http://localhost:7000
# Look how channel state was changed
snet client get-channel-state <channel-id> http://localhost:7000
# Check account balance
snet account balance