Account Module

Address Class

class graphenebase.account.Address(address, prefix=None)

Address class

This class serves as an address representation for Public Keys.

  • address (str) – Base58 encoded address (defaults to None)
  • pubkey (str) – Base58 encoded pubkey (defaults to None)
  • prefix (str) – Network prefix (defaults to GPH)



Returns the raw content of the Base58CheckEncoded address


May be issued to get valid “MUSE”, “PLAY” or any other Graphene compatible address with corresponding prefix.


Gives the hex representation of the GrapheneBase58CheckEncoded Graphene address.


Returns the readable Graphene address. This call is equivalent to format(Address, "GPH")

PublicKey Class

class graphenebase.account.PublicKey(pk, prefix=None)

This class deals with Public Keys and inherits Address.

  • pk (str) – Base58 encoded public key
  • prefix (str) – Network prefix (defaults to GPH)




By default, graphene-based networks deal with compressed public keys. If an uncompressed key is required, the method unCompressed can be used:


Returns the raw public key (has length 33)


Formats the instance of:doc:Base58 <base58> according to _format


Gives the hex representation of the Graphene public key.


Returns the readable Graphene public key. This call is equivalent to format(PublicKey, "GPH")

PrivateKey Class

class graphenebase.account.PrivateKey(wif=None, prefix=None)

Derives the compressed and uncompressed public keys and constructs two instances of PublicKey:

  • wif (str) – Base58check-encoded wif key
  • prefix (str) – Network prefix (defaults to GPH)



Compressed vs. Uncompressed:

  • PrivateKey("w-i-f").pubkey:
    Instance of PublicKey using compressed key.
  • PrivateKey("w-i-f").pubkey.address:
    Instance of Address using compressed key.
  • PrivateKey("w-i-f").uncompressed:
    Instance of PublicKey using uncompressed key.
  • PrivateKey("w-i-f").uncompressed.address:
    Instance of Address using uncompressed key.

Derive new private key from this key and a sha256 “offset”


Derive private key using “generate_from_seed” method. Here, the key itself serves as a seed, and offset is expected to be a sha256 digest.


Derive new private key from this private key and an arbitrary sequence number


Get sha256 digest of the wif key.


class graphenebase.account.BrainKey(brainkey=None, sequence=0, prefix=None)

Brainkey implementation similar to the graphene-ui web-wallet.

  • brainkey (str) – Brain Key
  • sequence (int) – Sequence number for consecutive keys

Keys in Graphene are derived from a seed brain key which is a string of 16 words out of a predefined dictionary with 49744 words. It is a simple single-chain key derivation scheme that is not compatible with BIP44 but easy to use.

Given the brain key, a private key is derived as:

privkey = SHA256(SHA512(brainkey + " " + sequence))

Incrementing the sequence number yields a new key that can be regenerated given the brain key.


Derive private key from the brain key (and no sequence number)


Return brain key of this instance


Derive private key from the brain key and the current sequence number


Increment the sequence number by 1


Correct formating with single whitespace syntax and no trailing space

static suggest()

Suggest a new random brain key. Randomness is provided by the operating system using os.urandom().


Format vs. Repr

print("Private Key             : " + format(private_key,"WIF"))
print("Secret Exponent (hex)   : " + repr(private_key))
print("BTS PubKey (hex)        : " + repr(private_key.pubkey))
print("BTS PubKey              : " + format(private_key.pubkey, "BTS"))
print("BTS Address             : " + format(private_key.address,"BTS"))


Private Key             : 5Jdv8JHh4r2tUPtmLq8hp8DkW5vCp9y4UGgj6udjJQjG747FCMc
Secret Exponent (hex)   : 6c2662a6ac41bd9132a9f846847761ab4f80c82d519cdf92f40dfcd5e97ec5b5
BTS PubKey (hex)        : 021760b78d93878af16f8c11d22f0784c54782a12a88bbd36be847ab0c8b2994de
BTS PubKey              : BTS54nWRnewkASXXTwpn3q4q8noadzXmw4y1KpED3grup7VrDDRmx
BTS Address             : BTSCmUwH8G1t3VSZRH5kwxx31tiYDNrzWvyW

Compressed vs. Uncompressed

print("BTC uncomp. Pubkey (hex): " + repr(private_key.uncompressed.pubkey))
print("BTC Address (uncompr)   : " + format(private_key.uncompressed.address,"BTC"))
print("BTC comp. Pubkey (hex)  : " + repr(private_key.pubkey))
print("BTC Address (compr)     : " + format(private_key.address,"BTC"))


BTC uncomp. Pubkey (hex): 041760b78d93878af16f8c11d22f0784c54782a12a88bbd36be847ab0c8b2994de4d5abd46cabab34222023cd9034e1e6c0377fac5579a9c01e46b9498529aaf46
BTC Address (uncompr)   : 1JidAV2npbyLn77jGYQtkpJDjx6Yt5eJSh
BTC comp. Pubkey (hex)  : 021760b78d93878af16f8c11d22f0784c54782a12a88bbd36be847ab0c8b2994de
BTC Address (compr)     : 1GZ1JCW3kdL4LoCWbzHK4oV6V8JcUGG8HF