IconScoreBase

class IconScoreBase(db: iconservice.iconscore.db.IconScoreDatabase)

A base class of SCOREs. This class provides facilities and environments to SCORE to run.

__init__(db: iconservice.iconscore.db.IconScoreDatabase) → None

A Python init function. Invoked when the contract is loaded at each node. Do not put state-changing works in here.

address

The current SCORE address

Returns:Address current address
block

Deprecated property

Use block_height and now() instead.

block_height

Current block height

Returns:current block height
call(addr_to: iconservice.base.address.Address, func_name: str, kw_dict: dict, amount: int = 0)

Calls an external function provided by another SCORE. func_name can be None if fallback calls

Parameters:
  • addr_toAddress the address of another SCORE
  • func_name – function name of another SCORE
  • kw_dict – arguments of the external function
  • amount – amount of ICX to transfer in loop
Returns:

returning value of the external function

static create_interface_score(addr_to: iconservice.base.address.Address, interface_cls: Callable[[Address], T]) → T

Creates an object, through which you have an access to the designated SCORE’s external functions.

Parameters:
  • addr_to – SCORE address
  • interface_cls – interface class
Returns:

An instance of given class

db

An instance used to access state DB

Returns:IconScoreDatabase db
fallback() → None

fallback function can not be decorated with @external. (i.e., fallback function is not allowed to be called by external contract or user.) This fallback function is executed whenever the contract receives plain icx coins without data. If the fallback function is not decorated with @payable, it is not listed on the SCORE APIs also cannot be called.

icx

An object used to transfer icx coin

  • icx.transfer(addr_to(address), amount(integer)) -> bool Transfers designated amount of icx coin to addr_to. If exception occurs during execution, the exception will be escalated. Returns True if coin transfer succeeds.
  • icx.send(addr_to(address), amount(integer)) -> bool Sends designated amount of icx coin to addr_to. Basic behavior is same as transfer, the difference is that exception is caught inside the function. Returns True when coin transfer succeeded, False when failed.
Returns:Icx instance of icx
msg

Holds information of calling the SCORE

  • msg.sender : Address of the account who called this function. If other contact called this function, msg.sender points to the caller contract’s address.
  • msg.value : Amount of icx that the sender attempts to transfer to the current SCORE.
now() → int

Timestamp of current block in microseconds

Returns:timestamp in microseconds
on_install(**kwargs) → None

Invoked when the contract is deployed for the first time, and will not be called again on contract update or deletion afterward. This is the place where you initialize the state DB.

on_update(**kwargs) → None

Invoked when the contract is deployed for update. This is the place where you migrate old states.

owner

Address of the account who deployed the contract

Returns:Address owner address
static revert(message: Optional[str] = None, code: int = 0)

Deprecated method

Use global function revert() instead.

tx

Holds information of the transaction

Returns:Transaction transaction