aea.crypto.fetchai

Fetchai module wrapping the public and private key cryptography and ledger api.

FetchAICrypto Objects

class FetchAICrypto(Crypto[Entity])

Class wrapping the Entity Generation from Fetch.AI ledger.

__init__

 | __init__(private_key_path: Optional[str] = None)

Instantiate a fetchai crypto object.

Arguments:

  • private_key_path: the private key path of the agent

private_key

 | @property
 | private_key() -> str

Return a private key.

Returns:

a private key string

public_key

 | @property
 | public_key() -> str

Return a public key in hex format.

Returns:

a public key string in hex format

address

 | @property
 | address() -> str

Return the address for the key pair.

Returns:

a display_address str

load_private_key_from_path

 | @classmethod
 | load_private_key_from_path(cls, file_name: str) -> Entity

Load a private key in hex format from a file.

Arguments:

  • file_name: the path to the hex file.

Returns:

the Entity.

generate_private_key

 | @classmethod
 | generate_private_key(cls) -> Entity

Generate a key pair for fetchai network.

sign_message

 | sign_message(message: bytes, is_deprecated_mode: bool = False) -> str

Sign a message in bytes string form.

Arguments:

  • message: the message we want to send
  • is_deprecated_mode: if the deprecated signing is used

Returns:

signature of the message in string form

sign_transaction

 | sign_transaction(transaction: Any) -> Any

Sign a transaction in bytes string form.

Arguments:

  • transaction: the transaction to be signed

Returns:

signed transaction

dump

 | dump(fp: BinaryIO) -> None

Serialize crypto object as binary stream to fp (a .write()-supporting file-like object).

Arguments:

  • fp: the output file pointer. Must be set in binary mode (mode='wb')

Returns:

None

FetchAIHelper Objects

class FetchAIHelper(Helper)

Helper class usable as Mixin for FetchAIApi or as standalone class.

is_transaction_settled

 | @staticmethod
 | is_transaction_settled(tx_receipt: Any) -> bool

Check whether a transaction is settled or not.

Arguments:

  • tx_digest: the digest associated to the transaction.

Returns:

True if the transaction has been settled, False o/w.

is_transaction_valid

 | @staticmethod
 | is_transaction_valid(tx: Any, seller: Address, client: Address, tx_nonce: str, amount: int) -> bool

Check whether a transaction is valid or not.

Arguments:

  • tx: the transaction.
  • seller: the address of the seller.
  • client: the address of the client.
  • tx_nonce: the transaction nonce.
  • amount: the amount we expect to get from the transaction.

Returns:

True if the random_message is equals to tx['input']

generate_tx_nonce

 | @staticmethod
 | generate_tx_nonce(seller: Address, client: Address) -> str

Generate a unique hash to distinguish txs with the same terms.

Arguments:

  • seller: the address of the seller.
  • client: the address of the client.

Returns:

return the hash in hex.

get_address_from_public_key

 | @staticmethod
 | get_address_from_public_key(public_key: str) -> Address

Get the address from the public key.

Arguments:

  • public_key: the public key

Returns:

str

recover_message

 | @staticmethod
 | recover_message(message: bytes, signature: str, is_deprecated_mode: bool = False) -> Tuple[Address, ...]

Recover the addresses from the hash.

Arguments:

  • message: the message we expect
  • signature: the transaction signature
  • is_deprecated_mode: if the deprecated signing was used

Returns:

the recovered addresses

get_hash

 | @staticmethod
 | get_hash(message: bytes) -> str

Get the hash of a message.

Arguments:

  • message: the message to be hashed.

Returns:

the hash of the message.

FetchAIApi Objects

class FetchAIApi(LedgerApi,  FetchAIHelper)

Class to interact with the Fetch ledger APIs.

__init__

 | __init__(**kwargs)

Initialize the Fetch.AI ledger APIs.

Arguments:

  • kwargs: key word arguments (expects either a pair of 'host' and 'port' or a 'network')

api

 | @property
 | api() -> FetchaiLedgerApi

Get the underlying API object.

get_balance

 | get_balance(address: Address) -> Optional[int]

Get the balance of a given account.

Arguments:

  • address: the address for which to retrieve the balance.

Returns:

the balance, if retrivable, otherwise None

get_transfer_transaction

 | get_transfer_transaction(sender_address: Address, destination_address: Address, amount: int, tx_fee: int, tx_nonce: str, **kwargs, ,) -> Optional[Any]

Submit a transfer transaction to the ledger.

Arguments:

  • sender_address: the sender address of the payer.
  • destination_address: the destination address of the payee.
  • amount: the amount of wealth to be transferred.
  • tx_fee: the transaction fee.
  • tx_nonce: verifies the authenticity of the tx

Returns:

the transfer transaction

send_signed_transaction

 | send_signed_transaction(tx_signed: Any) -> Optional[str]

Send a signed transaction and wait for confirmation.

Arguments:

  • tx_signed: the signed transaction

get_transaction_receipt

 | get_transaction_receipt(tx_digest: str) -> Optional[Any]

Get the transaction receipt for a transaction digest (non-blocking).

Arguments:

  • tx_digest: the digest associated to the transaction.

Returns:

the tx receipt, if present

get_transaction

 | get_transaction(tx_digest: str) -> Optional[Any]

Get the transaction for a transaction digest.

Arguments:

  • tx_digest: the digest associated to the transaction.

Returns:

the tx, if present

get_contract_instance

 | get_contract_instance(contract_interface: Dict[str, str], contract_address: Optional[str] = None) -> Any

Get the instance of a contract.

Arguments:

  • contract_interface: the contract interface.
  • contract_address: the contract address.

Returns:

the contract instance

get_deploy_transaction

 | get_deploy_transaction(contract_interface: Dict[str, str], deployer_address: Address, **kwargs, ,) -> Dict[str, Any]

Get the transaction to deploy the smart contract.

Arguments:

  • contract_interface: the contract interface.
  • deployer_address: The address that will deploy the contract. :returns tx: the transaction dictionary.

FetchAIFaucetApi Objects

class FetchAIFaucetApi(FaucetApi)

Fetchai testnet faucet API.

get_wealth

 | get_wealth(address: Address) -> None

Get wealth from the faucet for the provided address.

Arguments:

  • address: the address.

Returns:

None