GraphQlClient
GraphQlClient
class GraphQlClient
The GraphQL client for interacting with the IOTA blockchain.
init(server:)
convenience init(server: String) throws
Create a new GraphQL client with the provided server address.
activeValidators(epoch:paginationFilter:)
func activeValidators(epoch: UInt64? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> 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.
addressTransactions(address:relation:filter:paginationFilter:)
func addressTransactions(address: Address, relation: GraphQlAddressTransactionRelationship? = nil, filter: GraphQlTransactionsFilter? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> 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(address:coinType:)
func balance(address: Address, coinType: StructTag? = nil) async throws -> UInt64?
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.
chainId()
func chainId() async throws -> String
Get the chain identifier.
checkpoint(digest:sequenceNumber:)
func checkpoint(digest: CheckpointDigest? = nil, sequenceNumber: UInt64? = nil) async throws -> 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(paginationFilter:)
func checkpoints(paginationFilter: GraphQlPaginationFilter? = nil) async throws -> GraphQlCheckpointSummaryPage
Get a page of CheckpointSummary for the provided parameters.
coinMetadata(coinType:)
func coinMetadata(coinType: StructTag) async throws -> GraphQlCoinMetadata?
Get the coin metadata for the coin type.
coins(owner:paginationFilter:coinType:)
func coins(owner: Address, paginationFilter: GraphQlPaginationFilter? = nil, coinType: StructTag? = nil) async throws -> 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.
dryRunTransaction(transaction:skipChecks:)
func dryRunTransaction(transaction: Transaction, skipChecks: Bool = false) async throws -> 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.
dryRunTransactionKind(transactionKind:transactionMetadata:skipChecks:)
func dryRunTransactionKind(transactionKind: TransactionKind, transactionMetadata: GraphQlTransactionMetadata, skipChecks: Bool = false) async throws -> 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.
dynamicField(address:typeTag:name:)
func dynamicField(address: Address, typeTag: TypeTag, name: Value) async throws -> 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.
dynamicFields(address:paginationFilter:)
func dynamicFields(address: Address, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> 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.
dynamicObjectField(address:typeTag:name:)
func dynamicObjectField(address: Address, typeTag: TypeTag, name: Value) async throws -> 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(epoch:)
func epoch(epoch: UInt64? = nil) async throws -> GraphQlEpoch?
Return the epoch information for the provided epoch. If no epoch is provided, it will return the last known epoch.
epochTotalCheckpoints(epoch:)
func epochTotalCheckpoints(epoch: UInt64? = nil) async throws -> UInt64?
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).
epochTotalTransactionBlocks(epoch:)
func epochTotalTransactionBlocks(epoch: UInt64? = nil) async throws -> UInt64?
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(filter:paginationFilter:)
func events(filter: GraphQlEventFilter? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> GraphQlEventPage
Return a page of tuple (event, transaction digest) based on the (optional) event filter.
eventsSubscription(filter:startAfter:)
func eventsSubscription(filter: GraphQlSubscriptionEventFilter? = nil, startAfter: TransactionDigest? = nil) -> 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.
executeTransaction(signatures:transaction:waitFor:)
func executeTransaction(signatures: [UserSignature], transaction: Transaction, waitFor: WaitForTransaction? = nil) async throws -> 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.
gasCoins(owner:paginationFilter:)
func gasCoins(owner: Address, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> GraphQlCoinPage
Get the list of gas coins for the specified address.
iotaNamesDefaultName(address:format:)
func iotaNamesDefaultName(address: Address, format: NameFormat?) async throws -> Name?
Get the default name pointing to this address, if one exists.
iotaNamesLookup(name:)
func iotaNamesLookup(name: Name) async throws -> Address?
Return the resolved address for the given name.
iotaNamesRegistrations(address:paginationFilter:)
func iotaNamesRegistrations(address: Address, paginationFilter: GraphQlPaginationFilter) async throws -> GraphQlNameRegistrationPage
Find all registration NFTs for the given address.
isTransactionFinalized(digest:)
func isTransactionFinalized(digest: TransactionDigest) async throws -> Bool
Returns whether the transaction for the given digest has been included in a checkpoint (finalized).
isTransactionIndexedOnNode(digest:)
func isTransactionIndexedOnNode(digest: TransactionDigest) async throws -> 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.
latestCheckpointSequenceNumber()
func latestCheckpointSequenceNumber() async throws -> UInt64?
Return the sequence number of the latest checkpoint that has been executed.
maxPageSize()
func maxPageSize() async throws -> Int32
Lazily fetch the max page size
moveObjectContents(objectId:version:)
func moveObjectContents(objectId: ObjectId, version: Version? = nil) async throws -> 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).
moveObjectContentsBcs(objectId:version:)
func moveObjectContentsBcs(objectId: ObjectId, version: Version? = nil) async throws -> Data?
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).
moveViewCall(package:module:function:typeArguments:arguments:)
func moveViewCall(package: ObjectId, module: String, function: String, typeArguments: [TypeTag]? = nil, arguments: [MoveViewArg]? = nil) async throws -> 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.
moveViewCallJson(package:module:function:typeArguments:arguments:)
func moveViewCallJson(package: ObjectId, module: String, function: String, typeArguments: [String]? = nil, arguments: [Value]? = nil) async throws -> 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.
normalizedMoveFunction(package:module:function:version:)
func normalizedMoveFunction(package: Address, module: String, function: String, version: Version? = nil) async throws -> GraphQlMoveFunction?
Return the normalized Move function data for the provided package, module, and function.
normalizedMoveModule(package:module:version:paginationFilterEnums:paginationFilterFriends:paginationFilterFunctions:paginationFilterStructs:)
func normalizedMoveModule(package: Address, module: String, version: Version? = nil, paginationFilterEnums: GraphQlPaginationFilter? = nil, paginationFilterFriends: GraphQlPaginationFilter? = nil, paginationFilterFunctions: GraphQlPaginationFilter? = nil, paginationFilterStructs: GraphQlPaginationFilter? = nil) async throws -> GraphQlMoveModule?
Return the normalized Move module data for the provided module.
object(objectId:version:)
func object(objectId: ObjectId, version: Version? = nil) async throws -> 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).
objectBcs(objectId:)
func objectBcs(objectId: ObjectId) async throws -> Data?
Return the object's bcs content Vec<u8> based on the provided Address.
objects(filter:paginationFilter:)
func objects(filter: GraphQlObjectFilter? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> 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(address:version:)
func package(address: Address, version: Version? = nil) async throws -> 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).
packageLatest(address:)
func packageLatest(address: Address) async throws -> 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.
packageVersions(address:afterVersion:beforeVersion:paginationFilter:)
func packageVersions(address: Address, afterVersion: Version? = nil, beforeVersion: Version? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> 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(afterCheckpoint:beforeCheckpoint:paginationFilter:)
func packages(afterCheckpoint: UInt64? = nil, beforeCheckpoint: UInt64? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> 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.
protocolConfig(version:)
func protocolConfig(version: UInt64? = nil) async throws -> GraphQlProtocolConfigs
Get the protocol configuration.
referenceGasPrice(epoch:)
func referenceGasPrice(epoch: UInt64? = nil) async throws -> UInt64?
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).
runQuery(query:)
func runQuery(query: GraphQlQuery) async throws -> Value
Run a query.
serviceConfig()
func serviceConfig() async throws -> GraphQlServiceConfig
Get the GraphQL service configuration, including complexity limits, read and mutation limits, supported versions, and others.
totalSupply(coinType:)
func totalSupply(coinType: StructTag) async throws -> UInt64?
Get total supply for the coin type.
totalTransactionBlocks()
func totalTransactionBlocks() async throws -> UInt64?
The total number of transaction blocks in the network by the end of the last known checkpoint.
totalTransactionBlocksByDigest(digest:)
func totalTransactionBlocksByDigest(digest: CheckpointDigest) async throws -> UInt64?
The total number of transaction blocks in the network by the end of the provided checkpoint digest.
totalTransactionBlocksBySequenceNumber(sequenceNumber:)
func totalTransactionBlocksBySequenceNumber(sequenceNumber: UInt64) async throws -> UInt64?
The total number of transaction blocks in the network by the end of the provided checkpoint sequence number.
transaction(digest:)
func transaction(digest: TransactionDigest) async throws -> SignedTransaction?
Get a transaction by its digest.
transactionBuilder(sender:)
func transactionBuilder(sender: Address) -> GraphQlTransactionBuilder
Create a new transaction builder with the given sender address, backed by this client.
transactionDataEffects(digest:)
func transactionDataEffects(digest: TransactionDigest) async throws -> GraphQlTransactionDataEffects?
Get a transaction's data and effects by its digest.
transactionEffects(digest:)
func transactionEffects(digest: TransactionDigest) async throws -> TransactionEffects?
Get a transaction's effects by its digest.
transactions(filter:paginationFilter:)
func transactions(filter: GraphQlTransactionsFilter? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> GraphQlSignedTransactionPage
Get a page of transactions based on the provided filters.
transactionsDataEffects(filter:paginationFilter:)
func transactionsDataEffects(filter: GraphQlTransactionsFilter? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> GraphQlTransactionDataEffectsPage
Get a page of transactions' data and effects based on the provided filters.
transactionsEffects(filter:paginationFilter:)
func transactionsEffects(filter: GraphQlTransactionsFilter? = nil, paginationFilter: GraphQlPaginationFilter? = nil) async throws -> GraphQlTransactionEffectsPage
Get a page of transactions' effects based on the provided filters.
transactionsSubscription(filter:startAfter:)
func transactionsSubscription(filter: GraphQlSubscriptionTransactionFilter? = nil, startAfter: TransactionDigest? = nil) -> 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.
waitForTransaction(digest:waitFor:timeout:)
func waitForTransaction(digest: TransactionDigest, waitFor: WaitForTransaction, timeout: TimeInterval? = nil) async throws
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).
withSubscriptionUrl(url:)
func withSubscriptionUrl(url: String) throws -> 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.
newDevnet()
static func newDevnet() throws -> GraphQlClient
Create a new GraphQL client connected to the devnet GraphQL server:
https://graphql.devnet.iota.cafe.
newLocalnet()
static func newLocalnet() throws -> GraphQlClient
Create a new GraphQL client connected to the localhost GraphQL server:
http://localhost:9125/graphql.
newMainnet()
static func newMainnet() throws -> GraphQlClient
Create a new GraphQL client connected to the mainnet GraphQL server:
https://graphql.mainnet.iota.cafe.
newTestnet()
static func newTestnet() throws -> GraphQlClient
Create a new GraphQL client connected to the testnet GraphQL server:
https://graphql.testnet.iota.cafe.
newWithHttpOptions(server:options:)
static func newWithHttpOptions(server: String, options: HttpClientOptions) throws -> GraphQlClient
Create a new GraphQL client with the provided server address, using an HTTP client built to the given options.