Clients
Api Client
- class supra_sdk.clients.api_client.ApiClient(base_url, api_client_config=None, transport=None)
Bases:
objectA generic API client for making HTTP requests, it acts as a base class for specific API clients.
- _client
HTTP client to send the http request.
- Type:
httpx.AsyncClient
- base_url
The base URL of the API, always ending in /. A path prefix such as https://host/prefix is kept: requests go to https://host/prefix/rpc/v3/….
- Type:
str
- api_client_config
Configuration options for API client.
- Type:
- api_client_config: ApiClientConfig
- base_url: str
- async close()
Closes the HTTP client session.
- async get(endpoint, headers=None, params=None, strict_mode=True)
Performs an asynchronous GET request.
- Parameters:
endpoint (
str) – Endpoint to call.headers (
dict[str,str] |None) – Optional headers. Default to None.params (
dict[str,Any] |None) – Optional query parameters. Default to None.strict_mode (
bool|None) – If enabled then raises an error when request response status code is not 200. Default to True.
- Returns:
The response from the server.
- Return type:
Response
- async post(endpoint, params=None, headers=None, data=None, strict_mode=True)
Performs an asynchronous POST request.
- Parameters:
endpoint (
str) – API endpoint.params (
dict[str,Any] |None) – Query parameters. Default to None.headers (
dict[str,Any] |None) – Request headers. Default to None.data (
dict[str,Any] |bytes|None) – POST body data. Default to None.strict_mode (
bool|None) – If enabled then raises an error when request response status code is not 200. Default to True.
- Returns:
The response from the server.
- Return type:
Response
- class supra_sdk.clients.api_client.ApiClientConfig(http2=False, access_token=None)
Bases:
objectHolds configuration options related to the generic API client.
- http2
Whether to use HTTP/2 for requests. Default to False.
- Type:
bool
- access_token
Optional access token (JWT) for authentication. Default to None.
- Type:
Optional[str]
- access_token: str | None = None
- http2: bool = False
- raise_if_access_token_not_exists()
Raise an error if the access token is not set.
Checks whether self.access_token exists. If it does not, an AuthorizationKeyNotSpecifiedError is raised.
- Raises:
AuthorizationKeyNotSpecifiedError – If self.access_token is missing or None.
- exception supra_sdk.clients.api_client.ApiError(message, status_code)
Bases:
ExceptionException raised when the API returns a non-200 response.
- message
The response body.
- Type:
str
- status_code
The HTTP status code returned.
- Type:
int
- message: str
- status_code: int
- exception supra_sdk.clients.api_client.AuthorizationKeyNotSpecifiedError
Bases:
ExceptionException raised when consensus api endpoints are accessed without defining access_token in ClientConfig.
Supra Token
- class supra_sdk.clients.supra_token.SupraTokenClient(client)
Bases:
objectA class that provides convenient methods to interact with the aptos-token package.
- Parameters:
client (
SupraClient) – Instance of the SupraClient class used for interacting with rpc-node.
- async claim_token(account, sender, creator, collection_name, token_name, property_version)
Claims a token that was offered to the account.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- client: SupraClient
- async create_collection(account, name, description, uri)
Creates a new collection within the specified account.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async create_token(account, collection_name, name, description, supply, uri, royalty_points_per_million)
Creates a new token in a collection.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async direct_transfer_token(sender, receiver, creators_address, collection_name, token_name, property_version, amount)
Transfers a token directly from the sender to the receiver, both signing.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async get_collection(creator, collection_name)
- Return type:
Any
- async get_token(owner, creator, collection_name, token_name, property_version)
- Return type:
Any
- async get_token_balance(owner, creator, collection_name, token_name, property_version)
- Return type:
str
- async get_token_data(creator, collection_name, token_name)
- Return type:
Any
- async offer_token(account, receiver, creator, collection_name, token_name, property_version, amount)
Offers a token to a receiver.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
Supra Token Object
- class supra_sdk.clients.supra_token_object.Collection(creator, description, name, uri)
Bases:
object- creator: AccountAddress
- description: str
- name: str
- static parse(resource)
- Return type:
- struct_tag: str = '0x4::collection::Collection'
- uri: str
- exception supra_sdk.clients.supra_token_object.InvalidPropertyTypeError(property_type)
Bases:
ExceptionInvalid property type
- property_type: Any
- class supra_sdk.clients.supra_token_object.Object(allow_ungated_transfer, owner)
Bases:
object- allow_ungated_transfer: bool
- owner: AccountAddress
- struct_tag: str = '0x1::object::ObjectCore'
- class supra_sdk.clients.supra_token_object.Property(name, property_type, value)
Bases:
object- ADDRESS: int = 7
- BOOL: int = 0
- BYTE_VECTOR: int = 8
- STRING: int = 9
- U128: int = 5
- U16: int = 2
- U256: int = 6
- U32: int = 3
- U64: int = 4
- U8: int = 1
- name: str
- property_type: str
- to_transaction_arguments()
- Return type:
list[TransactionArgument]
- value: Any
- class supra_sdk.clients.supra_token_object.PropertyMap(properties)
Bases:
object- static parse(resource)
- Return type:
- struct_tag: str = '0x4::property_map::PropertyMap'
- to_tuple()
- Return type:
tuple[list[str],list[str],list[bytes]]
- class supra_sdk.clients.supra_token_object.ReadObject(resources)
Bases:
object- resource_map: dict[str, Any] = {'0x1::object::ObjectCore': <class 'supra_sdk.clients.supra_token_object.Object'>, '0x4::collection::Collection': <class 'supra_sdk.clients.supra_token_object.Collection'>, '0x4::property_map::PropertyMap': <class 'supra_sdk.clients.supra_token_object.PropertyMap'>, '0x4::royalty::Royalty': <class 'supra_sdk.clients.supra_token_object.Royalty'>, '0x4::token::Token': <class 'supra_sdk.clients.supra_token_object.Token'>}
- resources: dict[Any, Any]
- class supra_sdk.clients.supra_token_object.Royalty(numerator, denominator, payee_address)
Bases:
object- denominator: int
- numerator: int
- payee_address: AccountAddress
- struct_tag: str = '0x4::royalty::Royalty'
- class supra_sdk.clients.supra_token_object.SupraTokenObjectClient(client)
Bases:
objectA class that provides convenient methods to interact with the aptos-token-package package.
- Parameters:
client (
SupraClient) – Instance of the SupraClient class used for interacting with rpc-node.
- PAGINATION_COUNT: int = 100
- async add_token_property(creator, token, prop)
Adds a property to a token.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async burn_token(creator, token)
Burns a token.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- client: SupraClient
- async create_collection(creator, description, max_supply, name, uri, mutable_description, mutable_royalty, mutable_uri, mutable_token_description, mutable_token_name, mutable_token_properties, mutable_token_uri, tokens_burnable_by_creator, tokens_freezable_by_creator, royalty_numerator, royalty_denominator)
Creates a new collection.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- static create_collection_payload(description, max_supply, name, uri, mutable_description, mutable_royalty, mutable_uri, mutable_token_description, mutable_token_name, mutable_token_properties, mutable_token_uri, tokens_burnable_by_creator, tokens_freezable_by_creator, royalty_numerator, royalty_denominator)
- Return type:
- async freeze_token(creator, token)
Freezes the transfer of a token.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async mint_soul_bound_token(creator, collection, description, name, uri, properties, soul_bound_to)
Mints a token that is bound to the given account.
- Returns:
Transaction hash.
- Return type:
str
- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async mint_token(creator, collection, description, name, uri, properties)
Mints a token in a collection.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- static mint_token_payload(collection, description, name, uri, properties)
- Return type:
- async read_object(address)
- Return type:
- async remove_token_property(creator, token, name)
Removes a property from a token.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async tokens_minted_from_transaction(txn_hash)
- Return type:
list[AccountAddress]
- async transfer_token(owner, token, to)
Transfers a token to another account.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async unfreeze_token(creator, token)
Unfreezes the transfer of a token.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.
- async update_token_property(creator, token, prop)
Updates a property of a token.
- Returns:
Transaction hash.
- Return type:
str- Raises:
TransactionFailedError – If waiting is enabled and the final status is not Success.
TransactionWaitTimeoutReachedError – If waiting is enabled and the transaction is not final in time.