API Documentation

Identity

Crypto / API Documentation / Identity / Address

Derive an address from a passphrase

def from_passphrase(cls, passphrase: str) -> str:

Parameters

TypeNameRequiredDescription
strpassphraseYesPassphrase

Return Value

This function returns an address derived from the given passphrase as a string.

from crypto.identity.address import Address

address = Address.from_passphrase("super secret passphrase")

>> '0x2289577F3784788784226Eb41E9B0ca9705C7C37'

Derive an address from a public key

def from_public_key(cls, public_key: str) -> str:

Parameters

TypeNameRequiredDescription
strpublic_keyYesPublic key

Return Value

This function returns an address derived from the given public key as a string.

from crypto.identity.address import Address

address = Address.from_public_key("023efc1da7f315f3c533a4080e491f32cd4219731cef008976c3876539e1f192d3")

>> '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22'

Derive an address from a private key

def from_private_key(cls, private_key: str) -> str:

Parameters

TypeNameRequiredDescription
strprivate_keyYesAddress in hexadecimal format

Return Value

This function returns an address derived from the given private key as a string.

from crypto.identity.address import Address

address = Address.from_private_key("50829dd3b7ffbe2df401d730b5e60cea7520ba3f3a18e5b1490707667fb43fae")

>> '0x1E6747BEAa5B4076a6A98D735DF8c35a70D18Bdd'

Validate the given address

def validate(cls, address: str) -> bool:

Parameters

TypeNameRequiredDescription
straddressYesAddress to validate

Return Value

This method returns a boolean indicating the validity of the address.

from crypto.identity.address import Address

is_valid = Address.validate('0x2289577F3784788784226Eb41E9B0ca9705C7C37');

>> True
Crypto / API Documentation / Identity / PrivateKey

Derive a private key from a passphrase

def from_passphrase(passphrase: str):

Parameters

TypeNameRequiredDescription
strpassphraseYesPassphrase

Return Value

This method returns a PrivateKey object derived from the given passphrase.

from crypto.identity.private_key import PrivateKey

private_key = PrivateKey.from_passphrase("super secret passphrase")

>> PrivateKey

Derive a private key from a hex string

def from_hex(private_key: str):

Parameters

TypeNameRequiredDescription
strprivate_keyYesHexadecimal representation of the private key

Return Value

This method returns a PrivateKey object derived from a hex string.

from crypto.identity.private_key import PrivateKey

private_key = PrivateKey.from_hex("d8839c2432bfd0a67ef10a804ba991eabba19f154a3d707917681d45822a5712")

>> PrivateKey

Derive a private key from a WIF

def from_wif(wif: str):

Parameters

TypeNameRequiredDescription
strwifYesHexadecimal representation of the WIF string

Return Value

This method returns a PrivateKey object derived from a WIF string.

from crypto.identity.private_key import PrivateKey

private_key = PrivateKey.from_wif("UZYnRZ8qpeQWTLeCNzw93guWSdKLmr2vHEWGG4sNv7TJofL7TZvy")

>> PrivateKey

Signs a message using the private key

def sign(self, message: bytes) -> bytes:

Parameters

TypeNameRequiredDescription
bytesmessageYesMessage to sign in bytes

Return Value

This method signs a message using the private key.

from crypto.identity.private_key import PrivateKey

private_key = PrivateKey.from_passphrase('this is a top secret passphrase');
signature = private_key.sign(bytes.fromhex("Hello World"));

>> bytes
Crypto / API Documentation / Identity / PublicKey

Derive a public key from a passphrase

def from_passphrase(passphrase: str) -> PublicKey:

Parameters

TypeNameRequiredDescription
strpassphraseYesPassphrase to derive the public key

Return Value

This function returns a public key instance object derived from the given passphrase.

from crypto.identity.public_key import PublicKey

public_key = PublicKey.from_passphrase("super secret passphrase")

>> PublicKey

Create a public key instance from a hex string

def from_hex(public_key: str) -> PublicKey:

Parameters

TypeNameRequiredDescription
strpublic_keyYesHexadecimal representation of the public key

Return Value

This function returns a PublicKey object created from the given hex string.

from crypto.identity.public_key import PublicKey

public_key = PublicKey.from_hex("validPublicKeyHex")

>> PublicKey

