Skip to main content

package to interact with ICON network.

Project description

PyPI - latest PyPI - Python

iconconsole

Python package to interact with the ICON network

Requirements

  • Python 3.7 or later.

Installation

Setup a virtual environment first, and install iconconsole via pypi.

Usage

You can use iconconsole interactively on the python console.

$ python
Python 3.7.7 (v3.7.7:d7c567b08f, Mar 10 2020, 02:56:16)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from iconconsole import *
>>>

Features

Network

Network allows you to specify your target ICON network.
You can get the network instance with Network(uri: str, nid: int = 0).
You can use predefined strings as an uri. You can get list of predefined network via ic.Network.PREDEFINED

>>> net = Network('berlin')
>>> net.uri
'https://berlin.net.solidwallet.io'
>>> Network.PREDEFINED
{'mainnet': {'uri': 'https://ctz.solidwallet.io', 'nid': 3},
 'sejong': {'uri': 'https://sejong.net.solidwallet.io',
            'nid': 83,
            'faucets': 'cx6434bfdcb6b3ad4a4f5ced0075c73b9fea2a172c'},
 'lisbon': {'uri': 'https://lisbon.net.solidwallet.io',
            'nid': 2,
            'faucets': 'cxcbece91fb181b754f906640a9746f361a3113641'},
 'berlin': {'uri': 'https://berlin.net.solidwallet.io',
            'nid': 7,
            'faucets': 'cx760787ff9b4b337ac1f2bacd2bfe2ec42ef88c0d'}}

Account

Account allow you to sign the TX and to do actions such as querying a balance or transfer ICX.

Create and load an Account

You can create new Account and load from keystore file.

>>> account1 = Account()    # create new
>>> account2 = Account(keystore=./path/to/keystore, password="password")    # load from keystore file

Methods

The Account.address() is used to get the address of account.

>>> account1.address()
'hx83d0056c46a36d623c42be5769f30210c34400bd'

The Account.network() and Account.get_network() are used to set and get the target network of an account.

>>> net.uri
'https://berlin.net.solidwallet.io'
>>> account1.network(net=net)
>>> account1.get_network().uri
'https://berlin.net.solidwallet.io'

The Account.balance() is used to query the balance of an account in the network specified by Account.network().

>>> account1.balance()
0

The Account.transfer() is used to transfer ICX to another account in the network specified by Account.network().

>>> txr = account2.transfer(account1, 10)
>>> account1.balance()
10

Score

Score allows you to deploy and update the SCORE and call the external method of SCORE

Deploy, update and load a SCORE

>>> score, txr = Score.deploy(net, account1, "./hello-world-0.1.0-optimized.jar", {"name": "Alice"})    # deploy SCORE
>>> score.address()
'cxf0a8e3aad24bad5f41444e76b865ca4aaeef84af'
>>> score.apis()
['writable setName(name: str):',
 'readonly name() -> str:',
 'readonly getGreeting() -> str:']
>>> score.name()
{'jsonrpc': '2.0', 'result': 'Alice', 'id': 1648466089}
>>> score.update("./hello-world-0.1.0-optimized.jar", {"name": "Bob"})  # update SCORE
>>> score.address()
'cxf0a8e3aad24bad5f41444e76b865ca4aaeef84af'
>>> score.name()
{'jsonrpc': '2.0', 'result': 'Alice', 'id': 1648466091}
>>> load_score = Score(net, "cxf0a8e3aad24bad5f41444e76b865ca4aaeef84af")   # load SCORE
>>> load_score.address()
'cxf0a8e3aad24bad5f41444e76b865ca4aaeef84af'
>>> load_score.name()
{'jsonrpc': '2.0', 'result': 'Alice', 'id': 1648466093}

Methods

The Score.address() is used to get an address of SCORE.
The Score.account() and Score.get_account() is used to set and get the signer account of SCORE.

Call external methods of SCORE

You can query the external methods of SCORE and call with Score object

>>> score.apis()
['writable setName(name: str):',
 'readonly name() -> str:',
 'readonly getGreeting() -> str:']
>>> txr = score.account(account1).setName("ICON")

TransactionResult

TransactionResult allows you to query transaction, transaction result and trace of transaction.

  • hash() is used to get hash of transaction
  • transaction() is used to get the transaction
  • result() is used to get the result of transaction
  • trace() is used to get the trace log of transaction execution
