Hello World

To show how to develop, deploy and invoke a service on TEEX network, we use "Hello World" service as an example. The "Hello World" service is already in our container, as well as our developing tools. After starting the container, it can be found by:

    $ cd ~/service_demo/hello_world

The directory looks like:

    --  client.opt.conf  
    --  deploy.opt.conf  
    --  hello_world.py  
    --  input.txt
    --  README.md

The client.opt.conf and deploy.opt.conf are configuration files, which are used to invoke and deploy the service respectively. hello_world.py is the service code and input.txt contains the input string. README.md briefly introduces the services.

Service Code

Let's first see the hello_world.py, which is very simple:

from teex import *

TEEX_return({'message': TEEX_getinput()})

The first line imports our teex Python library, which provides interfaces to get service input and return. Then the TEEX_getinput is used to get the user input string. "Hello World" service just splices the input string with "message", and then use TEE_return to send it back to the user.

Deploying "Hello World"

We can use teex-deploy to deploy the "Hello World" service to TEEX TestNet. We use a configuration file to parse all arguments to teex-deploy. You can deploy the service by typing:

    $ teex-deploy -c deploy.opt.conf

The deploy.opt.conf contains all the arguments required by teex-deploy, which contains:

    "service-file": "hello_world.py",
    "price": "2",
    "worker-feerate": "1",
    "private-key": "4E291BA605CED837F1044DE583453881527C9BD4A222DE0B9DFFB9FA72447337",
    "public-key": "7C0556cc73C78115454A219447ab870Ecf42B688",
    "desc": "Hello World Demo"

"service-file" specifies the service code, "price" indicates how much token need to be paid to invoke the service and "worker-feerate" is the token paid to the worker. We require that the "price" cannot less than 1. "private-key" and "public-key" specify the keys of the service. We have already provided the default key pair in the configuration file, and you can also replace it with your own key pair. After executing the teex-deploy, it will output the service ID of the "Hello World".


Although TEEX TestNet enforces the security of the "private-key", we recommend the user not to use his wallet private key as the service private key.

Invoking "Hello World"

The invocation can be performed with teex-client. We also use a configuration file to parse all arguments to it. A "Hello World" service can be invoked by typing:

    $ teex-client -c client.opt.conf

The client.opt.conf contains all the arguments required by teex-client, which contains:

        "service_id": "9cfd899533fd427ea597460ed0ee5709",
        "input_file": "input.txt",
        "payment": "2"

The "input_file" specifies the file which contains the input string to the service and "payment" specifies how mush token user wants to pay for this invocation. The payment cannot less than the price of the invoked service. "service_id" is the ID of service, which is generated by teex-deploy.

We have already deployed the service on TEEX TestNet and put its service ID in the configuration file, so users can directly use it. User can replace this ID with the service ID generated in Deploying "Hello World".