account_id

class AccountId

NEAR Account Identifier.

This is a unique, syntactically valid, human-readable account identifier on the NEAR network.

Example

>>> from pyonear.account_id import AccountId
>>> alice = AccountId("alice.near")
>>> AccountId("ƒelicia.near") # (ƒ is not f)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: the Account ID contains an invalid character 'ƒ' at index 0
MAX_LEN = 64
MIN_LEN = 2
static from_bytes(data)

Deserialize from bytes.

Parameters:

data (bytes) – the serialized object.

Returns: the deserialized object.

static from_json(raw)

Build from a JSON string.

is_implicit()

Returns True if the AccountId is a 64 characters long hexadecimal.

See Implicit-Accounts.

Example

>>> from pyonear.account_id import AccountId
>>> AccountId("alice.near").is_implicit()
False
>>> rando = AccountId("98793cd91a3f870fb126f66285808c7e094afcfc4eda8a970f6648cdf0dbd6de")
>>> rando.is_implicit()
True
is_sub_account_of(parent)

Returns `True if the AccountId is a direct sub-account of the provided parent account.

See Subaccounts.

Example

>>> from pyonear.account_id import AccountId
>>> near_tla = AccountId("near")
>>> near_tla.is_top_level()
True
>>> alice = AccountId("alice.near")
>>> alice.is_sub_account_of(near_tla)
True
>>> alice_app = AccountId("app.alice.near")
>>> alice_app.is_sub_account_of(alice)
True
>>> alice_app.is_sub_account_of(near_tla)
False
is_system()

Returns True if this AccountId is the system account.

See System account.

Example

>>> from pyonear.account_id import AccountId
>>> AccountId("alice.near").is_system()
False
>>> AccountId("system").is_system()
True
is_top_level()

Returns True if the AccountId is a top-level NEAR Account ID.

See Top-level Accounts.

Example

>>> from pyonear.account_id import AccountId
>>> AccountId("near").is_top_level()
True
>>> AccountId("alice").is_top_level()
True
>>> AccountId("alice.near").is_top_level()
False
to_json()

Convert to a JSON string.

static validate(account_id)

Validates a string as a well-structured NEAR Account ID.

Checks Account ID validity without constructing an AccountId instance.

Example

>>> from pyonear.account_id import AccountId
>>> AccountId.validate("alice.near")
>>> AccountId.validate("ƒelicia.near")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: the Account ID contains an invalid character 'ƒ' at index 0