asimov package

Submodules

asimov.account module

class asimov.account.AccountFactory

Bases: object

The primary entry point for working with Asimov private keys.

It does not require a connection to an Asimov node.

classmethod generate_address(private_key: str) → str

create an asimov address with the given private key

Parameters:private_key – the private key
Returns:an hex address generated from private key, without 0x prefix.
>>> from asimov import AccountFactory
>>> AccountFactory.generate_address("bba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056")
'66c17b951f0c85b860c9f7f0d811c77ea78f2d2e3a'
classmethod new(private_key=None) → asimov.data_type.Account

create a new account from the given private key and return as a Account

Parameters:private_key – private key, if None, a new private key will be generated
Returns:an Account object
>>> from asimov import AccountFactory
>>> account = AccountFactory.new("bba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056")
>>> account.address
'0x66c17b951f0c85b860c9f7f0d811c77ea78f2d2e3a'
>>> account.private_key
'0xbba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056'
>>> account.public_key
b'023a68576342553357f042c6ede12bd3ed01cb61ad39848908883cab93f66c7601'
classmethod private2account(private_key: str) → asimov.data_type.Account

convert private key to account and return as a Account

Parameters:private_key – the private key
Returns:an Account object with address, private key and public key.
>>> from asimov import AccountFactory
>>> account = AccountFactory.private2account(
    "bba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056")
>>> account.address
'0x66c17b951f0c85b860c9f7f0d811c77ea78f2d2e3a'
>>> account.private_key
'0xbba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056'
>>> account.public_key
b'023a68576342553357f042c6ede12bd3ed01cb61ad39848908883cab93f66c7601'
classmethod private2compressed_public(private_key: str) → bytes

generate compressed public key from private key

Parameters:private_key – private key
Returns:compressed public key in bytes format
classmethod private2public(private_key: str) → bytes

generate public key from private key

Parameters:private_key – private key
Returns:public key in bytes format
class asimov.account.Address(address: str)

Bases: object

is_pay_to_contract_hash
is_pay_to_pub_hash
to_contract_hash_script()
static to_create_contract_hash_script()
static to_create_template_hash_script()
to_create_vote_hash_script()
to_script_pub_key() → str
to_str()
type
class asimov.account.PrivateKeyFactory

Bases: object

Private key generator

classmethod generate_key() → str

Create a new private key and return.

Returns:a private key in string form.
>>> from asimov import PrivateKeyFactory
>>> PrivateKeyFactory.generate_key()
'bba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056'

# note that the key generated above is a random value, it will be different in your try

asimov.constant module

class asimov.constant.AddressType

Bases: object

address types

  1. 0x66 normal account
  2. 0x63 contract
ContractHash = 99
PubKeyHash = 102
class asimov.constant.AsimovOpCode

Bases: object

new opcode added in asimov

OP_CALL

Used by autodoc_mock_imports.

OP_CREATE

Used by autodoc_mock_imports.

OP_DATA_21

Used by autodoc_mock_imports.

OP_IFLAG_EQUAL

Used by autodoc_mock_imports.

OP_IFLAG_EQUALVERIFY

Used by autodoc_mock_imports.

OP_SPEND

Used by autodoc_mock_imports.

OP_TEMPLATE

Used by autodoc_mock_imports.

OP_VOTE

Used by autodoc_mock_imports.

class asimov.constant.ContractFunType

Bases: object

function types which follow EVM standards

CONSTRUCTOR = 'constructor'
EVENT = 'event'
FALLBACK = 'fallback'
FUN = 'function'
class asimov.constant.TxType

Bases: object

There are different call types when interacting with contract in a transaction

  1. CREATE deploy a new contract
  2. CALL call a contract function
  3. TEMPLATE submit a new template to template warehouse
  4. VOTE vote to a contact function
CALL = 'call'
CREATE = 'create'
TEMPLATE = 'template'
VOTE = 'vote'
class asimov.constant.UtxoSelectPolicy

Bases: object

NORMAL = 'normal'
VOTE = 'vote'

asimov.contract module

class asimov.contract.Contract(node: asimov.node.Node, address: str = None, c: asimov.data_type.SmartContract = None, template_name: str = None, args: list = None)

Bases: object

The primary entry point for working with smart contract.

