Package genlayer.std.genvm_contracts#

Warning

This is an internal module

class genlayer.std.genvm_contracts.Contract[source]#

Class that indicates main user contract

abstract __handle_undefined_method__(method_name: str, args: list[Any], kwargs: dict[str, Any])[source]#

Method that is called for no-method calls, must be either @gl.public.write or @gl.public.write.payable

__on_errored_message__()[source]#

Method that is called when emitted message with non-zero value failed. This method is not abstract to just receive value. It must be @gl.public.write.payable

abstract __receive__()[source]#

Method that is called for no-method transfers, must be @gl.public.write.payable

property address: Address#
Returns:

Address of this contract

property balance: u256#

Current balance of this contract

class genlayer.std.genvm_contracts.ContractAt[source]#

Provides a way to call view methods and send transactions to GenVM contracts

__init__(addr: Address)[source]#
address: Address#

Address to which this proxy points

emit(**data: Unpack[TransactionDataKwArgs])[source]#

Namespace with write message

Returns:

object supporting .name(*args, **kwargs) that emits a message and returns None

emit_transfer(**data: Unpack[TransactionDataKwArgs])[source]#

Method to emit a message that transfers native tokens

view()[source]#

Namespace with all view methods

Returns:

object supporting .name(*args, **kwargs) that calls a contract and returns its result (Any) or rises its Rollback

Note

supports name.lazy(*args, **kwargs) call version

class genlayer.std.genvm_contracts.DeploymentTransactionDataKwArgs[source]#

Class for representing parameters of deploy_contract

clear() None.  Remove all items from D.#
copy() a shallow copy of D#
fromkeys(value=None, /)#

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)#

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
pop(k[, d]) v, remove specified key and return the corresponding value.#

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()#

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

salt_nonce: NotRequired[u256 | Literal[0]]#

iff it is provided and does not equal to \(0\) then Address of deployed contract will be known ahead of time. It will depend on this field

setdefault(key, default=None, /)#

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from mapping/iterable E and F.#

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values#
class genlayer.std.genvm_contracts.TransactionDataKwArgs[source]#

Built-in parameters of all transaction messages that a contract can emit

Warning

parameters are subject to change!

clear() None.  Remove all items from D.#
copy() a shallow copy of D#
fromkeys(value=None, /)#

Create a new dictionary with keys from iterable and values set to value.

get(key, default=None, /)#

Return the value for key if key is in the dictionary, else default.

items() a set-like object providing a view on D's items#
keys() a set-like object providing a view on D's keys#
pop(k[, d]) v, remove specified key and return the corresponding value.#

If the key is not found, return the default if given; otherwise, raise a KeyError.

popitem()#

Remove and return a (key, value) pair as a 2-tuple.

Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.

setdefault(key, default=None, /)#

Insert key with a value of default if key is not in the dictionary.

Return the value for key if key is in the dictionary, else default.

update([E, ]**F) None.  Update D from mapping/iterable E and F.#

If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]

values() an object providing a view on D's values#
genlayer.std.genvm_contracts.contract_interface(_contr: GenVMContractDeclaration) Callable[[Address], GenVMContractProxy][source]#

This decorator produces an “interface” for other GenVM contracts. It has no semantical value, but can be used for auto completion and type checks

@gl.contract_interface
class MyContract:
  class View:
    def view_meth(self, i: int) -> int: ...

  class Write:
    def write_meth(self, i: int) -> None: ...
Return type:

Callable[[Address], GenVMContractProxy]

genlayer.std.genvm_contracts.deploy_contract(*, code: bytes, args: Sequence[Any] = [], kwargs: Mapping[str, Any] = {}) None[source]#
genlayer.std.genvm_contracts.deploy_contract(*, code: bytes, args: Sequence[Any] = [], kwargs: Mapping[str, Any] = {}, salt_nonce: Literal[0], **rest: Unpack[TransactionDataKwArgs]) None
genlayer.std.genvm_contracts.deploy_contract(*, code: bytes, args: Sequence[Any] = [], kwargs: Mapping[str, Any] = {}, salt_nonce: u256, **rest: Unpack[TransactionDataKwArgs]) Address

Function for deploying new genvm contracts

Parameters:
  • code – code (i.e. contents of a python file) of the contract

  • args – arguments to be encoded into calldata

  • kwargs – keyword arguments to be encoded into calldata

Returns:

address of new contract iff non-zero salt_nonce was provided

Note

Refer to consensus documentation for exact specification of

  • salt_nonce requirements and it’s effect on address

  • order of transactions