My Python script for create and excute XCH and CAT2 transactions

Hello everyone,

I would like to share with you a script I’ve just written to automatize payments with Chia and Cat tokens.

I think this script will be useful for my future project I wish to develop on the Chia blockchain.

This very simple and basic program is in python, and you need to have a full Chia node up and running.
Basically, the script gives a Chia CLI request.

Here the Script:

import subprocess

send_transaction=subprocess.getstatusoutput(['chia wallet send -i 14 -a [TKEN AMOUNT] -t [WALLET ADDRES] -m [FEES IN XCH] -e  [MEMO TEXT]])


if "'error_msg': None" in str(send_transaction[1]).split("'_transport'")[1]:
    print('DONE')
else :
    print ('ERROR')
    print (str(send_transaction[1]).split("'_transport'")[1])

As I’ve written above, this program simply gives a CLI command and the command in this one:

hia wallet send -i 14 -a [TKEN AMOUNT] -t [WALLET ADDRES] -m [FEES IN XCH] -e  [MEMO TEXT]

-i is your local wallet id, 1 is the default for XCH token I put 14 because it is my CAT2 token wallet id.
in order to get all of your local wallets id you need to run:

chia wallet show

I hope this could be useful to someone, even if it is so simple and basic.

Thanks for your attention.

3 Likes

nice work, I appreciate it.
Do I assume correctly, that the script calls the executable with the given command parameters or are you executing shell commands?
I will later (probably a few weeks until I get to it) start working on an api interface for .net
Might as well publish it on github…

The program execute the shell commands and print out the output

1 Like

I think you’ve made a typo between send and check transaction?

Anywho, this isn’t the way to do it. See the duster’s code for the proper way

yeah you are right about the typo

By the way this is work for me, but if you can share the link I’ll definitely take a look.

Also here How To See What chia coins you have but modified

Nice,

few lines more than mine

This video - Someone improved my code by 40,832,277,770% - YouTube - provides a nice perspective how people view what is the right way of coding. Hope you enjoy that video as much as I did.

It is worth stressing that Matt didn’t intend to have that video / competition (i.e., analysis of what happened), neither is a software dev. The subject just grew organically and shows that what really matters is not so much the language used (sure Python was the worst by far, C/C++ was the fastest - nothing new here), but rather domain expertise, the cost of development and potentially the easy of deployment. At the end of the day, the original program was still good enough to illustrate the problem.

But, as far as the OP code, sure it is worth noting that RPC is a much better way to go than CLI.

will create an c# rpc library #soon
for my projects. Ill publish it on github

Looking forward to it!

I am personally very interested in Code Performance.
Yes, you can oftentimes get thousandfold speed increases. Most caviats are procedure related (the way you code)
If you do well with that, only then comes the programming language.
The question is always if its nessessary to spend hours days into optimizing something when you can hack together something that just works in a couple of Minutes.

I personally prefer to quickly solve the problem or the project I have in front of me and then optimize the code and the speed

1 Like