Recover a public key from a signature

def recover(cls, message: bytes, signature: bytes) -> PublicKey:

Parameters

TypeNameRequiredDescription
bytesmessageYesMessage to use to recover
bytessignatureYesSignature to use to recover

Return Value

This function returns a PublicKey object recovered from the given signature and message.

from crypto.identity.public_key import PublicKey

publicKey = PublicKey.recover(message, signature);

>> PublicKey
Crypto / API Documentation / Identity / WIF

Derive a WIF from a passphrase

def wif_from_passphrase(passphrase: str, network_wif: Optional[int] = None) -> str:

Parameters

TypeNameRequiredDescription
strpassphraseYesPassphrase to derive the WIF
intnetwork_wifNoOptional network WIF

Return Value

This function returns a Wallet Import Format (WIF) string derived from the passphrase.

from crypto.identity.wif import WIF

wif = WIF.from_passphrase("super secret passphrase", 170)

>> 'L2KVU2v4a1kgwem1S7LhWhTkzwMBvd1aR9Kh8itwu1c7cnRXAUxE'

Network

Crypto / API Documentation / Configuration / Network

Set the network you want to use in the crypto library

def set_network(network: AbstractNetwork) -> None:

Parameters

TypeNameRequiredDescription
AbstractNetworknetworkYesNetwork object (Testnet, Mainnet, etc)

Return Value

This method returns void.

from crypto.configuration.network import Network
from crypto.networks.mainnet import Mainnet

Network.set_network(Mainnet())

>> None
# Custom network example

from crypto.configuration.network import Network
from crypto.networks.abstract_network import AbstractNetwork

class CustomNetwork(AbstractNetwork) {
  ...
}

Network.set_network(CustomNetwork())

>> None

Get the currently used network

def get_network() -> AbstractNetwork:

Return Value

This function returns the current network.

from crypto.configuration.network import Network

current_network = Network.get_network()

>> AbstractNetwork

Get the chain ID of the Network

def chainId(self) -> int:

Return Value

This method returns the chain ID as an integer.

from crypto.networks.testnet import Testnet

Testnet().chainId()

>> 10000

Get the epoch time of the start of the Network

def epoch(self) -> str:

Return Value

This method returns the epoch time in string format.

from crypto.networks.testnet import Testnet

Testnet().epoch()

>> '2017-03-21T13:00:00.000Z'

Get the WIF of the Network as a hexadecimal string

def wif(self) -> str:

Return Value

This method returns the WIF in hexadecimal string format.

from crypto.networks.testnet import Testnet

Testnet().wif()

>> 'ba'

Transactions

Crypto / API Documentation / Transactions / AbstractTransactionBuilder

For full examples of using the Builders to create transactions, please have a look at the Examples page.

Create a new transaction instance

def new(cls, data: Optional[dict] = None):

Parameters

TypeNameRequiredDescription
dictdataNoOptional transaction data

Return Value

This method creates and returns a new transaction builder instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = TransferBuilder.new()

>> TransferBuilder

Convert the transaction to its string representation

def __str__(self):

Return Value

This method returns the string representation of the transaction.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = str(TransferBuilder.new())

>> '{"gasPrice":"5000000000","network":30,"gas":1000000,"nonce":"1","senderPublicKey":"","value":"0","data":""}'

Set the gas limit for the transaction

def gasLimit(self, gas: int):

Parameters

TypeNameRequiredDescription
intgasLimitYesGas limit for the transaction

Return Value

This method sets the gas limit for the transaction and returns the builder instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = TransferBuilder.new().gasLimit(21000)

>> TransferBuilder

Set the recipient address for the transaction

def to(self, to: str):

Parameters

TypeNameRequiredDescription
strtoYesRecipient address

Return Value

This method sets the recipient address for the transaction and returns the builder instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = TransferBuilder.new().to('0xb693449AdDa7EFc015D87944EAE8b7C37EB1690A')

>> TransferBuilder

Set the gas price for the transaction

def gas_price(self, gas_price: int):

Parameters

TypeNameRequiredDescription
intgas_priceYesGas price for the transaction

Return Value

This method sets the gas price for the transaction and returns the builder instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = TransferBuilder.new().gas_price(5000000000)

>> TransferBuilder

Set the nonce for the transaction

