Published 7 December 2018

Using of Credits API in Python 3 (demo)

Requirements

Requirements

Windows x64

Download Credits API files

Development Environment: https://www.jetbrains.com/pycharm/

Additional libraries:

base58

thrift

Create Application

Create Application

You have to add them via the PyCharm IDE package manager, for example:

Create console applications (Python 3) in PyCharm IDE

Credits API Source Code Generation

Open the folder which you have used for download of Credits API from the GitHub, for example, in d: \ Credits \ github \ CS-API \

Let's say thrift is installed to the folder: d: \ vcpkg \

execute commands:

D: \ vcpkg \ packages \ thrift_x64-windows \ tools \ thrift \ thrift.exe --gen py api.thrift

D: \ vcpkg \ packages \ thrift_x64-windows \ tools \ thrift \ thrift.exe --gen py variant.thrift

As the result will be a folder with files: gen-cpp, copy the files from the folder to the folder of our application, for example in: d: \ Credits \ app \ app \

Add files to our project

Add files to our project

Add the code

Add the code

from thrift.protocol.TBinaryProtocol import TBinaryProtocol

from thrift.transport.TSocket import TSocket

import base58

from gen.api.API import Client

publicKey = 'H5ptdUUfjJBGiK2X3gN2EzNYxituCUUnXv2tiMdQKP3b'

publicKeyBytes = base58.b58decode(publicKey)

try:

   tr = TSocket('127.0.0.1', 9090)

   protocol = TBinaryProtocol(tr)

   client = Client(protocol)

   tr.open()

   balance = client.BalanceGet(publicKeyBytes, 0)

   print(balance)

   transactionGetResult = client.TransactionsGet(publicKeyBytes, 0, 5)

   print(transactionGetResult)

except:

   print("Oops. Unexpected error.")

Check the performance. Call the GetBalance Method.

Check the performance. Call the GetBalance Method.

As the result of the program we see the requested balance:

GitHub link

12 Useful article

Contents