contract

call_contract(script_hash: UInt160, method: str, args: Sequence = (), call_flags: CallFlags = CallFlags.ALL) Any

Calls a smart contract given the method and the arguments. Since the return is type Any, you’ll probably need to type cast the return.

>>> call_contract(NEO, 'balanceOf', [UInt160(b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2')])
100
Parameters:
  • script_hash (UInt160) – the target smart contract’s script hash

  • method (str) – the name of the method to be executed

  • args (Sequence[Any]) – the specified method’s arguments

  • call_flags (CallFlags) – the CallFlags to be used to call the contract

Returns:

the result of the specified method

Return type:

Any

Raises:

Exception – raised if there isn’t a valid CallFlags, the script hash is not a valid smart contract or the method was not found or the arguments aren’t valid to the specified method.

create_contract(nef_file: bytes, manifest: bytes, data: Optional[Any] = None) Contract

Creates a smart contract given the script and the manifest.

>>> nef_file_ = get_script(); manifest_ = get_manifest()    # get the script and manifest somehow
... create_contract(nef_file_, manifest_, None)             # smart contract will be deployed
{
    'id': 2,
    'update_counter': 0,
    'hash': b'\x92\x8f+1q\x86z_@\x94\xf5pE\xcb\xb8 \x0f\\`Z',
    'nef': b'NEF3neo3-boa by COZ-1.0.0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x07W\x00\x02xy\x9e@\xf9\7b\xbb\xcc',
    'manifest': {
        'name': 'TestContract',
        'group': [],
        'supported_standards': [],
        'abi': [[['test', [['a', 17], ['b', 17]], 17, 0, False]], []],
        'permissions': [],
        'trusts': [],
        'extras': 'null'
    },
}
Parameters:
  • nef_file (bytes) – the target smart contract’s compiled nef

  • manifest (bytes) – the manifest.json that describes how the script should behave

  • data (Any) – the parameters for the _deploy function

Returns:

the contract that was created

Return type:

Contract

Raises:

Exception – raised if the nef or the manifest are not a valid smart contract.

update_contract(nef_file: bytes, manifest: bytes, data: Optional[Any] = None)

Updates the executing smart contract given the script and the manifest.

>>> nef_file_ = get_script(); manifest_ = get_manifest()    # get the script and manifest somehow
... update_contract(nef_file_, manifest_, None)             # smart contract will be updated
None
Parameters:
  • nef_file (bytes) – the new smart contract’s compiled nef

  • manifest (bytes) – the new smart contract’s manifest

  • data (Any) – the parameters for the _deploy function

Raises:

Exception – raised if the nef and the manifest are not a valid smart contract or the new contract is the same as the old one.

destroy_contract()

Destroy the executing smart contract.

>>> destroy_contract()
None
get_minimum_deployment_fee() int

Gets the minimum fee of contract deployment.

>>> get_minimum_deployment_fee()
1000000000
Returns:

the minimum fee of contract deployment

get_call_flags() CallFlags

Gets the CallFlags in the current context.

>>> get_call_flags()
CallFlags.READ_ONLY
create_standard_account(pub_key: ECPoint) UInt160

Calculates the script hash from a public key.

>>> create_standard_account(ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a'))
b'\r\xa9g\xa4\x00C+\xf2\x7f\x8e\x8e\xb4o\xe8\xace\x9e\xcc\xde\x04'
Parameters:

pub_key (ECPoint) – the given public key

Returns:

the corresponding script hash of the public key

Return type:

UInt160

create_multisig_account(m: int, pub_keys: List[ECPoint]) UInt160

Calculates corresponding multisig account script hash for the given public keys.

>>> create_multisig_account(1, [ECPoint(b'\x03\x5a\x92\x8f\x20\x16\x39\x20\x4e\x06\xb4\x36\x8b\x1a\x93\x36\x54\x62\xa8\xeb\xbf\xf0\xb8\x81\x81\x51\xb7\x4f\xaa\xb3\xa2\xb6\x1a')])
b'"5,\xd2\x9e\xe7\xb4\x02\x08b\xdbd\x1e\xedx\x82\x8fU(m'
Parameters:
  • m (int) – the minimum number of correct signatures need to be provided in order for the verification to pass.

  • pub_keys (List[ECPoint]) – the public keys of the account

Returns:

the hash of the corresponding account

Return type:

UInt160

NEO: UInt160

NEO’s token script hash.

>>> NEO
b'\xf5c\xea@\xbc(=M\x0e\x05\xc4\x8e\xa3\x05\xb3\xf2\xa0s@\xef'
GAS: UInt160

GAS’ token script hash.

>>> GAS
b'\xcfv\xe2\x8b\xd0\x06,JG\x8e\xe3Ua\x01\x13\x19\xf3\xcf\xa4\xd2'

Subpackages

class CallFlags(value)

Bases: IntFlag

Defines special behaviors allowed when invoking smart contracts, e.g., chain calls, sending notifications and modifying states.

Check out Neo’s Documentation to learn more about CallFlags.

NONE

Special behaviors of the invoked contract are not allowed, such as chain calls, sending notifications, modifying state, etc.

READ_STATES

Indicates that the called contract is allowed to read states.

WRITE_STATES

Indicates that the called contract is allowed to write states.

ALLOW_CALL

Indicates that the called contract is allowed to call another contract.

ALLOW_NOTIFY

Indicates that the called contract is allowed to send notifications.

STATES

Indicates that the called contract is allowed to read or write states.

READ_ONLY

Indicates that the called contract is allowed to read states or call another contract.

ALL

All behaviors of the invoked contract are allowed.

class Contract

Bases: object

Represents a contract that can be invoked.

Check out Neo’s Documentation to learn about Smart Contracts.

Variables:
  • id (int) – the serial number of the contract

  • update_counter (int) – the number of times the contract was updated

  • hash (UInt160) – the hash of the contract

  • nef (bytes) – the serialized Neo Executable Format (NEF) object holding of the smart contract code and compiler information

  • manifest (ContractManifest) – the manifest of the contract

class ContractManifest

Bases: object

Represents the manifest of a smart contract.

When a smart contract is deployed, it must explicitly declare the features and permissions it will use.

When it is running, it will be limited by its declared list of features and permissions, and cannot make any behavior beyond the scope of the list.

For more details, check out NEP-15 or Neo’s Documentation.

Variables:
  • name (str) – The name of the contract.

  • groups (List[ContractGroup]) – The groups of the contract.

  • supported_standards (List[str]) – Indicates which standards the contract supports. It can be a list of NEPs.

  • abi (ContractAbi) – The ABI of the contract.

  • permissions (List[ContractPermission]) – The permissions of the contract.

  • trusts (List[ContractPermissionDescriptor] or None) –

    The trusted contracts and groups of the contract.

    If a contract is trusted, the user interface will not give any warnings when called by the contract.

  • extras (str) – Custom user data as a json string.

class ContractPermission

Bases: object

Represents a permission of a contract. It describes which contracts may be invoked and which methods are called.

If a contract invokes a contract or method that is not declared in the manifest at runtime, the invocation will fail.

Variables:
  • contract (ContractPermissionDescriptor or None) –

    Indicates which contract to be invoked.

    It can be a hash of a contract, a public key of a group, or a wildcard *.

    If it specifies a hash of a contract, then the contract will be invoked; If it specifies a public key of a group, then any contract in this group may be invoked; If it specifies a wildcard *, then any contract may be invoked.

  • methods (List[str] or None) –

    Indicates which methods to be called.

    It can also be assigned with a wildcard *. If it is a wildcard *, then it means that any method can be called.

class ContractPermissionDescriptor

Bases: object

Indicates which contracts are authorized to be called.

Variables:
  • hash (UInt160 or None) – The hash of the contract.

  • group (ECPoint or None) – The group of the contracts.

class ContractGroup

Bases: object

Represents a set of mutually trusted contracts.

A contract will trust and allow any contract in the same group to invoke it, and the user interface will not give any warnings.

A group is identified by a public key and must be accompanied by a signature for the contract hash to prove that the contract is indeed included in the group.

Variables:
  • pubkey (ECPoint) – The public key of the group.

  • signature (bytes) – The signature of the contract hash which can be verified by pubkey.

class ContractAbi

Bases: object

Represents the ABI of a smart contract.

For more details, check out NEP-14 or Neo’s Documentation.

Variables:
class ContractMethodDescriptor

Bases: object

Represents a method in a smart contract ABI.

Variables:
  • name (str) – The name of the method.

  • parameters (List[ContractParameterDefinition]) – The parameters of the method.

  • return_type (ContractParameterType) – Indicates the return type of the method.

  • offset (int) – The position of the method in the contract script.

  • safe (bool) –

    Indicates whether the method is a safe method.

    If a method is marked as safe, the user interface will not give any warnings when it is called by other contracts.

class ContractEventDescriptor

Bases: object

Represents an event in a smart contract ABI.

Variables:
class ContractParameterDefinition

Bases: object

Represents a parameter of an event or method in ABI.

Variables:
class ContractParameterType(value)

Bases: IntEnum

An enumeration.

Any = 0
Boolean = 16
Integer = 17
ByteArray = 18
String = 19
Hash160 = 20
Hash256 = 21
PublicKey = 22
Signature = 23
Array = 32
Map = 34
InteropInterface = 48
Void = 255