API
Account
- class supra_sdk.account.Account(account_address, private_key)
Bases:
objectRepresents an account as well as the private, public key-pair for the Supra blockchain.
- account_address: AccountAddress
- address()
Returns the address associated with the given account
- Return type:
- auth_key()
Returns the auth_key for the associated account
- Return type:
str
- private_key: PrivateKey
- sign_simulated_transaction(transaction)
- Return type:
- sign_transaction(transaction)
- Return type:
- store(path)
Writes the address and the private key to path as JSON.
The private key is stored unencrypted. The file is created readable and writable only by its owner (mode 0600). An existing file at path is replaced, not modified in place, so the result is 0600 whatever the old file’s mode or owner was. The replacement is atomic: the data is written to a temporary file in the same directory and renamed over path, so a crash or a full disk does not leave a partial or empty file, and a failed write leaves any existing file intact. On Windows the mode is not applied and the file inherits the directory’s access control. Read the file back with Account.load.
- class supra_sdk.account.RotationProofChallenge(sequence_number, originator, current_auth_key, new_public_key)
Bases:
object- current_auth_key: AccountAddress
- originator: AccountAddress
- sequence_number: int
- serialize(serializer)
- type_info_account_address: AccountAddress = 0x1
- type_info_module_name: str = 'account'
- type_info_struct_name: str = 'RotationProofChallenge'
Account Address
- class supra_sdk.account_address.AccountAddress(address)
Bases:
object- LENGTH: int = 32
- address: bytes
- static deserialize(deserializer)
- Return type:
- static for_guid_object(creator, creation_num)
- Return type:
- static for_named_collection(creator, collection_name)
- Return type:
- static for_named_object(creator, seed)
- Return type:
- static for_named_token(creator, collection_name, token_name)
- Return type:
- static for_resource_account(creator, seed)
- Return type:
- static from_key(key)
- Return type:
- static from_str(address)
NOTE: This function has strict parsing behavior. For relaxed behavior, please use from_string_relaxed function.
Creates an instance of AccountAddress from a hex string.
This function allows only the strictest formats defined by AIP-40. In short this means only the following formats are accepted: - LONG - SHORT for special addresses
Where: - LONG is defined as 0x + 64 hex characters. - SHORT for special addresses is 0x0 to 0xf inclusive without padding zeroes.
This means the following are not accepted: - SHORT for non-special addresses. - Any address without a leading 0x.
Learn more about the different address formats by reading AIP-40: https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.
- Parameters:
(str) (- address)
- Return type:
- Returns:
AccountAddress: An instance of AccountAddress.
- static from_str_relaxed(address)
NOTE: This function has relaxed parsing behavior. For strict behavior, please use the from_string function. Where possible, use from_string rather than this function. from_string_relaxed is only provided for backwards compatibility.
Creates an instance of AccountAddress from a hex string.
This function allows all formats defined by AIP-40. In short, this means the following formats are accepted: - LONG, with or without leading 0x - SHORT, with or without leading 0x
Where: - LONG is 64 hex characters. - SHORT is 1 to 63 hex characters inclusive. - Padding zeroes are allowed, e.g., 0x0123 is valid.
Learn more about the different address formats by reading AIP-40: https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md.
- Parameters:
(str) (- address)
- Return type:
- Returns:
AccountAddress: An instance of AccountAddress.
- is_special()
Returns whether the address is a “special” address. Addresses are considered special if the first 63 characters of the hex string are zero. In other words, an address is special if the first 31 bytes are zero and the last byte is smaller than 0b10000 (16). In other words, special is defined as an address that matches the following regex: ^0x0{63}[0-9a-f]$. In short form this means the addresses in the range from 0x0 to 0xf (inclusive) are special.
For more details see the v1 address standard defined as part of AIP-40: https://github.com/aptos-foundation/AIPs/blob/main/aips/aip-40.md
- serialize(serializer)
- class supra_sdk.account_address.AuthKeyScheme
Bases:
object- DeriveObjectAddressFromGuid: bytes = b'\xfd'
- DeriveObjectAddressFromSeed: bytes = b'\xfe'
- DeriveResourceAccountAddress: bytes = b'\xff'
- Ed25519: bytes = b'\x00'
- MultiEd25519: bytes = b'\x01'
- MultiKey: bytes = b'\x03'
- SingleKey: bytes = b'\x02'
- exception supra_sdk.account_address.ParseAddressError
Bases:
ExceptionThere was an error parsing an address.
Asymmetric Crypto
- class supra_sdk.asymmetric_crypto.PrivateKey(*args, **kwargs)
Bases:
Deserializable,Serializable,Protocol- hex()
- Return type:
str
- class supra_sdk.asymmetric_crypto.PublicKey(*args, **kwargs)
Bases:
Deserializable,Serializable,Protocol- to_crypto_bytes()
A long time ago, someone decided that we should have both bcs and a special representation for MultiEd25519, so we use this to let keys self-define a special encoding.
- Return type:
bytes
- verify(data, signature)
- Return type:
bool
- class supra_sdk.asymmetric_crypto.Signature(*args, **kwargs)
Bases:
Deserializable,Serializable,Protocol
Asymmetric Crypto Wrapper
- class supra_sdk.asymmetric_crypto_wrapper.MultiPublicKey(keys, threshold)
Bases:
PublicKey- MAX_KEYS = 32
- MIN_KEYS = 1
- MIN_THRESHOLD = 1
- static deserialize(deserializer)
- Return type:
- static from_crypto_bytes(indata)
- Return type:
- serialize(serializer)
- threshold: int
- to_crypto_bytes()
A long time ago, someone decided that we should have both bcs and a special representation for MultiEd25519, so we use this to let keys self-define a special encoding.
- Return type:
bytes
- verify(data, signature)
Returns True only if the signature set meets the threshold and every signature verifies against the key at its index.
- Return type:
bool
- class supra_sdk.asymmetric_crypto_wrapper.MultiSignature(signatures, bitmap_num_of_bytes=4)
Bases:
Signature- BITMAP_NUM_OF_BYTES: int = 4
- MAX_BITMAP_NUM_OF_BYTES: int = 8192
- bitmap_num_of_bytes: int
- static deserialize(deserializer)
Reads the signatures and the bitmap, which is a byte vector whose bits are numbered from the most significant bit of its first byte.
The bitmap length is kept so that re-serialising reproduces the bytes. Raises ValueError if the bitmap does not match the number of signatures.
- Return type:
- serialize(serializer)
- unset_signatures()
- class supra_sdk.asymmetric_crypto_wrapper.PublicKey(public_key)
Bases:
PublicKey- ED25519: int = 0
- serialize(serializer)
- to_crypto_bytes()
A long time ago, someone decided that we should have both bcs and a special representation for MultiEd25519, so we use this to let keys self-define a special encoding.
- Return type:
bytes
- variant: int
- verify(data, signature)
- Return type:
bool
Authenticator
- class supra_sdk.authenticator.AccountAuthenticator(authenticator)
Bases:
object- ED25519: int = 0
- MULTI_ED25519: int = 1
- MULTI_KEY: int = 3
- SINGLE_KEY: int = 2
- authenticator: Any
- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- unset_signature()
- variant: int
- verify(data)
- Return type:
bool
- class supra_sdk.authenticator.Authenticator(authenticator)
Bases:
objectEach transaction submitted to the Supra blockchain contains a TransactionAuthenticator. During transaction execution, the executor will check if every AccountAuthenticator’s signature on the transaction hash is well-formed and whether AccountAuthenticator’s matches the AuthenticationKey stored under the participating signer’s account address.
- ED25519: int = 0
- FEE_PAYER: int = 3
- MULTI_AGENT: int = 2
- MULTI_ED25519: int = 1
- SINGLE_SENDER: int = 4
- authenticator: Any
- static deserialize(deserializer)
- Return type:
- static from_key(key)
- Return type:
int
- serialize(serializer)
- unset_signature()
- variant: int
- verify(data)
- Return type:
bool
- class supra_sdk.authenticator.Ed25519Authenticator(public_key, signature)
Bases:
object- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- unset_signature()
- verify(data)
- Return type:
bool
- class supra_sdk.authenticator.FeePayerAuthenticator(sender, secondary_signers, fee_payer)
Bases:
object- static deserialize(deserializer)
- Return type:
- fee_payer: tuple[AccountAddress, AccountAuthenticator]
- fee_payer_address()
- Return type:
- secondary_addresses()
- Return type:
list[AccountAddress]
- secondary_signers: list[tuple[AccountAddress, AccountAuthenticator]]
- sender: AccountAuthenticator
- serialize(serializer)
- unset_signature()
- verify(data)
- Return type:
bool
- class supra_sdk.authenticator.MultiAgentAuthenticator(sender, secondary_signers)
Bases:
object- static deserialize(deserializer)
- Return type:
- secondary_addresses()
- Return type:
list[AccountAddress]
- secondary_signers: list[tuple[AccountAddress, AccountAuthenticator]]
- sender: AccountAuthenticator
- serialize(serializer)
- unset_signature()
- verify(data)
- Return type:
bool
- class supra_sdk.authenticator.MultiEd25519Authenticator(public_key, signature)
Bases:
object- static deserialize(deserializer)
- Return type:
- public_key: MultiPublicKey
- serialize(serializer)
- signature: MultiSignature
- unset_signature()
- verify(data)
- Return type:
bool
- class supra_sdk.authenticator.MultiKeyAuthenticator(public_key, signature)
Bases:
object- static deserialize(deserializer)
- Return type:
- public_key: MultiPublicKey
- serialize(serializer)
- signature: MultiSignature
- unset_signature()
- verify(data)
- Return type:
bool
- class supra_sdk.authenticator.SingleKeyAuthenticator(public_key, signature)
Bases:
object- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- unset_signature()
- verify(data)
- Return type:
bool
BCS
This is a simple BCS serializer and deserializer. Learn more at https://github.com/diem/bcs
- class supra_sdk.bcs.Deserializable(*args, **kwargs)
Bases:
Protocol- static deserialize(deserializer)
- Return type:
- classmethod from_bytes(indata)
- Return type:
- class supra_sdk.bcs.Deserializer(data)
Bases:
object- fixed_bytes(length)
- Return type:
bytes
- map(key_decoder, value_decoder)
- Return type:
dict[Any,Any]
- remaining()
- Return type:
int
- sequence(value_decoder)
- Return type:
list[Any]
- struct(struct)
- Return type:
Any
- to_bytes()
- Return type:
bytes
- u128()
- Return type:
int
- u16()
- Return type:
int
- u256()
- Return type:
int
- u32()
- Return type:
int
- u64()
- Return type:
int
- u8()
- Return type:
int
- uleb128()
- Return type:
int
- class supra_sdk.bcs.Serializable(*args, **kwargs)
Bases:
Protocol- serialize(serializer)
- to_bytes()
- Return type:
bytes
- class supra_sdk.bcs.Serializer
Bases:
object- bool(value)
- fixed_bytes(value)
- map(values, key_encoder, value_encoder)
- output()
- Return type:
bytes
- sequence(values, value_encoder)
- static sequence_serializer(value_encoder)
- str(value)
- struct(value)
- to_bytes(value)
- u128(value)
- u16(value)
- u256(value)
- u32(value)
- u64(value)
- u8(value)
- uleb128(value)
- supra_sdk.bcs.encoder(value, encoder)
- Return type:
bytes
ED25519
- class supra_sdk.ed25519.MultiPublicKey(keys, threshold)
Bases:
PublicKey- MAX_KEYS = 32
- MIN_KEYS = 1
- MIN_THRESHOLD = 1
- static deserialize(deserializer)
- Return type:
- static from_crypto_bytes(indata)
- Return type:
- serialize(serializer)
- threshold: int
- to_crypto_bytes()
A long time ago, someone decided that we should have both bcs and a special representation for MultiEd25519, so we use this to let keys self-define a special encoding.
- Return type:
bytes
- verify(data, signature)
Returns True only if the signature set meets the threshold and every signature verifies against the key at its index.
- Return type:
bool
- class supra_sdk.ed25519.MultiSignature(signatures)
Bases:
Signature- BITMAP_NUM_OF_BYTES: int = 4
- static deserialize(deserializer)
Raises ValueError if the length or the bitmap is inconsistent.
- Return type:
- static from_key_map(public_key, signatures_map)
Builds a signature from (public key, signature) pairs given in any order.
Raises ValueError if a public key is not one of the multi-key’s keys.
- Return type:
- serialize(serializer)
- unset_signatures()
- class supra_sdk.ed25519.PrivateKey(key)
Bases:
PrivateKey- LENGTH: int = 32
- static deserialize(deserializer)
- Return type:
- static from_str(value)
- Return type:
- hex()
Returns the private key as 0x-prefixed hex. This is the explicit export of the secret.
- Return type:
str
- key: SigningKey
- static random()
- Return type:
- serialize(serializer)
- class supra_sdk.ed25519.PublicKey(key)
Bases:
PublicKey- LENGTH: int = 32
- key: VerifyKey
- serialize(serializer)
- to_crypto_bytes()
A long time ago, someone decided that we should have both bcs and a special representation for MultiEd25519, so we use this to let keys self-define a special encoding.
- Return type:
bytes
- verify(data, signature)
- Return type:
bool
Metadata
- class supra_sdk.metadata.Metadata
Bases:
objectRepresents the metadata related to the SDK sent to the rpc_node in header during API call.
The main objective of this is to provide additional information to the rpc_node to track the source of the incoming requests.
- SUPRA_HEADER = 'x-supra-client'
- static get_supra_header_val()
Transactions
This translates Supra transactions to and from BCS for signing and submitting to the REST API.
- class supra_sdk.transactions.AutomationRegistrationParams(registration_params)
Bases:
object- V1: int = 0
- V2: int = 1
- static build(automated_function, max_gas_amount, gas_price_cap, automation_fee_cap_for_epoch, expiration_timestamp_secs, aux_data, task_type=None, priority=None)
Builds registration parameters, choosing the version from the arguments.
With neither
task_typenorprioritythe result is version 1. With either, it is version 2; a missingtask_typeis thenAutomationTaskType.USER.Without a priority, the registry uses the task’s index as its priority.
- Return type:
- static deserialize(deserializer)
- Return type:
- registration_params: Any
- serialize(serializer)
- Return type:
None
- variant: int
- class supra_sdk.transactions.AutomationRegistrationParamsV1(automated_function, max_gas_amount, gas_price_cap, automation_fee_cap_for_epoch, expiration_timestamp_secs, aux_data)
Bases:
object- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.AutomationRegistrationParamsV2(automated_function, max_gas_amount, gas_price_cap, automation_fee_cap_for_epoch, expiration_timestamp_secs, aux_data, task_type=AutomationTaskType.USER, priority=None)
Bases:
objectVersion 2 of the automation registration parameters.
The version 1 fields, followed by the task type and an optional priority. Without a priority (
None), the registry uses the task’s index as its priority.- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.AutomationTaskType(*values)
Bases:
EnumThe type of an automation task.
The value of a member is its index in the node’s task type enum, which is what is written to BCS. It is not the numeric value the node uses elsewhere for the type.
SYSTEMtasks can only be registered by accounts that the registry has authorised for system tasks; registration from any other account aborts. System tasks are not charged, so their gas price cap and fee cap are not used.- SYSTEM = 1
- USER = 0
- class supra_sdk.transactions.EntryFunction(module, function, ty_args, args)
Bases:
object- args: list[bytes]
- static deserialize(deserializer)
- Return type:
- function: str
- static natural(module, function, ty_args, args)
- Return type:
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.FeePayerRawTransaction(raw_transaction, secondary_signers, fee_payer)
Bases:
RawTransactionWithData- fee_payer: AccountAddress | None
- secondary_signers: list[AccountAddress]
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.ModuleBundle
Bases:
object- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.ModuleId(address, name)
Bases:
object- address: AccountAddress
- name: str
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.MultiAgentRawTransaction(raw_transaction, secondary_signers)
Bases:
RawTransactionWithData- secondary_signers: list[AccountAddress]
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.Multisig(multisig_address, transaction_payload=None)
Bases:
object- multisig_address: AccountAddress
- serialize(serializer)
- Return type:
None
- transaction_payload: MultisigTransactionPayload | None
- class supra_sdk.transactions.MultisigTransactionPayload(transaction_payload)
Bases:
object- ENTRY_FUNCTION: int = 0
- static deserialize(deserializer)
- Return type:
- payload_variant: int
- serialize(serializer)
- Return type:
None
- transaction_payload: EntryFunction
Currently MultisigTransactionPayload only supports EntryFunction type payload
- class supra_sdk.transactions.RawTransaction(sender, sequence_number, payload, max_gas_amount, gas_unit_price, expiration_timestamps_secs, chain_id)
Bases:
Deserializable,RawTransactionInternal,Serializable- chain_id: int
- static deserialize(deserializer)
- Return type:
- expiration_timestamps_secs: int
- gas_unit_price: int
- max_gas_amount: int
- payload: TransactionPayload
- prehash()
- Return type:
bytes
- sender: AccountAddress
- sequence_number: int
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.RawTransactionInternal(*args, **kwargs)
Bases:
Protocol- keyed()
- Return type:
bytes
- prehash()
- Return type:
bytes
- serialize(serializer)
- Return type:
None
- sign(key)
- Return type:
- sign_simulated(key)
- Return type:
- verify(key, signature)
- Return type:
bool
- class supra_sdk.transactions.RawTransactionWithData(*args, **kwargs)
Bases:
RawTransactionInternal,Protocol- inner()
- Return type:
- prehash()
- Return type:
bytes
- raw_transaction: RawTransaction
- class supra_sdk.transactions.Script(code, ty_args, args)
Bases:
object- args: list[ScriptArgument]
- code: bytes
- serialize(serializer)
- Return type:
None
- class supra_sdk.transactions.ScriptArgument(variant, value)
Bases:
object- ADDRESS: int = 3
- BOOL: int = 5
- U128: int = 2
- U16: int = 6
- U256: int = 8
- U32: int = 7
- U64: int = 1
- U8: int = 0
- U8_VECTOR: int = 4
- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- Return type:
None
- value: Any
- variant: int
- class supra_sdk.transactions.SignedTransaction(transaction, authenticator)
Bases:
object- authenticator: Authenticator
- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- Return type:
None
- transaction: RawTransaction
- verify()
- Return type:
bool
- class supra_sdk.transactions.SupraTransaction(transaction)
Bases:
object- MOVE: int = 1
- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- Return type:
None
- to_bytes()
Provides BCS serialized bytes
- Return type:
bytes
- value: Any
- variant: int
- class supra_sdk.transactions.TransactionArgument(value, encoder)
Bases:
object- encode()
- Return type:
bytes
- encoder: Callable[[Serializer, Any], None]
- value: Any
- class supra_sdk.transactions.TransactionPayload(payload)
Bases:
object- AUTOMATION_REGISTRATION: int = 4
- ENTRY_FUNCTION: int = 2
- MODULE_BUNDLE: int = 1
- MULTISIG: int = 3
- SCRIPT: int = 0
- static deserialize(deserializer)
- Return type:
- serialize(serializer)
- Return type:
None
- value: Any
- variant: int
Type Tag
- class supra_sdk.type_tag.AccountAddressTag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'address'
- VARIANT: ClassVar[int] = 4
- class supra_sdk.type_tag.BoolTag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'bool'
- VARIANT: ClassVar[int] = 0
- class supra_sdk.type_tag.SignerTag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'signer'
- VARIANT: ClassVar[int] = 5
- class supra_sdk.type_tag.StructTag(address, module, name, type_args)
Bases:
Deserializable,Serializable- address: AccountAddress
- static from_str(type_tag)
Parse a struct such as
0x1::option::Option<vector<u8>>.Type arguments may be any type, nested up to the Move type-tag nesting limit. Raises
ValueErrorif the string is malformed, nests deeper than that limit, or is not a struct.- Return type:
- module: str
- name: str
- serialize(serializer)
- variant()
- class supra_sdk.type_tag.TypeTag(value)
Bases:
Deserializable,SerializableA Move type, as used for the type arguments of a transaction payload.
The BCS encoding is the variant index followed by the variant’s payload. Primitive types and
signerhave no payload, sou64encodes as the single byte02.vectorcarries its element type and a struct carries aStructTag.TypeTag.from_strparses the textual form, for exampleu64,vector<vector<u8>>or0x1::option::Option<vector<u8>>.- ACCOUNT_ADDRESS: int = 4
- BOOL: int = 0
- SIGNER: int = 5
- STRUCT: int = 7
- U128: int = 3
- U16: int = 8
- U256: int = 10
- U32: int = 9
- U64: int = 2
- U8: int = 1
- VECTOR: int = 6
- static deserialize(deserializer)
Raises
ValueErrorfor an unknown variant or for nesting deeper than the Move type-tag nesting limit (MAX_TYPE_TAG_NESTING).- Return type:
- static from_str(type_tag)
Parse a type such as
u64,vector<u8>or0x1::option::Option<vector<u8>>.Raises
ValueErrorif the string is not a well-formed type or nests deeper than the Move type-tag nesting limit (MAX_TYPE_TAG_NESTING).- Return type:
- serialize(serializer)
- value: Any
- class supra_sdk.type_tag.U128Tag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'u128'
- VARIANT: ClassVar[int] = 3
- class supra_sdk.type_tag.U16Tag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'u16'
- VARIANT: ClassVar[int] = 8
- class supra_sdk.type_tag.U256Tag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'u256'
- VARIANT: ClassVar[int] = 10
- class supra_sdk.type_tag.U32Tag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'u32'
- VARIANT: ClassVar[int] = 9
- class supra_sdk.type_tag.U64Tag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'u64'
- VARIANT: ClassVar[int] = 2
- class supra_sdk.type_tag.U8Tag(value=None)
Bases:
_PrimitiveTag- NAME: ClassVar[str] = 'u8'
- VARIANT: ClassVar[int] = 1
- class supra_sdk.type_tag.VectorTag(value)
Bases:
Deserializable,Serializablevector<T>.valueis the elementTypeTag.The argument is a
TypeTagor a bare tag (U8Tag(),StructTag(...), anotherVectorTag), which is wrapped in aTypeTag. Anything else, including a string, raisesTypeError; parse text explicitly withTypeTag.from_str.- serialize(serializer)
- variant()