execute(func_name, args=None, asset_value=0, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000') → asimov.data_type.Tx

send a transaction to execute a function in the contract and return the transaction object Tx. Note the returned Tx object is in pending status. You need to check execution status constantly and wait it confirmed on chain.

Parameters:
  • func_name – function name
  • args – function arguments
  • asset_value – the asset value to be send
  • asset_type – the asset type to be send
  • tx_fee_type – the transaction fee type
Returns:

the Tx object

>>> from asimov import Contract, Node, AsimovSolc
>>> node = Node("http://seed.asimov.tech")
>>> contract = Contract(node, c=AsimovSolc.compile("/path/to/my/sources/tutorial.sol")['Tutorial'])
>>> tx = contract.execute("mint", [1000000])
>>> tx.check()  # 1 / 0
fetch(tx_id) → asimov.data_type.EvmLogs

fetch the contract execution logs in the transaction

Parameters:tx_id – contract transaction id
Returns:the EvmLogs object
read(func_name, args=None)

call a view/pure function in the contract and return the execution result

Parameters:
  • func_name – function name
  • args – function arguments
Returns:

the return value of the readonly function

>>> from asimov import Contract, Node, AsimovSolc
>>> node = Node("http://seed.asimov.tech")
>>> contract = Contract(node, c=AsimovSolc.compile("/path/to/my/sources/example.sol")['Example'])
>>> contract.read("readonly function name")
vote(func_name, args=None, asset_value=0, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000') → asimov.data_type.Tx

send a transaction to vote on a contract and return the transaction object Tx Note the returned Tx object is in pending status. You need to check execution status constantly and wait it confirmed on chain.

Parameters:
  • func_name – function name
  • args – function arguments
  • asset_value – the asset value to be send
  • asset_type – the asset type to be send
  • tx_fee_type – the transaction fee type
Returns:

the Tx object

>>> from asimov import Contract, Node, AsimovSolc
>>> node = Node("http://seed.asimov.tech")
>>> contract = Contract(node, c=AsimovSolc.compile("/path/to/my/sources/tutorial.sol")['Tutorial'])
>>> contract.vote("vote", [1]).check()

asimov.data_type module

class asimov.data_type.Account(private_key=None, address=None, public_key=None)

Bases: object

Asimov account, consists of private key, public key and address

class asimov.data_type.Asset(contract, asset_type: int, asset_index: int)

Bases: object

The primary entry point for working with asset on asimov chain.

Asimov asset consists of 3 parts

#. asset_type, 4 bytes long, each bit contains an asset property. For now, the first bit is used to determine whether an asset is divisible and the second bit is used to determine whether the asset is restricted. #. org_id, 4 bytes long organization id, system wide unique id assigned to organization when registering to asimov platform. #. asset_index, 4 bytes long asset index in organization, the assigning rule is determined by the organization itself.

static asset2str(asset: int) → str

convert asset id from int to hex string without 0x :param asset: asset id in int format :return: asset id in hex string format

>>> from asimov import Asset
>>> Asset.asset2str(4294967297)
'000000000000000100000001'
asset_id_int

get the asset id in int format

asset_id_str

get the asset id in hex string format

static asset_wrapper(asset_type, org_id, asset_index) → int

asimov asset wrapper

Parameters:
  • asset_type – asset type.
  • org_id – organization id.
  • asset_index – asset index.
Returns:

asimov asset id in int format

>>> from asimov import Asset
>>> Asset.asset_wrapper(0, 1, 1)
4294967297
class asimov.data_type.ContractTemplate

Bases: tuple

contract template

abi

template abi

byte_code

template bytecode

category

template category

source

template source code

template_name

template name

class asimov.data_type.EvmLog(raw_log)

Bases: object

contract execution log

class asimov.data_type.EvmLogs(*args, **kwargs)

Bases: list

to_dict() → dict

convert evm logs from list to dict, which may lose the logs of the same name :return: evm logs in dict format

class asimov.data_type.SmartContract

Bases: tuple

compiled contract

abi

contract abi

address

contract address on chain

bytecode

contract bytecode

source

contract source code

class asimov.data_type.Tx(node, transaction, _id=None, is_contract_tx=False)

Bases: object

The primary entry point for working with transaction object.

broadcast()

broadcast the transaction :return:

check() → int

check whether a normal transaction is confirmed on chain, or a contract call is successful or not :return: 1 if the transaction is confirmed on chain, or the contract call is successful

id

get the transaction id

asimov.error module

exception asimov.error.CompileError

Bases: asimov.error._BaseException

compile error

exception asimov.error.CompileTimeout

Bases: asimov.error._BaseException

compile timeout

exception asimov.error.InvalidParams

Bases: asimov.error._BaseException

invalid parameters

exception asimov.error.InvalidPrivateKey

Bases: asimov.error._BaseException

invalid private key

exception asimov.error.InvalidTxType

Bases: asimov.error._BaseException

invalid tx type

exception asimov.error.JsonException

Bases: asimov.error._BaseException

json

exception asimov.error.NetWorkError

Bases: asimov.error._BaseException

network error

exception asimov.error.NoAvailableKey

Bases: asimov.error._BaseException

no available key

exception asimov.error.NoUtxoError

Bases: asimov.error._BaseException

no available utxo

exception asimov.error.NotEnoughMoney

Bases: asimov.error._BaseException

not enough money

exception asimov.error.RPCError

Bases: asimov.error._BaseException

rpc response error

exception asimov.error.UnSupportSolidityImportType

Bases: asimov.error._BaseException

solidity import error

exception asimov.error.UnknownError

Bases: asimov.error._BaseException

Unknown

asimov.evm_log module

class asimov.evm_log.EvmLogParser

Bases: object

The primary entry point for working with Asimov smart contract execution logs.

classmethod parse(raw_log: Union[dict, list], abi: Union[dict, str]) → asimov.data_type.EvmLogs

Parse asimov vm execution log

Parameters:
  • raw_log – contract execution log
  • abi – contract abi object in json format
Returns:

parsed log list

asimov.node module

class asimov.node.Node(provider: str = None, private_key: str = None)

Bases: object

A wrapped object for asimov node

address

get the corresponding account address

balance(address: str = None, asset='000000000000000000000000') → Union[int, dict]

get the balance of specific address by given asset type

Parameters:
  • address – specific address, default is current node account address
  • asset – asset type, will return balance for all asset types if none is given
Returns:

balance of given asset type, or balance for all asset types

static build_data_of_create_template(category, name, hex_code, abi, source='solidity source code') → str

binary data for template creation transaction

Parameters:
  • category – template category
  • name – template name
  • hex_code – transaction data in hex type
  • abi – template abi
  • source – template source code
Returns:

transaction data

static build_data_of_deploy_contract(contract_template: asimov.data_type.ContractTemplate, params: list) → str

binary data for contract deployment transaction

Parameters:
  • contract_template – the ContractTemplate object
  • params – parameters of contract constructor function
Returns:

transaction data

call(method: str, args: list = None)

call asimov rpc service

Parameters:
  • method – rpc function name
  • args – rpc function arguments
Returns:

the return value of the rpc function

>>> from asimov import Node
>>> node = Node("http://seed.asimov.tech")
>>> node.call("getBlockChainInfo")
{'chain': 'devnet',
 'blocks': 6841,
 'bestblockhash': '329a4289a46b5e6e6a7e63744338d63d9065c264a87f17c82bf13853806cc3ef',
 'mediantime': 1574942764,
 'pruned': False}
call_write_function(func_name: str = None, params: tuple = None, abi=None, contract_address: str = '0x660000000000000000000000000000000000000000', contract_tx_data=None, call_type='call', asset_value=0, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000', gas_price=0.1, corrected_gas=50000) → asimov.data_type.Tx

send a transaction to execute a method in the contract

Parameters:
  • func_name – function name to be called in the contract
  • params – call parameters
  • abi – contract abi
  • contract_address – contract address
  • contract_tx_data – binary data of the transaction
  • call_type – call type
  • asset_value – asset value to send
  • asset_type – asset type to send
  • tx_fee_type – transaction fee type
  • gas_price – gas price
  • corrected_gas – adjusted gas value
Returns:

the Tx object

check(tx_id: str) → int

If the transaction is a normal transaction, this function checks whether a transaction is confirmed on chain. If the transaction is a contract transaction, this function checks whether a transaction is confirmed on chain and returns contract execution status.

Parameters:tx_id – transaction id
Returns:return 1 if the transaction is confirmed on chain and the execution result is success.
>>> from asimov import Node, constant
>>> node = Node(
        "http://seed.asimov.tech",
        "0xafd29358a5ba9e2f5aac5cd5013a6830a99e34a68c469c78ab5f4c6f1d8c2a46"
    )
>>> tx = node.send("0x663bc0936166c07431ed04d7dc207eb7694e223ec4", asset_value=10)
# wait tx on chain
>>> assert tx.check() is constant.SUCCESS
static create_contract_tx_output(address: str, amount: int, data: str, assets: str = '000000000000000000000000', contract_type='call') → dict

create contract transaction output. in asimov, contract call is wrapped in transaction output.

Parameters:
  • address – output address
  • amount – output amount
  • data – output data
  • assets – output asset id in hex string format
  • contract_type – contract call type, default is ‘call’
Returns:

output dict

static create_tx_output(address: str, amount: int, assets: str = '000000000000000000000000')

create transaction output.

Parameters:
  • address – output address
  • amount – output amount
  • assets – output asset id in hex string format
Returns:

output dict

current_height

get the current height of chain

estimate_gas(tx_hex: str, inputs: list, corrected_value=50000)

estimate transaction execution gas cost :param tx_hex: transaction in hex format :param inputs: UTXO used in transaction :param corrected_value: corrected gas value :return:

get_contract_template(address: str = None, key: str = None, name: str = None) → asimov.data_type.ContractTemplate

get contract template object according to address, key or name

Parameters:
  • address – contract address
  • key – template key (template id)
  • name – template name
Returns:

the ContractTemplate object

private_key

get the account private key

send(address, asset_value: int, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000') → asimov.data_type.Tx

send a normal transaction on asimov chain and return the transaction object Tx

Parameters:
  • address – target address
  • asset_value – asset value to send
  • asset_type – asset type to send
  • tx_fee_type – transaction fee type
Returns:

the Tx object

>>> from asimov import Node, constant
>>> node = Node(
        "http://seed.asimov.tech",
        "0x98ca5264f6919fc12536a77c122dfaeb491ab01ed657c6db32e14a252a8125e3"
    )
>>> node.send(
        "0x663bc0936166c07431ed04d7dc207eb7694e223ec4",
        asset_value=10, asset_type=constant.ASCOIN,
        tx_fee_type=constant.ASCOIN
    )
[id: 91c4645bcf3680c699a591632cd8769abe2973fd2de70081a6752d9781f2801b]
set_private_key(private_key: str)

set the account private key

set_rpc_server(url: str)

set rpc server url :param url: rpc server url

wait_for_confirmation(tx_id, confirm_num=1, timeout=60) → bool

wait for the transaction to be confirmed on chain

Parameters:
  • tx_id – transaction id
  • confirm_num – confirmed block count, default is 1
  • timeout – time out length, default is 60 seconds
Returns:

true if confirmed, false otherwise

asimov.node.encode_transaction_data(fn_identifier, contract_abi=None, fn_abi=None, args=None, kwargs=None)

asimov.solc module

class asimov.solc.AsimovSolc

Bases: object

The primary entry point for working with solidity compiler.

classmethod compile(source_file: str, **kwargs) → dict

compile solidity source file

Parameters:
  • source_file – source file path
  • kwargs (dict) – reference to compile_files function in py-solc library
Returns:

multiple compiled contract objects in dict type

>>> from asimov import AsimovSolc
>>> AsimovSolc.compile("/path/to/my/sources/example.sol")
{'Example': {
    'abi': [{
        'inputs': [],
        'payable': False,
        'stateMutability': 'nonpayable',
        'type': 'constructor'
    }],
    'address': None,
    'bytecode': '6080604052348015600f57600080fd5b50603580601d6000396000f3006080604052600080fd00a165627a7a72305820bf199053a6eea79c7732c9211fc200781b170db435d118cbd86d2ac117e2fa360029',
    'source': 'pragma solidity ^0.4.25;\n'
              '\n'
              'contract Example {\n'
              '    constructor() public {}\n'
              '}\n'
    }
}
classmethod set_solidity_compiler(compiler_path: str) → None

set solidity compiler path

Parameters:compiler_path – solidity compiler path
Returns:None
>>> from asimov import AsimovSolc
>>> AsimovSolc.set_solidity_compiler("/usr/local/bin/solc")

asimov.template module

class asimov.template.Template(node: asimov.node.Node)

Bases: object

deploy_contract(template_id: str, constructor_arguments=None, asset_value=0, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000') -> (<class 'asimov.data_type.Tx'>, <class 'str'>)

deploy a contract based on a given template id and return the address of the newly deployed contract on asimov blockchain and transaction object

Parameters:
  • template_id – template id
  • constructor_arguments – contract constructor arguments
  • asset_value – asset value to send
  • asset_type – asset type to send
  • tx_fee_type – transaction fee type
Returns:

the transaction object Tx and the address of new contract

>>> from asimov import Node, Template, constant
>>> node = Node(
        "http://seed.asimov.tech",
        "0x98ca5264f6919fc12536a77c122dfaeb491ab01ed657c6db32e14a252a8125e3"
    )
>>> t = Template(node)
>>> tx = t.submit("tutorial.sol", "template name1", "Tutorial")
>>> assert tx.check() is constant.SUCCESS
>>> t.deploy_contract(tx.id)
[id: 2b7af42268f1ae098bc959d52c2c7d05af9cb44b2f2b6c8cfeb5c3afab941d5b]
submit(source, template_name, chosen_contract, tx_fee_type='000000000000000000000000') → asimov.data_type.Tx

submit a new template to asimov blockchain and return the transaction object Tx

Parameters:
  • source – smart contract source file path
  • template_name – template name
  • chosen_contract – contract name
  • tx_fee_type – transaction fee type
Returns:

the transaction object Tx

>>> from asimov import Node, Template
>>> node = Node(
    "http://seed.asimov.tech",
    "0x98ca5264f6919fc12536a77c122dfaeb491ab01ed657c6db32e14a252a8125e3"
    )
>>> t = Template(node)
>>> tx = t.submit("tutorial.sol", "template name1", "Tutorial")
>>> tx
[id: 8414ceb0d6db9c6418cd62c022168d961e69de80f662f0cdd99669f5954955ae]
# template id
>>> tx.id
'8414ceb0d6db9c6418cd62c022168d961e69de80f662f0cdd99669f5954955ae'

asimov.transactions module

class asimov.transactions.AsimovScript

Bases: object

classmethod sign(tx: asimov.transactions.Transaction, key_pair: asimov.data_type.Account, in_idx, sub_script, hash_type=<sphinx.ext.autodoc.importer._MockObject object>) → bytes
classmethod signature_hash(tx: asimov.transactions.Transaction, in_idx, sub_script, hash_type=<sphinx.ext.autodoc.importer._MockObject object>) → bytes
class asimov.transactions.Transaction(vin=(), vout=(), nLockTime=0, nVersion=1, gas_limit=0)

Bases: object

serialize_size() → int
sign(sig_type=<sphinx.ext.autodoc.importer._MockObject object>)
to_buffer_writer() → _io.StringIO
to_hex() → str
class asimov.transactions.TxInput(vin: dict)

Bases: object

serialize_size() → int
write_buffer(buf)
class asimov.transactions.TxOutput(output: dict)

Bases: object

serialize_size() → int
write_buffer(buf)
asimov.transactions.var_int_serialize_size(val: int) → int

Module contents

class asimov.AccountFactory

Bases: object

The primary entry point for working with Asimov private keys.

It does not require a connection to an Asimov node.

classmethod generate_address(private_key: str) → str

create an asimov address with the given private key

Parameters:private_key – the private key
Returns:an hex address generated from private key, without 0x prefix.
>>> from asimov import AccountFactory
>>> AccountFactory.generate_address("bba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056")
'66c17b951f0c85b860c9f7f0d811c77ea78f2d2e3a'
classmethod new(private_key=None) → asimov.data_type.Account

create a new account from the given private key and return as a Account

Parameters:private_key – private key, if None, a new private key will be generated
Returns:an Account object
>>> from asimov import AccountFactory
>>> account = AccountFactory.new("bba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056")
>>> account.address
'0x66c17b951f0c85b860c9f7f0d811c77ea78f2d2e3a'
>>> account.private_key
'0xbba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056'
>>> account.public_key
b'023a68576342553357f042c6ede12bd3ed01cb61ad39848908883cab93f66c7601'
classmethod private2account(private_key: str) → asimov.data_type.Account

convert private key to account and return as a Account

Parameters:private_key – the private key
Returns:an Account object with address, private key and public key.
>>> from asimov import AccountFactory
>>> account = AccountFactory.private2account(
    "bba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056")
>>> account.address
'0x66c17b951f0c85b860c9f7f0d811c77ea78f2d2e3a'
>>> account.private_key
'0xbba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056'
>>> account.public_key
b'023a68576342553357f042c6ede12bd3ed01cb61ad39848908883cab93f66c7601'
classmethod private2compressed_public(private_key: str) → bytes

generate compressed public key from private key

Parameters:private_key – private key
Returns:compressed public key in bytes format
classmethod private2public(private_key: str) → bytes

generate public key from private key

Parameters:private_key – private key
Returns:public key in bytes format
class asimov.Address(address: str)

Bases: object

is_pay_to_contract_hash
is_pay_to_pub_hash
to_contract_hash_script()
static to_create_contract_hash_script()
static to_create_template_hash_script()
to_create_vote_hash_script()
to_script_pub_key() → str
to_str()
type
class asimov.Transaction(vin=(), vout=(), nLockTime=0, nVersion=1, gas_limit=0)

Bases: object

serialize_size() → int
sign(sig_type=<sphinx.ext.autodoc.importer._MockObject object>)
to_buffer_writer() → _io.StringIO
to_hex() → str
class asimov.Contract(node: asimov.node.Node, address: str = None, c: asimov.data_type.SmartContract = None, template_name: str = None, args: list = None)

Bases: object

The primary entry point for working with smart contract.

execute(func_name, args=None, asset_value=0, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000') → asimov.data_type.Tx

send a transaction to execute a function in the contract and return the transaction object Tx. Note the returned Tx object is in pending status. You need to check execution status constantly and wait it confirmed on chain.

Parameters:
  • func_name – function name
  • args – function arguments
  • asset_value – the asset value to be send
  • asset_type – the asset type to be send
  • tx_fee_type – the transaction fee type
Returns:

the Tx object

>>> from asimov import Contract, Node, AsimovSolc
>>> node = Node("http://seed.asimov.tech")
>>> contract = Contract(node, c=AsimovSolc.compile("/path/to/my/sources/tutorial.sol")['Tutorial'])
>>> tx = contract.execute("mint", [1000000])
>>> tx.check()  # 1 / 0
fetch(tx_id) → asimov.data_type.EvmLogs

fetch the contract execution logs in the transaction

Parameters:tx_id – contract transaction id
Returns:the EvmLogs object
read(func_name, args=None)

call a view/pure function in the contract and return the execution result

Parameters:
  • func_name – function name
  • args – function arguments
Returns:

the return value of the readonly function

>>> from asimov import Contract, Node, AsimovSolc
>>> node = Node("http://seed.asimov.tech")
>>> contract = Contract(node, c=AsimovSolc.compile("/path/to/my/sources/example.sol")['Example'])
>>> contract.read("readonly function name")
vote(func_name, args=None, asset_value=0, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000') → asimov.data_type.Tx

send a transaction to vote on a contract and return the transaction object Tx Note the returned Tx object is in pending status. You need to check execution status constantly and wait it confirmed on chain.

Parameters:
  • func_name – function name
  • args – function arguments
  • asset_value – the asset value to be send
  • asset_type – the asset type to be send
  • tx_fee_type – the transaction fee type
Returns:

the Tx object

>>> from asimov import Contract, Node, AsimovSolc
>>> node = Node("http://seed.asimov.tech")
>>> contract = Contract(node, c=AsimovSolc.compile("/path/to/my/sources/tutorial.sol")['Tutorial'])
>>> contract.vote("vote", [1]).check()
class asimov.Node(provider: str = None, private_key: str = None)

Bases: object

A wrapped object for asimov node

address

get the corresponding account address

balance(address: str = None, asset='000000000000000000000000') → Union[int, dict]

get the balance of specific address by given asset type

Parameters:
  • address – specific address, default is current node account address
  • asset – asset type, will return balance for all asset types if none is given
Returns:

balance of given asset type, or balance for all asset types

static build_data_of_create_template(category, name, hex_code, abi, source='solidity source code') → str

binary data for template creation transaction

Parameters:
  • category – template category
  • name – template name
  • hex_code – transaction data in hex type
  • abi – template abi
  • source – template source code
Returns:

transaction data

static build_data_of_deploy_contract(contract_template: asimov.data_type.ContractTemplate, params: list) → str

binary data for contract deployment transaction

Parameters:
  • contract_template – the ContractTemplate object
  • params – parameters of contract constructor function
Returns:

transaction data

call(method: str, args: list = None)

call asimov rpc service

Parameters:
  • method – rpc function name
  • args – rpc function arguments
Returns:

the return value of the rpc function

>>> from asimov import Node
>>> node = Node("http://seed.asimov.tech")
>>> node.call("getBlockChainInfo")
{'chain': 'devnet',
 'blocks': 6841,
 'bestblockhash': '329a4289a46b5e6e6a7e63744338d63d9065c264a87f17c82bf13853806cc3ef',
 'mediantime': 1574942764,
 'pruned': False}
call_write_function(func_name: str = None, params: tuple = None, abi=None, contract_address: str = '0x660000000000000000000000000000000000000000', contract_tx_data=None, call_type='call', asset_value=0, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000', gas_price=0.1, corrected_gas=50000) → asimov.data_type.Tx

send a transaction to execute a method in the contract

Parameters:
  • func_name – function name to be called in the contract
  • params – call parameters
  • abi – contract abi
  • contract_address – contract address
  • contract_tx_data – binary data of the transaction
  • call_type – call type
  • asset_value – asset value to send
  • asset_type – asset type to send
  • tx_fee_type – transaction fee type
  • gas_price – gas price
  • corrected_gas – adjusted gas value
Returns:

the Tx object

check(tx_id: str) → int

If the transaction is a normal transaction, this function checks whether a transaction is confirmed on chain. If the transaction is a contract transaction, this function checks whether a transaction is confirmed on chain and returns contract execution status.

Parameters:tx_id – transaction id
Returns:return 1 if the transaction is confirmed on chain and the execution result is success.
>>> from asimov import Node, constant
>>> node = Node(
        "http://seed.asimov.tech",
        "0xafd29358a5ba9e2f5aac5cd5013a6830a99e34a68c469c78ab5f4c6f1d8c2a46"
    )
>>> tx = node.send("0x663bc0936166c07431ed04d7dc207eb7694e223ec4", asset_value=10)
# wait tx on chain
>>> assert tx.check() is constant.SUCCESS
static create_contract_tx_output(address: str, amount: int, data: str, assets: str = '000000000000000000000000', contract_type='call') → dict

create contract transaction output. in asimov, contract call is wrapped in transaction output.

Parameters:
  • address – output address
  • amount – output amount
  • data – output data
  • assets – output asset id in hex string format
  • contract_type – contract call type, default is ‘call’
Returns:

output dict

static create_tx_output(address: str, amount: int, assets: str = '000000000000000000000000')

create transaction output.

Parameters:
  • address – output address
  • amount – output amount
  • assets – output asset id in hex string format
Returns:

output dict

current_height

get the current height of chain

estimate_gas(tx_hex: str, inputs: list, corrected_value=50000)

estimate transaction execution gas cost :param tx_hex: transaction in hex format :param inputs: UTXO used in transaction :param corrected_value: corrected gas value :return:

get_contract_template(address: str = None, key: str = None, name: str = None) → asimov.data_type.ContractTemplate

get contract template object according to address, key or name

Parameters:
  • address – contract address
  • key – template key (template id)
  • name – template name
Returns:

the ContractTemplate object

private_key

get the account private key

send(address, asset_value: int, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000') → asimov.data_type.Tx

send a normal transaction on asimov chain and return the transaction object Tx

Parameters:
  • address – target address
  • asset_value – asset value to send
  • asset_type – asset type to send
  • tx_fee_type – transaction fee type
Returns:

the Tx object

>>> from asimov import Node, constant
>>> node = Node(
        "http://seed.asimov.tech",
        "0x98ca5264f6919fc12536a77c122dfaeb491ab01ed657c6db32e14a252a8125e3"
    )
>>> node.send(
        "0x663bc0936166c07431ed04d7dc207eb7694e223ec4",
        asset_value=10, asset_type=constant.ASCOIN,
        tx_fee_type=constant.ASCOIN
    )
[id: 91c4645bcf3680c699a591632cd8769abe2973fd2de70081a6752d9781f2801b]
set_private_key(private_key: str)

set the account private key

set_rpc_server(url: str)

set rpc server url :param url: rpc server url

wait_for_confirmation(tx_id, confirm_num=1, timeout=60) → bool

wait for the transaction to be confirmed on chain

Parameters:
  • tx_id – transaction id
  • confirm_num – confirmed block count, default is 1
  • timeout – time out length, default is 60 seconds
Returns:

true if confirmed, false otherwise

class asimov.AsimovSolc

Bases: object

The primary entry point for working with solidity compiler.

classmethod compile(source_file: str, **kwargs) → dict

compile solidity source file

Parameters:
  • source_file – source file path
  • kwargs (dict) –

    reference to compile_files function in py-solc library

Returns:

multiple compiled contract objects in dict type

>>> from asimov import AsimovSolc
>>> AsimovSolc.compile("/path/to/my/sources/example.sol")
{'Example': {
    'abi': [{
        'inputs': [],
        'payable': False,
        'stateMutability': 'nonpayable',
        'type': 'constructor'
    }],
    'address': None,
    'bytecode': '6080604052348015600f57600080fd5b50603580601d6000396000f3006080604052600080fd00a165627a7a72305820bf199053a6eea79c7732c9211fc200781b170db435d118cbd86d2ac117e2fa360029',
    'source': 'pragma solidity ^0.4.25;\n'
              '\n'
              'contract Example {\n'
              '    constructor() public {}\n'
              '}\n'
    }
}
classmethod set_solidity_compiler(compiler_path: str) → None

set solidity compiler path

Parameters:compiler_path – solidity compiler path
Returns:None
>>> from asimov import AsimovSolc
>>> AsimovSolc.set_solidity_compiler("/usr/local/bin/solc")
class asimov.EvmLogParser

Bases: object

The primary entry point for working with Asimov smart contract execution logs.

classmethod parse(raw_log: Union[dict, list], abi: Union[dict, str]) → asimov.data_type.EvmLogs

Parse asimov vm execution log

Parameters:
  • raw_log – contract execution log
  • abi – contract abi object in json format
Returns:

parsed log list

class asimov.Template(node: asimov.node.Node)

Bases: object

deploy_contract(template_id: str, constructor_arguments=None, asset_value=0, asset_type='000000000000000000000000', tx_fee_type='000000000000000000000000') -> (<class 'asimov.data_type.Tx'>, <class 'str'>)

deploy a contract based on a given template id and return the address of the newly deployed contract on asimov blockchain and transaction object

Parameters:
  • template_id – template id
  • constructor_arguments – contract constructor arguments
  • asset_value – asset value to send
  • asset_type – asset type to send
  • tx_fee_type – transaction fee type
Returns:

the transaction object Tx and the address of new contract

>>> from asimov import Node, Template, constant
>>> node = Node(
        "http://seed.asimov.tech",
        "0x98ca5264f6919fc12536a77c122dfaeb491ab01ed657c6db32e14a252a8125e3"
    )
>>> t = Template(node)
>>> tx = t.submit("tutorial.sol", "template name1", "Tutorial")
>>> assert tx.check() is constant.SUCCESS
>>> t.deploy_contract(tx.id)
[id: 2b7af42268f1ae098bc959d52c2c7d05af9cb44b2f2b6c8cfeb5c3afab941d5b]
submit(source, template_name, chosen_contract, tx_fee_type='000000000000000000000000') → asimov.data_type.Tx

submit a new template to asimov blockchain and return the transaction object Tx

Parameters:
  • source – smart contract source file path
  • template_name – template name
  • chosen_contract – contract name
  • tx_fee_type – transaction fee type
Returns:

the transaction object Tx

>>> from asimov import Node, Template
>>> node = Node(
    "http://seed.asimov.tech",
    "0x98ca5264f6919fc12536a77c122dfaeb491ab01ed657c6db32e14a252a8125e3"
    )
>>> t = Template(node)
>>> tx = t.submit("tutorial.sol", "template name1", "Tutorial")
>>> tx
[id: 8414ceb0d6db9c6418cd62c022168d961e69de80f662f0cdd99669f5954955ae]
# template id
>>> tx.id
'8414ceb0d6db9c6418cd62c022168d961e69de80f662f0cdd99669f5954955ae'
class asimov.Asset(contract, asset_type: int, asset_index: int)

Bases: object

The primary entry point for working with asset on asimov chain.

Asimov asset consists of 3 parts

#. asset_type, 4 bytes long, each bit contains an asset property. For now, the first bit is used to determine whether an asset is divisible and the second bit is used to determine whether the asset is restricted. #. org_id, 4 bytes long organization id, system wide unique id assigned to organization when registering to asimov platform. #. asset_index, 4 bytes long asset index in organization, the assigning rule is determined by the organization itself.

static asset2str(asset: int) → str

convert asset id from int to hex string without 0x :param asset: asset id in int format :return: asset id in hex string format

>>> from asimov import Asset
>>> Asset.asset2str(4294967297)
'000000000000000100000001'
asset_id_int

get the asset id in int format

asset_id_str

get the asset id in hex string format

static asset_wrapper(asset_type, org_id, asset_index) → int

asimov asset wrapper

Parameters:
  • asset_type – asset type.
  • org_id – organization id.
  • asset_index – asset index.
Returns:

asimov asset id in int format

>>> from asimov import Asset
>>> Asset.asset_wrapper(0, 1, 1)
4294967297
class asimov.PrivateKeyFactory

Bases: object

Private key generator

classmethod generate_key() → str

Create a new private key and return.

Returns:a private key in string form.
>>> from asimov import PrivateKeyFactory
>>> PrivateKeyFactory.generate_key()
'bba692e559fda550d0157669b101bafddb23e7f57aeeb5cef5494e7a41a1f056'

# note that the key generated above is a random value, it will be different in your try