Account class
+-
+
- +class convex_api.Account(key_pair: KeyPair, address: Account | int | str, name: str | None = None) +
Bases:
+object
Create a new account with a private key KeyPair.
+-
+
- Parameters: +
- + +
++>>> # import convex-api +>>> from convex_api import API, KeyPair, Account + +>>> # setup the network connection +>>> convex = API('https://convex.world') + +>>> # create a random keypair +>>> key_pair = KeyPair() + +>>> # create a new account and address +>>> account = convex.create_account(key_pair) + +>>> # export the private key to a file +>>> key_pair.export_to_file('/tmp/my_account.pem', 'my secret password') + +>>> # save the address for later +>>> my_address = account.address + +>>> # ---- + +>>> # now import the account and address for later use +>>> key_pair = KeyPair.import_from_file('/tmp/my_account.pem', 'my secret password') +>>> account = Account(key_pair, my_address) +
-
+
- +property address: int +
-
+
- Returns: +
the network account address
+
+- Return type: +
- + +
++>>> # create an account with the network +>>> key_pair = KeyPair() +>>> account = convex.create_account(key_pair) +>>> print(account.address) +42 +
-
+
- +static is_address(text: int | str) bool +
Returns True if the text value is a valid address.
+ +
-
+
- +property public_key: bytes +
Return the public key of the account in the format ‘0x….’
+-
+
- Returns: +
public_key with leading ‘0x’
+
+- Return type: +
- + +
++>>> # create an account with the network +>>> account = convex.create_account(key_pair) + +>>> # show the public key as a hex string +>>> print(account.public_key) +0x36d8c5c40dbe2d1b0131acf41c38b9d37ebe04d85... +
-
+
- +sign(hash_text: str) str +
Sign a hash text using the internal key_pair.
+-
+
- Parameters: +
hash_text (str) – Hex string of the hash to sign
+
+- Returns: +
Hex string of the signed text
+
+
++>>> # create an account +>>> account = convex.create_account(key_pair) +>>> # sign a given hash +>>> sig = account.sign('7e2f1062f5fc51ed65a28b5945b49425aa42df6b7e67107efec357794096e05e') +>>> print(sig) +'5d41b964c63d1087ad66e58f4f9d3fe2b7bd0560b..' +