Skip to main content

A Python API for interacting with Stabila (STB)

Project description

A Python API for interacting with the Stabila (STB)

https://img.shields.io/pypi/v/stabilaapi.svg https://img.shields.io/pypi/pyversions/stabilaapi.svg https://api.travis-ci.com/stabilaclick/stabila-api-python.svg?branch=master https://img.shields.io/github/issues/stabilaclick/stabila-api-python.svg https://img.shields.io/github/issues-pr/stabilaclick/stabila-api-python.svg Codacy Badge

A Command-Line Interface framework

You can install it in a system-wide location via pip:

sudo pip3 install stabilaapi

Or install it locally using virtualenv:

virtualenv -p /usr/bin/python3 ~/stabilaapi
source ~/stabilaapi/bin/activate
pip3 install stabilaapi

Usage

Specify the API endpoints:

Smart Contract

from stabilaapi import Stabila
from solc import compile_source

full_node = 'https://api.stablilascan.org'
solidity_node = 'https://api.stablilascan.org'
event_server = 'https://api.stablilascan.org'

stabila = Stabila(full_node=full_node,
        solidity_node=solidity_node,
        event_server=event_server)

# or default (stabila = Stabila())


# Solidity source code
contract_source_code = '''
pragma solidity ^0.4.25;

contract Hello {
    string public message;

    function Hello(string initialMessage) public {
        message = initialMessage;
    }

    function setMessage(string newMessage) public {
        message = newMessage;
    }
}

'''

compiled_sol = compile_source(contract_source_code)
contract_interface = compiled_sol['<stdin>:Hello']

hello = stabila.stb.contract(
    abi=contract_interface['abi'],
    bytecode=contract_interface['bin']
)

# Submit the transaction that deploys the contract
tx = hello.deploy(
    fee_limit=10**6,
    call_value=0,
    consume_user_resource_percent=1
)

Base Example

from stabilaapi import Stabila
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(levelname)s - %(message)s")
logger = logging.getLogger()

full_node = 'https://api.stablilascan.org'
solidity_node = 'https://api.stablilascan.org'
event_server = 'https://api.stablilascan.org'

stabila = Stabila(full_node=full_node,
        solidity_node=solidity_node,
        event_server=event_server)

account = stabila.create_account()
is_valid = bool(stabila.stb.is_address(account.address.hex))

logger.debug('Generated account: ')
logger.debug('- Private Key: ' + account.private_key)
logger.debug('- Public Key: ' + account.public_key)
logger.debug('- Address: ')
logger.debug('-- Base58: ' + account.address.base58)
logger.debug('-- Hex: ' + account.address.hex)
logger.debug('-- isValid: ' + str(is_valid))
logger.debug('-----------')

transaction = stabila.stb.get_transaction('757a14cef293c69b1cf9b9d3d19c2e40a330c640b05c6ffa4d54609a9628758c')

logger.debug('Transaction: ')
logger.debug('- Hash: ' + transaction['txID'])
logger.debug('- Transaction: ' + json.dumps(transaction, indent=2))
logger.debug('-----------')

# Events
event_result = stabila.stb.get_event_result('SGEJj8eus46QMHPgWQe1FJ2ymBXRm96fn1', 0, 'Notify')

logger.debug('Event result:')
logger.debug('Contract Address: SGEJj8eus46QMHPgWQe1FJ2ymBXRm96fn1')
logger.debug('Event Name: Notify')
logger.debug('Block Number: 32162')
logger.debug('- Events: ' + json.dumps(event_result, indent=2))

More samples and snippets are available at examples.

Documentation

Documentation is available at docs.

Donations

STABILA:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

stabilaapi-1.0.3.tar.gz (43.3 kB view details)

Uploaded Source

File details

Details for the file stabilaapi-1.0.3.tar.gz.

File metadata

  • Download URL: stabilaapi-1.0.3.tar.gz
  • Upload date:
  • Size: 43.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for stabilaapi-1.0.3.tar.gz
Algorithm Hash digest
SHA256 6158b114975ac75dd7bebc2118e8641238839e92adb6337feb0dd566927a7449
MD5 44721af6b32cd67f53a3493a382c1e5a
BLAKE2b-256 9541ac2bc006aeda165e30230f8ab1ead7fd5f5c6cdd4536dc7a0b83f30f8968

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page