mkdir test
cd ./test
pip3 install bloqly
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())
In response it will print the hash of created transaction and other transaction details:
{'space': 'space1', 'key': 'test-key1', 'nonce': 1, 'timestamp': 1566127054884, 'tags': ['tag1', 'tag2'], 'memo': 'memo', 'value': 'test', 'hash': 'E85D07EFC81550089BE9E03DA7AA0711C6F46DE6C83B3432086F4097B2F97BD2', 'signature': '6yL7GBnIlwIdUJx1YpUk0It5XlC8G0AgMVg/IFQTFG22l4JsCdd/RjJuqrD9SbxWqhG/kjuDIc1HljvlhJzkBg==', 'public_key': 'Ud8SI+nIX/XrPss2DEM1B2tdxu0v9NvuuAdABfUMrZk='}
{'resultStatus': 'SUCCESS', 'resultCode': 'OK', 'message': None}
curl 'http://localhost:8082/api/events/E85D07EFC81550089BE9E03DA7AA0711C6F46DE6C83B3432086F4097B2F97BD2'
{
"space": "space1",
"key": "test-key1",
"nonce": 1,
"timestamp": 1566127054884,
"memo": "memo",
"value": "test",
"height": 264,
"hash": "E85D07EFC81550089BE9E03DA7AA0711C6F46DE6C83B3432086F4097B2F97BD2",
"publicKey": "Ud8SI+nIX/XrPss2DEM1B2tdxu0v9NvuuAdABfUMrZk=",
"signature": "6yL7GBnIlwIdUJx1YpUk0It5XlC8G0AgMVg/IFQTFG22l4JsCdd/RjJuqrD9SbxWqhG/kjuDIc1HljvlhJzkBg=="
}