Skip to content

Instantly share code, notes, and snippets.

@nakata5321
Last active October 1, 2020 11:12
Show Gist options
  • Save nakata5321/3979ebc6798df03cb5f70ce2b76cf27c to your computer and use it in GitHub Desktop.
Save nakata5321/3979ebc6798df03cb5f70ce2b76cf27c to your computer and use it in GitHub Desktop.

Tutorial 1: How to launch robot via asset transfer transaction in Polkadot network.

To see the result of transaction first of all run read part:

% ./robonomics io read launch

If you have a remote node, specify the address via --remote option.

Now let's turn a robot on:

% echo "ON" | ./robonomics io write launch -r 5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL -s 0xb046fc3c322e91e14a61ad4f08a3809ee0de7092e73aa9b3c2b642a0f476d4d6
0c71f523533445ea193223e635448b6186899270ae1dd0dd8ad21b56d7870fa3

Then you should see in the first terminal window:

% ./robonomics io read launch
5H3iRnX16DH2sb2RLxMM8UhDZTvJjP84EhhKXv3sCiEDq6bH >> 5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL : true

Let's describe all the accounts and options above.

  • -r 5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL means robot's address
  • -s 0xb046fc3c322e91e14a61ad4f08a3809ee0de7092e73aa9b3c2b642a0f476d4d6 private key of the account to launch from (must have tokens for a transaction)
  • 5H3iRnX16DH2sb2RLxMM8UhDZTvJjP84EhhKXv3sCiEDq6bH address that launches a robot
  • 5CiPPseXPECbkjWCa6MnjNokrgYjMqmKndv2rSnekmSK2DjL robot's address
  • true turn it on

If we pass anything else but "ON" the state becomes false

Example of code with reading robonomics io read from strout:

program = '/path/to/directory/' + '/robonomics io read launch'
rob_read = subprocess.Popen(program, shell=True, stdout=subprocess.PIPE)
while True:
    try:
        output = rob_read.stdout.readline()
        rospy.loginfo("Find a payment")
        out = output.split(" >> ")
        check_state = my_adress.rstrip() + " : true"
        if(out[1].rstrip() == check_state):
            rospy.loginfo("Job paid")
            rob_read.kill()
            break
        if(output):
            rospy.loginfo("Not my job")
    except KeyboardInterrupt:
        exit()

Video example is available on YouTube on 2:32.

Full simulation you can find here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment