Create transaction (Python)

Install Python3 and pip3.

Create a new folder 'test'

mkdir test
cd ./test
pip3 install bloqly

Create file test-api.py

import bloqly
import requests
import time

PRIVATE_KEY = 'x9oZ6jrUVEBDP5C0005fPseqPwLshQbb9io7Upg8sNM='

NODE_URL = 'http://localhost:8082'

EVENT_URL = NODE_URL + '/api/events/add'

LAST_ID_URL = NODE_URL + '/api/events/last-id'

SPACE = 'space1'

KEY = 'test-key1'

last_id = requests.get(LAST_ID_URL, params={'space': SPACE, 'key': KEY}).json()

nonce = last_id['nonce'] + 1

signed_transaction = bloqly.sign_transaction(
    private_key=PRIVATE_KEY,
    space=SPACE,
    key=KEY,
    nonce=nonce,
    memo='memo',
    timestamp=int(time.time() * 1000),
    value='yes',
    tags=['user2', 'golos1']
)

encoded_transaction = bloqly.encode_transaction(signed_transaction)

res = requests.get(EVENT_URL, params={'event': encoded_transaction})

print(res.json())

Run python script

In response it will print the hash of created transaction and other transaction details:

Now lets check transaction is created and saved in blockchain

Will print the transaction details in response

Last updated

Was this helpful?