def nonce(self, nonce: str):

Parameters

TypeNameRequiredDescription
strnonceYesNonce for the transaction

Return Value

This method sets the nonce for the transaction and returns the builder instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = TransferBuilder.new().nonce('12')

>> TransferBuilder

Set the network for the transaction

def network(self, network: int):

Parameters

TypeNameRequiredDescription
intnetworkYesNetwork identifier for the transaction

Return Value

This method sets the network for the transaction and returns the builder instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = TransferBuilder.new().network(30)

>> TransferBuilder

Sign the transaction using the given passphrase

def sign(self, passphrase: str):

Parameters

TypeNameRequiredDescription
strpassphraseYesPassphrase for signing the transaction

Return Value

This method signs the transaction using the provided passphrase and returns the builder instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = TransferBuilder.new().sign('this is a top secret passphrase')

>> TransferBuilder

Sign the transaction with a second signature (only for legacy addresses)

def legacySecondSign(self, passphrase: str, secondPassphrase: str):

Parameters

TypeNameRequiredDescription
strpassphraseYesPassphrase for signing the transaction
strsecondPassphraseYesSecond Passphrase for signing the transaction

Return Value

This method signs the transaction using the provided passphrases and returns the builder instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
transaction = TransferBuilder.new().legacySecondSign('this is a top secret passphrase', 'this is a top secret second passphrase')

>> TransferBuilder

Verify the transaction validity

def verify(self):

Return Value

