GraphQlClient
GraphQlClient Objects
class GraphQlClient(GraphQlClientProtocol)
The GraphQL client for interacting with the IOTA blockchain.
new_devnet
@classmethod
def new_devnet(cls) -> GraphQlClient
Create a new GraphQL client connected to the devnet GraphQL server:
<https://graphql.devnet.iota.cafe>.
new_localnet
@classmethod
def new_localnet(cls) -> GraphQlClient
Create a new GraphQL client connected to the localhost GraphQL server:
<http://localhost:9125/graphql>.
new_mainnet
@classmethod
def new_mainnet(cls) -> GraphQlClient
Create a new GraphQL client connected to the mainnet GraphQL server:
<https://graphql.mainnet.iota.cafe>.
new_testnet
@classmethod
def new_testnet(cls) -> GraphQlClient
Create a new GraphQL client connected to the testnet GraphQL server:
<https://graphql.testnet.iota.cafe>.
new_with_http_options
@classmethod
def new_with_http_options(cls, server: str,
options: HttpClientOptions) -> GraphQlClient
Create a new GraphQL client with the provided server address, using an HTTP client built to the given options.
active_validators
async def active_validators(
epoch: typing.Union[object, typing.Optional[int]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlValidatorPage
Get the list of active validators for the provided epoch, including related metadata. If no epoch is provided, it will return the active validators for the current epoch.
address_transactions
async def address_transactions(
address: Address,
relation: typing.Union[
object,
typing.Optional[GraphQlAddressTransactionRelationship]] = _DEFAULT,
filter: typing.Union[
object, typing.Optional[GraphQlTransactionsFilter]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlSignedTransactionPage
Get a page of transactions related to the given address.
relation selects how the address relates to them, defaulting to the transactions it sent.
balance
async def balance(
address: Address,
coin_type: typing.Union[object, typing.Optional[StructTag]] = _DEFAULT
) -> typing.Optional[int]
Get the balance of all the coins owned by address for the provided coin type. Coin type will
default to 0x2::iota::IOTA if not provided.
chain_id
async def chain_id() -> str
Get the chain identifier.
checkpoint
async def checkpoint(
digest: typing.Union[object, typing.Optional[CheckpointDigest]] = _DEFAULT,
sequence_number: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> typing.Optional[CheckpointSummary]
Get the CheckpointSummary for a given checkpoint digest or checkpoint id. If none is
provided, it will use the last known checkpoint id.
checkpoints
async def checkpoints(
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlCheckpointSummaryPage
Get a page of CheckpointSummary for the provided parameters.
coin_metadata
async def coin_metadata(
coin_type: StructTag) -> typing.Optional[GraphQlCoinMetadata]
Get the coin metadata for the coin type.
coins
async def coins(
owner: Address,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT,
coin_type: typing.Union[object, typing.Optional[StructTag]] = _DEFAULT
) -> GraphQlCoinPage
Get the list of coins for the specified address.
If coin_type is not provided, all coins will be returned. For IOTA coins, pass in the coin
type: 0x2::iota::IOTA.
dry_run_transaction
async def dry_run_transaction(
transaction: Transaction,
skip_checks: bool = False) -> GraphQlDryRunResult
Dry run a Transaction and return the transaction effects and dry run error (if any).
skipChecks optional flag disables the usual verification checks that prevent access to
objects that are owned by addresses other than the sender, and calling non-public, non-entry
functions, and some other checks. Defaults to false.
dry_run_transaction_kind
async def dry_run_transaction_kind(
transaction_kind: TransactionKind,
transaction_metadata: GraphQlTransactionMetadata,
skip_checks: bool = False) -> GraphQlDryRunResult
Dry run a TransactionKind and return the transaction effects and dry run error (if any).
skipChecks optional flag disables the usual verification checks that prevent access to
objects that are owned by addresses other than the sender, and calling non-public, non-entry
functions, and some other checks. Defaults to false.
transaction_metadata is the transaction metadata.
dynamic_field
async def dynamic_field(
address: Address, type_tag: TypeTag,
name: Value) -> typing.Optional[GraphQlDynamicFieldOutput]
Access a dynamic field on an object using its name. Names are arbitrary Move values whose type have copy, drop, and store, and are specified using their type, and their BCS contents, Base64 encoded.
The name argument is a json serialized type.
This returns GraphQLDynamicFieldOutput which contains the name, the value as json, and
object.
dynamic_fields
async def dynamic_fields(
address: Address,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlDynamicFieldOutputPage
Get a page of dynamic fields for the provided address. Note that this will also fetch dynamic fields on wrapped objects.
This returns a page of GraphQLDynamicFieldOutputs.
dynamic_object_field
async def dynamic_object_field(
address: Address, type_tag: TypeTag,
name: Value) -> typing.Optional[GraphQlDynamicFieldOutput]
Access a dynamic object field on an object using its name. Names are arbitrary Move values whose type have copy, drop, and store, and are specified using their type, and their BCS contents, Base64 encoded.
The name argument is a json serialized type.
This returns GraphQLDynamicFieldOutput which contains the name, the value as json, and
object.
epoch
async def epoch(
epoch: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> typing.Optional[GraphQlEpoch]
Return the epoch information for the provided epoch. If no epoch is provided, it will return the last known epoch.
epoch_total_checkpoints
async def epoch_total_checkpoints(
epoch: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> typing.Optional[int]
Return the number of checkpoints in this epoch. This will return Ok(None) if the epoch
requested is not available in the GraphQL service (e.g., due to pruning).
epoch_total_transaction_blocks
async def epoch_total_transaction_blocks(
epoch: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> typing.Optional[int]
Return the number of transaction blocks in this epoch. This will return Ok(None) if the
epoch requested is not available in the GraphQL service (e.g., due to pruning).
events
async def events(
filter: typing.Union[object,
typing.Optional[GraphQlEventFilter]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlEventPage
Return a page of tuple (event, transaction digest) based on the (optional) event filter.
events_subscription
def events_subscription(
filter: typing.Union[
object, typing.Optional[GraphQlSubscriptionEventFilter]] = _DEFAULT,
start_after: typing.Union[object,
typing.Optional[TransactionDigest]] = _DEFAULT
) -> GraphQlEventSubscription
Subscribe to a live stream of events matching the (optional) filter.
start_after optionally resumes from the transaction immediately following the given
transaction digest; thereafter the subscription tracks its own resume point across
reconnects.
Note: subscriptions are served over a WebSocket, which the node has to have enabled —
serviceConfig.enabledFeatures includes SUBSCRIPTIONS when it is available.
execute_transaction
async def execute_transaction(
signatures: typing.List[UserSignature],
transaction: Transaction,
wait_for: typing.Union[object,
typing.Optional[WaitForTransaction]] = _DEFAULT
) -> TransactionEffects
Execute a transaction.
If the wait fails, the error is returned although the transaction was executed, and its
effects are lost. To keep them, pass no wait_for and call wait_for_transaction on the
client afterwards.
gas_coins
async def gas_coins(
owner: Address,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlCoinPage
Get the list of gas coins for the specified address.
iota_names_default_name
async def iota_names_default_name(
address: Address,
format: typing.Optional[NameFormat]) -> typing.Optional[Name]
Get the default name pointing to this address, if one exists.
iota_names_lookup
async def iota_names_lookup(name: Name) -> typing.Optional[Address]
Return the resolved address for the given name.
iota_names_registrations
async def iota_names_registrations(
address: Address, pagination_filter: GraphQlPaginationFilter
) -> GraphQlNameRegistrationPage
Find all registration NFTs for the given address.
is_transaction_finalized
async def is_transaction_finalized(digest: TransactionDigest) -> bool
Returns whether the transaction for the given digest has been included in a checkpoint (finalized).
is_transaction_indexed_on_node
async def is_transaction_indexed_on_node(digest: TransactionDigest) -> bool
Returns whether the transaction for the given digest has been indexed on the node. This
means that it can be queried by its digest and its effects will be usable for subsequent
transactions. To check for full finalization, use is_transaction_finalized.
latest_checkpoint_sequence_number
async def latest_checkpoint_sequence_number() -> typing.Optional[int]
Return the sequence number of the latest checkpoint that has been executed.
max_page_size
async def max_page_size() -> int
Lazily fetch the max page size
move_object_contents
async def move_object_contents(
object_id: ObjectId,
version: typing.Union[object, typing.Optional[Version]] = _DEFAULT
) -> typing.Optional[Value]
Return the contents' JSON of an object that is a Move object.
If the object does not exist (e.g., due to pruning), this will return Ok(None). Similarly,
if this is not an object but an address, it will return Ok(None).
move_object_contents_bcs
async def move_object_contents_bcs(
object_id: ObjectId,
version: typing.Union[object, typing.Optional[Version]] = _DEFAULT
) -> typing.Optional[bytes]
Return the BCS of an object that is a Move object.
If the object does not exist (e.g., due to pruning), this will return Ok(None). Similarly,
if this is not an object but an address, it will return Ok(None).
move_view_call
async def move_view_call(
package: ObjectId,
module: str,
function: str,
type_arguments: typing.Union[
object, typing.Optional[typing.List[TypeTag]]] = _DEFAULT,
arguments: typing.Union[
object, typing.Optional[typing.List[MoveViewArg]]] = _DEFAULT
) -> GraphQlMoveViewResult
Execute a Move View Function.
A View Function is a function in a Move module with a return type that does not alter the state of the ledger. When using this interface, no transactions are submitted to the network for inclusion into the ledger.
This method allows calling nearly any Move function with a return type and any arguments. The function's result values are provided and decoded using the appropriate Move type, then formatted in JSON.
The use of this interface does not require signature checks (even for functions that take Owned Objects as input) or gas coins, as it does not alter ledger state. Spam attacks are dealt with at the RPC level rather than execution level.
Arguments
package- The package the Move function is defined inmodule- The module the Move function is defined infunction- The name of the Move functiontype_arguments- The type arguments of the Move functionarguments- The typed arguments to be passed into the Move function
Returns
A GraphQLMoveViewResult containing either execution results (return values) or an error.
move_view_call_json
async def move_view_call_json(
package: ObjectId,
module: str,
function: str,
type_arguments: typing.Union[object,
typing.Optional[typing.List[str]]] = _DEFAULT,
arguments: typing.Union[object,
typing.Optional[typing.List[Value]]] = _DEFAULT
) -> GraphQlMoveViewResult
Execute a Move View Function with raw JSON arguments.
This is an alternative to [GraphQLClient::move_view_call] that accepts raw JSON values
instead of typed arguments.
A View Function is a function in a Move module with a return type that does not alter the state of the ledger. When using this interface, no transactions are submitted to the network for inclusion into the ledger.
Arguments
package- The package the Move function is defined inmodule- The module the Move function is defined infunction- The name of the Move functiontype_arguments- The type arguments of the Move functionarguments- The arguments to be passed into the Move function, in JSON format
Returns
A GraphQLMoveViewResult containing either execution results (return values) or an error.
normalized_move_function
async def normalized_move_function(
package: Address,
module: str,
function: str,
version: typing.Union[object, typing.Optional[Version]] = _DEFAULT
) -> typing.Optional[GraphQlMoveFunction]
Return the normalized Move function data for the provided package, module, and function.
normalized_move_module
async def normalized_move_module(
package: Address,
module: str,
version: typing.Union[object, typing.Optional[Version]] = _DEFAULT,
pagination_filter_enums: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT,
pagination_filter_friends: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT,
pagination_filter_functions: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT,
pagination_filter_structs: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> typing.Optional[GraphQlMoveModule]
Return the normalized Move module data for the provided module.
object
async def object(
object_id: ObjectId,
version: typing.Union[object, typing.Optional[Version]] = _DEFAULT
) -> typing.Optional[Object]
Return an object based on the provided Address.
If the object does not exist (e.g., due to pruning), this will return Ok(None). Similarly,
if this is not an object but an address, it will return Ok(None).
object_bcs
async def object_bcs(object_id: ObjectId) -> typing.Optional[bytes]
Return the object's bcs content Vec<u8> based on the provided Address.
objects
async def objects(
filter: typing.Union[object,
typing.Optional[GraphQlObjectFilter]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlObjectPage
Return a page of objects based on the provided parameters.
Use this function together with the GraphQLObjectFilter::owner to get the objects owned by
an address.
package
async def package(
address: Address,
version: typing.Union[object, typing.Optional[Version]] = _DEFAULT
) -> typing.Optional[MovePackage]
The package corresponding to the given address (at the optionally given version). When no version is given, the package is loaded directly from the address given. Otherwise, the address is translated before loading to point to the package whose original ID matches the package at address, but whose version is version. For non-system packages, this might result in a different address than address because different versions of a package, introduced by upgrades, exist at distinct addresses.
Note that this interpretation of version is different from a historical object read (the interpretation of version for the object query).
package_latest
async def package_latest(address: Address) -> typing.Optional[MovePackage]
Fetch the latest version of the package at address. This corresponds to the package with the highest version that shares its original ID with the package at address.
package_versions
async def package_versions(
address: Address,
after_version: typing.Union[object, typing.Optional[Version]] = _DEFAULT,
before_version: typing.Union[object, typing.Optional[Version]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlMovePackagePage
Fetch all versions of package at address (packages that share this package's original ID), optionally bounding the versions exclusively from below with afterVersion, or from above with beforeVersion.
packages
async def packages(
after_checkpoint: typing.Union[object, typing.Optional[int]] = _DEFAULT,
before_checkpoint: typing.Union[object, typing.Optional[int]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlMovePackagePage
The Move packages that exist in the network, optionally filtered to be strictly before beforeCheckpoint and/or strictly after afterCheckpoint.
This query returns all versions of a given user package that appear between the specified checkpoints, but only records the latest versions of system packages.
protocol_config
async def protocol_config(
version: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> GraphQlProtocolConfigs
Get the protocol configuration.
reference_gas_price
async def reference_gas_price(
epoch: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> typing.Optional[int]
Get the reference gas price for the provided epoch or the last known one if no epoch is provided.
This will return Ok(None) if the epoch requested is not available in the GraphQL service
(e.g., due to pruning).
run_query
async def run_query(query: GraphQlQuery) -> Value
Run a query.
service_config
async def service_config() -> GraphQlServiceConfig
Get the GraphQL service configuration, including complexity limits, read and mutation limits, supported versions, and others.
total_supply
async def total_supply(coin_type: StructTag) -> typing.Optional[int]
Get total supply for the coin type.
total_transaction_blocks
async def total_transaction_blocks() -> typing.Optional[int]
The total number of transaction blocks in the network by the end of the last known checkpoint.
total_transaction_blocks_by_digest
async def total_transaction_blocks_by_digest(
digest: CheckpointDigest) -> typing.Optional[int]
The total number of transaction blocks in the network by the end of the provided checkpoint digest.
total_transaction_blocks_by_sequence_number
async def total_transaction_blocks_by_sequence_number(
sequence_number: int) -> typing.Optional[int]
The total number of transaction blocks in the network by the end of the provided checkpoint sequence number.
transaction
async def transaction(
digest: TransactionDigest) -> typing.Optional[SignedTransaction]
Get a transaction by its digest.
transaction_builder
def transaction_builder(sender: Address) -> GraphQlTransactionBuilder
Create a new transaction builder with the given sender address, backed by this client.
transaction_data_effects
async def transaction_data_effects(
digest: TransactionDigest
) -> typing.Optional[GraphQlTransactionDataEffects]
Get a transaction's data and effects by its digest.
transaction_effects
async def transaction_effects(
digest: TransactionDigest) -> typing.Optional[TransactionEffects]
Get a transaction's effects by its digest.
transactions
async def transactions(
filter: typing.Union[
object, typing.Optional[GraphQlTransactionsFilter]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlSignedTransactionPage
Get a page of transactions based on the provided filters.
transactions_data_effects
async def transactions_data_effects(
filter: typing.Union[
object, typing.Optional[GraphQlTransactionsFilter]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlTransactionDataEffectsPage
Get a page of transactions' data and effects based on the provided filters.
transactions_effects
async def transactions_effects(
filter: typing.Union[
object, typing.Optional[GraphQlTransactionsFilter]] = _DEFAULT,
pagination_filter: typing.Union[
object, typing.Optional[GraphQlPaginationFilter]] = _DEFAULT
) -> GraphQlTransactionEffectsPage
Get a page of transactions' effects based on the provided filters.
transactions_subscription
def transactions_subscription(
filter: typing.Union[
object,
typing.Optional[GraphQlSubscriptionTransactionFilter]] = _DEFAULT,
start_after: typing.Union[object,
typing.Optional[TransactionDigest]] = _DEFAULT
) -> GraphQlTransactionSubscription
Subscribe to a live stream of transactions matching the (optional) filter.
start_after optionally resumes from the transaction immediately following the given
digest; thereafter the subscription tracks its own resume point across reconnects.
Note: subscriptions are served over a WebSocket, which the node has to have enabled —
serviceConfig.enabledFeatures includes SUBSCRIPTIONS when it is available.
wait_for_transaction
async def wait_for_transaction(
digest: TransactionDigest,
wait_for: WaitForTransaction,
timeout: typing.Union[object,
typing.Optional[Duration]] = _DEFAULT) -> None
Wait for the indexing (on the node, not the indexer) or finalization of a transaction by its digest. An optional timeout can be provided, which, if exceeded, will return an error (default 60s).
with_subscription_url
def with_subscription_url(url: str) -> GraphQlClient
A copy of this client whose subscriptions connect to url instead of the subscriptions
endpoint under the RPC URL. An http or https URL is upgraded to ws or wss.