>>> txr = score.account(account1).setName("ICON")
>> txr.hash()
'0x9499fc3ce8a21039b3951dc08cb1f2e4098f46f2b8e5f7e518c378ebe7569539'
>>> txr.transaction()
{'jsonrpc': '2.0',
 'result': {'blockHash': '0x70319f44901cf9e3af472bb22573b91fdb70b335e1e64b0cea256a5ad0849dd5',
            'blockHeight': '0xe5f',
            'data': {'method': 'setName', 'params': {'name': 'ICON'}},
            'dataType': 'call',
            'from': 'hxa8df82e93e8a9cd5325e37289bcd0fbc0a8b4e5e',
            'nid': '0x7',
            'signature': 'M5c88PehWFkpr83AOtVIH4zJKTEdPVe41EzckXhIufo6XSBUtLqpUy5pthlMWKvBg+eQBLoaRMifD3uc7Kq1SQA=',
            'stepLimit': '0x989680',
            'timestamp': '0x5db45c316fe0b',
            'to': 'cxf0a8e3aad24bad5f41444e76b865ca4aaeef84af',
            'txHash': '0x9499fc3ce8a21039b3951dc08cb1f2e4098f46f2b8e5f7e518c378ebe7569539',
            'txIndex': '0x1',
            'value': '0x0',
            'version': '0x3'},
 'id': 1648467564}
>>> txr.result()
{'jsonrpc': '2.0',
 'result': {'blockHash': '0x70319f44901cf9e3af472bb22573b91fdb70b335e1e64b0cea256a5ad0849dd5',
            'blockHeight': '0xe5f',
            'cumulativeStepUsed': '0x23fc5',
            'eventLogs': [],
            'logsBloom': '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
            'status': '0x1',
            'stepPrice': '0x2540be400',
            'stepUsed': '0x23fc5',
            'to': 'cxf0a8e3aad24bad5f41444e76b865ca4aaeef84af',
            'txHash': '0x9499fc3ce8a21039b3951dc08cb1f2e4098f46f2b8e5f7e518c378ebe7569539',
            'txIndex': '0x1'},
 'id': 1648467626}
>>> txr.trace()
{'failure': {'code': 1, 'message': 'Calculator(height=3701,exp=3661)'},
 'logs': [{'level': 2,
           'msg': 'FRAME[1] TRANSACTION start from=hxa8df82e93e8a9cd5325e37289bcd0fbc0a8b4e5e to=cxf0a8e3aad24bad5f41444e76b865ca4aaeef84af id=0x9499fc3ce8a21039b3951dc08cb1f2e4098f46f2b8e5f7e518c378ebe7569539',
           'ts': 0},
          {'level': 2,
           'msg': 'FRAME[1] STEP apply type=default count=1 cost=100000 total=100000',
           'ts': 80},
          {'level': 2,
           'msg': 'FRAME[1] STEP apply type=input count=45 cost=9000 total=109000',
           'ts': 84},
          {'level': 2, 'msg': 'FRAME[2] START parent=FRAME[1]', 'ts': 92},
          {'level': 2,
           'msg': 'FRAME[2] INVOKE start score=cxf0a8e3aad24bad5f41444e76b865ca4aaeef84af method=setName',
           'ts': 95},
          {'level': 2,
           'msg': 'FRAME[2] STEP apply type=contractCall count=1 cost=25000 total=25000',
           'ts': 99},
          {'level': 2,
           'msg': 'FRAME[2] INVOKE done status=Success steps=13397 result=null',
           'ts': 6755},
          {'level': 2,
           'msg': 'FRAME[2] STEP apply cost=13397 total=38397',
           'ts': 6775},
          {'level': 2, 'msg': 'FRAME[2] END success=true steps=38397', 'ts': 6777},
          {'level': 2,
           'msg': 'FRAME[1] STEP apply cost=38397 total=147397',
           'ts': 6783},
          {'level': 2,
           'msg': 'FRAME[1] TRANSACTION charge fee=1473970000000000 steps=147397 price=10000000000',
           'ts': 6791},
          {'level': 2,
           'msg': 'FRAME[1] TRANSACTION done status=Success steps=147397 price=10000000000',
           'ts': 6797}],
 'status': '0x0'}

License

This project is available under the Apache License, Version 2.0.

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

iconconsole-0.1.0.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

iconconsole-0.1.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file iconconsole-0.1.0.tar.gz.

File metadata

  • Download URL: iconconsole-0.1.0.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.7

File hashes

Hashes for iconconsole-0.1.0.tar.gz
Algorithm Hash digest
SHA256 4a2f4e2e2558fe8fec4db62909f02323b84542c6a787799c7e5feb7f8ea2acca
MD5 3afb31d5ebe3dc9538a86091eb441d76
BLAKE2b-256 67e214468ce1ea966ab331e77c0637d955209b7885088c65af497886c22eedc3

See more details on using hashes here.

File details

Details for the file iconconsole-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iconconsole-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 18.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.7

File hashes

Hashes for iconconsole-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e94dcf3254743e1883d1f092ba226ad13744b5336d43e3ec2cba6533087f330
MD5 ee44ded1763677186f75396b9bde457c
BLAKE2b-256 ea72f2bef57a86073594017615710b5610260160d61c7fffd5e5fca70752a03b

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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page