This method returns the validity of the transaction as a bool.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
is_valid = (TransferBuilder.new()
  .to('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
  .sign('this is a top secret passphrase')).verify()

>> true

Convert the transaction to a dict

def to_dict(self):

Return Value

This method converts the transaction to a dictionary and returns it.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
data = TransferBuilder.new().to_dict()

>> {
  'gasPrice': '5000000000',
  'network': 30,
  'gasLimit': 1000000,
  'nonce': 1,
  'senderPublicKey': '',
  'value': '0',
  'data': '',
}

Convert the transaction to its JSON representation

def to_json(self):

Return Value

This method converts the transaction to a JSON string and returns it.

from crypto.transactions.builder.transfer_builder import TransferBuilder

# Using TransferBuilder as an example of AbstractTransactionBuilder
json = TransferBuilder.new().to_json()

>> '{"value": "0", ..., "data": ""}'
Crypto / API Documentation / Transactions / EvmCallBuilder

Inherits from:AbstractTransactionBuilder

Set the payload for the EVM call

def payload(self, payload: str):

Parameters

TypeNameRequiredDescription
strpayloadYesEVM code in hexadecimal format (without `0x` prefix)

Return Value

This method sets the payload for the EVM call and returns the builder instance.

from crypto.transactions.builder.evm_call_builder import EvmCallBuilder

transaction = EvmCallBuilder.new().payload('yourHexPayload')

>> EvmCallBuilder
Crypto / API Documentation / Transactions / MultipaymentBuilder

Inherits from:AbstractTransactionBuilder

Add recipient to the transaction

def pay(self, address: str, value: str):

Parameters

TypeNameRequiredDescription
straddressYesAddress to recipient
strvalueYesAmount to send to recipient

Return Value

This method adds a recipient to the transaction and returns the builder instance.

from crypto.transactions.builder.multipayment_builder import MultipaymentBuilder

transaction = MultipaymentBuilder.new().pay('0x512F366D524157BcF734546eB29a6d687B762255', '100000')

>> MultipaymentBuilder
Crypto / API Documentation / Transactions / TransferBuilder

Inherits from:AbstractTransactionBuilder

Set the value to transfer (in wei)

def value(self, value: int):

Parameters

TypeNameRequiredDescription
intvalueYesAmount to transfer in the smallest unit

Return Value

This method returns the transaction instance with the value set.

from crypto.transactions.builder.transfer_builder import TransferBuilder

transaction = TransferBuilder.new().value('1000000000000000000')

>> TransferBuilder
Crypto / API Documentation / Transactions / ValidatorRegistrationBuilder

Inherits from:AbstractTransactionBuilder

Set the validator BLS public key

def validator_public_key(self, validator_public_key: str):

Parameters

TypeNameRequiredDescription
strvalidator_public_keyYesValidator BLS public key to register

Return Value

This method returns the transaction instance with the validator public key set.

from crypto.transactions.builder.validator_registration_builder import ValidatorRegistrationBuilder

transaction = ValidatorRegistrationBuilder.new().validator_public_key('954f46d6097a1d314e900e66e11e0dad0a57cd03e04ec99f0dedd1c765dcb11e6d7fa02e22cf40f9ee23d9cc1c0624bd')

>> ValidatorRegistrationBuilder

Set the locked value (in wei)

def value(self, value: int):

Parameters

TypeNameRequiredDescription
intvalueYesAmount to lock in wei

Return Value

This method returns the transaction instance with the value set.

from crypto.transactions.builder.validator_registration_builder import ValidatorRegistrationBuilder

transaction = ValidatorRegistrationBuilder.new().value('250000000000000000000')

>> ValidatorRegistrationBuilder
Crypto / API Documentation / Transactions / ValidatorResignationBuilder

Inherits from:AbstractTransactionBuilder

Crypto / API Documentation / Transactions / UsernameRegistrationBuilder

Inherits from:AbstractTransactionBuilder

Set the username

def username(self, username: str):

Parameters

TypeNameRequiredDescription
strusernameYesUsername to register

Return Value

This method returns the transaction instance with the Username set.

from crypto.transactions.builder.username_registration_builder import UsernameRegistrationBuilder

transaction = UsernameRegistrationBuilder.new().username('myusername')

>> UsernameRegistrationBuilder
Crypto / API Documentation / Transactions / UsernameResignationBuilder

Inherits from:AbstractTransactionBuilder

Crypto / API Documentation / Transactions / VoteBuilder

Inherits from:AbstractTransactionBuilder

Set the vote for the transaction

def vote(self, vote: str):

Parameters

TypeNameRequiredDescription
strvoteYesAddress to vote for

Return Value

This method returns the transaction instance with the vote set.

from crypto.transactions.builder.vote_builder import VoteBuilder

transaction = VoteBuilder.new().vote('0x512F366D524157BcF734546eB29a6d687B762255')

>> VoteBuilder
Crypto / API Documentation / Transactions / UnvoteBuilder

Inherits from:AbstractTransactionBuilder

Crypto / API Documentation / Transactions / AbstractTransaction

It is recommended to use the Transaction Builders instead of the AbstractTransaction class directly. You can also access the underlying transaction property of the Builder to work with the AbstractTransaction instance, e.g. TransferBuilder.new().transaction.

Create a new transaction instance

def __init__(self, data: dict):

Parameters

TypeNameRequiredDescription
dictdataYesThe transaction data.

Return Value

This method initializes a new transaction instance.

from crypto.transactions.transfer import Transfer

# Using Transfer as an example of AbstractTransaction
transaction = Transfer({...})

>> Transfer

Get the payload of the transaction

def get_payload(self) -> str:

Return Value

This method returns the payload of the transaction as a string.

from crypto.transactions.transfer import Transfer
from crypto.transactions.Vote import vote
from crypto.utils.abi_encoder import AbiEncoder

payload = Transfer().getPayload()

>> ''

encoded = AbiEncoder().encode_function_call('vote', ['0xC3bBE9B1CeE1ff85Ad72b87414B0E9B7F2366763'])
payload = Vote({'data': encoded}).getPayload()

>> '0x6dd7d8ea000000000000000000000000c3bbe9b1cee1ff85ad72b87414b0e9b7f2366763'

Sign the transaction using the given private key

def sign(self, private_key: PrivateKey):

Parameters

TypeNameRequiredDescription
PrivateKeyprivate_keyYesPrivate key for signing

Return Value

This method signs the transaction and returns the transaction instance.

from crypto.transactions.types.transfer import Transfer
from crypto.identity.private_key import PrivateKey

# Using Transfer as an example of AbstractTransaction
Transfer({
  'value': '1',
  'nonce': 1,
  'to': '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
  'gasPrice': 5000000000,
  'gasLimit': 21000,
}).sign(PrivateKey.fromPassphrase('this is a top secret passphrase'))

>> Transfer

Recover the sender public key and address

def recover_sender(self):

Return Value

This method recovers the sender's public key and address from the transaction signature.

from crypto.transactions.types.transfer import Transfer
from crypto.identity.private_key import PrivateKey

# Using Transfer as an example of AbstractTransaction
transfer = Transfer({
  'value': '1',
  'nonce': 1,
  'to': '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
  'gasPrice': 5000000000,
  'gasLimit': 21000,
}).sign(PrivateKey.fromPassphrase('this is a top secret passphrase'))

transfer.recoverSender()

transaction_json = transfer.toJson()

>> '{..., "to":"0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22"}'

Verify the transaction

def verify(self) -> bool:

Return Value

This method verifies the transaction signature and returns a boolean indicating validity.

from crypto.transactions.types.transfer import Transfer
from crypto.identity.private_key import PrivateKey

# Using Transfer as an example of AbstractTransaction
transfer = Transfer({
  'value': '1',
  'nonce': 1,
  'to': '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
  'gasPrice': 5000000000,
  'gasLimit': 21000,
}).sign(PrivateKey.fromPassphrase('this is a top secret passphrase'))

transfer.verify()

>> True

Serialize the transaction

def serialize(self, skip_signature: bool = False) -> bytes:

Parameters

TypeNameRequiredDescription
boolskip_signatureNoSerialization options

Return Value

This method serializes the transaction and returns it as a Buffer.

from crypto.transactions.types.transfer import Transfer

# Using Transfer as an example of AbstractTransaction
serialized = Transfer({
  'value': '1',
  'nonce': 1,
  'to': '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
  'gasPrice': 5000000000,
  'gasLimit': 21000,
}).serialize()

>> Buffer

Get the hash for the transaction

def hash(self, skip_signature: bool) -> bytes:

Parameters

TypeNameRequiredDescription
boolskip_signatureYesSerialization options

Return Value

This method computes and returns the transaction hash.

from crypto.transactions.types.transfer import Transfer

# Using Transfer as an example of AbstractTransaction
transaction_hash = Transfer({
  'value': '1',
  'nonce': 1,
  'to': '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
  'gasPrice': 5000000000,
  'gasLimit': 21000,
}).hash()

>> string

Refresh the payload of the transaction

def refresh_payload_data(self):

Return Value

This method refreshes the payload data of the transaction and returns the transaction instance.

from crypto.transactions.types.transfer import Transfer

# Using Transfer as an example of AbstractTransaction
transaction = Transfer({
  'value': '1',
  'nonce': 1,
  'to': '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
  'gasPrice': 5000000000,
  'gasLimit': 21000,
}).refresh_payload_data();

>> Transfer

Convert the transaction to a dict

def to_dict(self) -> dict:

Return Value

This method returns the transaction data as a dict.

from crypto.transactions.types.transfer import Transfer

# Using Transfer as an example of AbstractTransaction
transaction_dict = Transfer({
  'value': '1',
  'nonce': 1,
  'to': '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
  'gasPrice': 5000000000,
  'gasLimit': 21000,
}).to_dict();

>> {'gasPrice': '5000000000', 'gasLimit': '21000', ...}

Convert the transaction to its JSON representation

def to_json(self) -> str:

Return Value

This method returns the JSON representation of the transaction as a string.

from crypto.transactions.types.transfer import Transfer

# Using Transfer as an example of AbstractTransaction
transaction_dict = Transfer({
  'value': '1',
  'nonce': 1,
  'to': '0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22',
  'gasPrice': 5000000000,
  'gasLimit': 21000,
}).to_json();

>> '{"gasPrice":"5000000000", ...}'
Crypto / API Documentation / Transactions / EvmCall

Inherits from:AbstractTransaction

Crypto / API Documentation / Transactions / Multipayment

Inherits from:AbstractTransaction

Crypto / API Documentation / Transactions / Transfer

Inherits from:AbstractTransaction

Crypto / API Documentation / Transactions / ValidatorRegistration

Inherits from:AbstractTransaction

Crypto / API Documentation / Transactions / ValidatorResignation

Inherits from:AbstractTransaction

Crypto / API Documentation / Transactions / UsernameRegistration

Inherits from:AbstractTransaction

Crypto / API Documentation / Transactions / UsernameResignation

Inherits from:AbstractTransaction

Crypto / API Documentation / Transactions / Vote

Inherits from:AbstractTransaction

Crypto / API Documentation / Transactions / Unvote

Inherits from:AbstractTransaction


Serializer

Crypto / API Documentation / Transactions / Serializer

Create a new serializer instance

def new(transaction: AbstractTransaction):

Parameters

TypeNameRequiredDescription
AbstractTransactiontransactionYesThe transaction object to serialize.

Return Value

This method creates and returns a new serializer instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder
from crypto.transactions.serializer import Serializer

transaction = (TransferBuilder.new()
  .value('0')
  .gas_price('5000000000')
  .gas_limit('21000')
  .recipient_address('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
  .sign('this is a top secret passphrase')).transaction

serializer = Serializer.new(transaction)

>> Serializer

Serialize a transaction

def serialize(self, skip_signature: bool = False) -> bytes:

Parameters

TypeNameRequiredDescription
boolskip_signatureNoWhether to skip the signature in serialization.

Return Value

This method serializes the transaction into a byte array.

from crypto.transactions.builder.transfer_builder import TransferBuilder
from crypto.transactions.serializer import Serializer

transaction = (TransferBuilder.new()
  .value('0')
  .gas_price('5000000000')
  .gas_limit('21000')
  .recipient_address('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
  .sign('this is a top secret passphrase')).transaction

serialized = Serializer.new(transaction).serialize()

>> bytes

Deserializer

Crypto / API Documentation / Transactions / Deserializer

Create a new deserializer instance

def new(serialized: str):

Parameters

TypeNameRequiredDescription
strserializedYesThe serialized transaction string.

Return Value

This static method creates and returns a new deserializer instance.

from crypto.transactions.builder.transfer_builder import TransferBuilder
from crypto.transactions.deserializer import Deserializer

transaction = (TransferBuilder.new()
  .value('0')
  .gas_price('5000000000')
  .gas_limit('21000')
  .recipient_address('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
  .sign('this is a top secret passphrase')).transaction

deserializer = Deserializer.new(transaction.serialize().getHex())

>> Deserializer

Deserialize a transaction

def deserialize(self) -> AbstractTransaction:

Return Value

This method deserializes the transaction from the provided serialized data and returns an `AbstractTransaction` object.

from crypto.transactions.builder.transfer_builder import TransferBuilder
from crypto.transactions.deserializer import Deserializer

transaction = (TransferBuilder.new()
  .value('0')
  .gas_price('5000000000')
  .gas_limit('21000')
  .recipient_address('0x6F0182a0cc707b055322CcF6d4CB6a5Aff1aEb22')
  .sign('this is a top secret passphrase')).transaction

transaction = Deserializer.new(transaction.serialize().getHex()).deserialize()

>> Transfer

Decode the payload of a transaction

def decode_payload(data: dict, abi_type: ContractAbiType = ContractAbiType.CONSENSUS) -> Optional[dict]:

Parameters

TypeNameRequiredDescription
dictdataYesThe dictionary containing the payload data to decode.
ContractAbiTypeabi_typeNoContract ABI Type to decode against

Return Value

This method decodes the payload data of a transaction and returns it as a dictionary. If decoding fails, it returns `None`.

from crypto.transactions.deserializer import Deserializer
from crypto.enums.contract_abi_type import ContractAbiType

payload_data = Deserializer.decode_payload(transaction_data)

>> {'args': [...], ...}

payload_data = Deserializer.decode_payload(transaction_data, ContractAbiType.USERNAMES)

>> {'args': [...], ...}

Message

Crypto / API Documentation / Utils / Message

Create a new message instance

def new(public_key: Union[bytes, str], message: Union[bytes, str], signature: Union[bytes, str]):

Parameters

TypeNameRequiredDescription
Union[bytes, str]public_keyYesPublic key of the sender
Union[bytes, str]messageYesMessage object
Union[bytes, str]signatureYesSignature of the message

Return Value

This method returns a new message instance.

from crypto.utils.message import Message

message = Message.new(
  public_key='034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192',
  message='0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b',
  signature='Hello World',
)

>> Message

Sign a message using the given passphrase

def sign(cls, message: Union[bytes, str], passphrase: Union[bytes, str]):

Parameters

TypeNameRequiredDescription
Union[bytes, str]messageYesMessage to sign
Union[bytes, str]passphraseYesPassphrase for signing

Return Value

This method signs the message and returns a new Message instance.

from crypto.utils.message import Message

signed_message = Message.sign("Hello, blockchain!", b"super secret passphrase")

>> Message

Verify the message contents

def verify(self):

Return Value

This method verifies the message and returns a boolean value indicating validity.

from crypto.utils.message import Message

signed_message = Message.sign("Hello, blockchain!", b"super secret passphrase")
is_valid = signed_message.verify()

>> True

Convert the message to a dict

def to_dict(self):

Return Value

This method converts the message to a dict and returns it.

from crypto.utils.message import Message

signed_message = Message.sign("Hello, blockchain!", b"super secret passphrase")
message_dict = signed_message.to_dict()

>> {
  'public_key': '034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192',
  'signature': '0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b',
  'message': 'Hello World',
}

Convert the message to its string representation

def __str__():

Return Value

This method returns the string representation of the message in JSON format.

from crypto.utils.message import Message

signed_message = Message.sign("Hello, blockchain!", b"super secret passphrase")

json_message = str(signed_message)

>> '{"publickey":"034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192","signature":"0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b","message":"Hello World"}'

Convert the message to its JSON representation

def to_json(self):

Return Value

This method converts the message to a JSON string and returns it.

from crypto.utils.message import Message

signed_message = Message.sign("Hello, blockchain!", b"super secret passphrase")

json_message = signed_message.to_json()

>> '{"publickey":"034151a3ec46b5670a682b0a63394f863587d1bc97483b1b6c70eb58e7f0aed192","signature":"0x6fc765ffd60aec43dc5eff277173006c8902c4a044712f1c10fb6ea1707b0199092235829bceb59a55a83556e44599bcc5677c3a28d8532ca72db183281a48dc1b","message":"Hello World"}'

Slot

Crypto / API Documentation / Utils / Slot

Get the time difference between now and network start

def time() -> int:

Return Value

This method returns the time difference between now and the network start in int format.

from crypto.utils.slot import Slot

network_time = Slot.time()

>> 200366014

Get the network start epoch

def epoch() -> int:

Return Value

This method returns the network start epoch as a datetime object.

from crypto.utils.slot import Slot

epoch_time = Slot.epoch()

>> 1490101200

ArgumentDecoder

Crypto / API Documentation / Utils / Abi / ArgumentDecoder

Create a new argument decoder instance

def __init__(self, hex_string: str):

Parameters

TypeNameRequiredDescription
stringbytesYesThe encoded bytes to be decoded

Return Value

This method returns a new instance of the ArgumentDecoder class.

from crypto.utils.abi.argument_decoder import ArgumentDecoder

decoder = ArgumentDecoder(argument)

>> ArgumentDecoder

Decode a string

def decode_string(self) -> str:

Return Value

This method returns the decoded string.

from crypto.utils.abi.argument_decoder import ArgumentDecoder

decoder = ArgumentDecoder(argument)

string = decoder.decode_string()

>> str

Decode an Address

def decode_address(self) -> str:

Return Value

This method returns the decoded address.

from crypto.utils.abi.argument_decoder import ArgumentDecoder

decoder = ArgumentDecoder(argument)

address = decoder.decode_address()

>> str

Decode an unsigned integer

def decode_unsigned_int(self) -> int:

Return Value

This method returns an unsigned integer as a string.

from crypto.utils.abi.argument_decoder import ArgumentDecoder

decoder = ArgumentDecoder(argument)

value = decoder.decode_unsigned_int()

>> int

Decode a signed integer

def decode_signed_int(self) -> int:

Return Value

This method returns an signed integer as a string.

from crypto.utils.abi.argument_decoder import ArgumentDecoder

decoder = ArgumentDecoder(argument)

value = decoder.decode_signed_int()

>> int

Decode a boolean

def decode_bool(self) -> bool:

Return Value

This method returns a boolean.

from crypto.utils.abi.argument_decoder import ArgumentDecoder

decoder = ArgumentDecoder(argument)

value = decoder.decode_bool()

>> bool

RlpEncoder

Crypto / API Documentation / Utils / RlpEncoder

RLP Encode data

def encode(data: Union[str, bytes, int, list]) -> str:

Parameters

TypeNameRequiredDescription
Union[str, bytes, int, list]dataYesThe data to encode.

Return Value

This method encodes data using the Recursive Length Prefix (RLP) algorithm and returns the encoded data as a hexadecimal string.

from crypto.utils.rlp_encoder import RlpEncoder

rlp_encoding = RlpEncoder.encode([
  bytes(network),
  bytes(nonce),
  b'',
  bytes(gasPrice),
  bytes(gas),
  bytes(to),
  bytes(value),
  bytes(transaction_data),
  [],
  bytes(v),
  bytes(r),
  bytes(s),
])

>> str

RlpDecoder

Crypto / API Documentation / Utils / RlpDecoder

RLP Decode data

def decode(data: str) -> Union[str, list]:

Parameters

TypeNameRequiredDescription
Union[str, list]dataYesThe data to decode.

Return Value

This method decodes encoded Recursive Length Prefix (RLP) data and returns the decoded data as a string or list.

from crypto.utils.rlp_decoder import RlpDecoder

decoded_rlp = RlpDecoder.decode('0x' + serialized_transaction[2:])

>> Union[str, list]

UnitConverter

Crypto / API Documentation / Utils / UnitConverter

Parse a value into the appropriate units

def parse_units(value: Union[float, int, str, Decimal], unit='ark') -> int:

Parameters

TypeNameRequiredDescription
Union[float, int, str, Decimal]valueYesThe value to be converted
strunitNoThe unit to convert to (default is 'ark')

Return Value

This method returns the value converted to the smallest unit as a string.

from crypto.utils.unit_converter import UnitConverter

wei_value = UnitConverter.parse_units(1, 'wei')

>> 1

gwei_value = UnitConverter.parse_units(1, 'gwei')

>> 1000000000

ark_value = UnitConverter.parse_units(1, 'ark')

>> 1000000000000000000

ark_decimal_value = UnitConverter.parse_units(0.1, 'ark')

>> 100000000000000000

Format a value from smaller units to a larger unit

def format_units(value: Union[float, int, str, Decimal], unit='ark') -> Decimal:

Parameters

TypeNameRequiredDescription
strvalueYesThe value in the smallest unit (as a string)
strunitNoThe unit to format to (default is 'ark')

Return Value

This method returns the value converted from the smallest unit to the specified unit as a float.

from crypto.utils.unit_converter import UnitConverter

formatted_wei = UnitConverter.format_units('1', 'wei')

>> 1.0

formatted_gwei = UnitConverter.format_units('1000000000', 'gwei')

>> 1.0

formatted_ark = UnitConverter.format_units('1000000000000000000', 'ark')

>> 1.0

formatted_ark_decimal = UnitConverter.format_units('100000000000000000', 'ark')

>> 0.1

Format a wei value to an ark value

def wei_to_ark(value: Union[float, int, str, Decimal], suffix=None):

Parameters

TypeNameRequiredDescription
Union[float, int, str, Decimal]valueYesThe wei value (as a string, int or float)
strsuffixNoThe suffix to show after the formatted value (default is null)

Return Value

This method returns the wei value formatted as an ARK value.

from crypto.utils.unit_converter import UnitConverter

formatted_value = UnitConverter.wei_to_ark(1, 'DARK')

>> 0.000000000000000001 DARK

formatted_value = UnitConverter.wei_to_ark(1)

>> 0.000000000000000001

formatted_value = UnitConverter.wei_to_ark('1000000000000000000', 'DARK')

>> 1 DARK

formatted_value = UnitConverter.wei_to_ark('1000000000000000000')

>> 1

Format a gwei value to an ark value

def gwei_to_ark(value: Union[float, int, str, Decimal], suffix=None):

Parameters

TypeNameRequiredDescription
Union[float, int, str, Decimal]valueYesThe gwei value (as a string, int or float)
strsuffixNoThe suffix to show after the formatted value (default is null)

Return Value

This method returns the gwei value formatted as an ARK value.

from crypto.utils.unit_converter import UnitConverter

formatted_value = UnitConverter.gwei_to_ark(1, 'DARK')

>> 0.000000001 DARK

formatted_value = UnitConverter.gwei_to_ark(1)

>> 0.000000001

formatted_value = UnitConverter.gwei_to_ark('1000000000', 'DARK')

>> 1 DARK

formatted_value = UnitConverter.gwei_to_ark('1000000000')

>> 1