GraphQlClient
Namespace: IotaSdk
The GraphQL client for interacting with the IOTA blockchain.
public class GraphQlClient : IGraphQlClient, System.IDisposable
Inheritance Object → GraphQlClient
Implements IGraphQlClient, IDisposable
Attributes NullableContextAttribute, NullableAttribute
Constructors
GraphQlClient(UInt64)
public GraphQlClient(ulong pointer)
Parameters
pointer UInt64
GraphQlClient(String)
Create a new GraphQL client with the provided server address.
public GraphQlClient(string server)
Parameters
server String
Methods
Destroy()
public void Destroy()
Dispose()
public void Dispose()
Balance(Address, StructTag)
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.
public async Task<ulong?> Balance(Address address, StructTag? coinType = null)
Parameters
address Address
coinType StructTag?
Returns
Exceptions
Checkpoint(CheckpointDigest, UInt64?)
Get the CheckpointSummary for a given checkpoint digest or checkpoint id. If none is
provided, it will use the last known checkpoint id.
public async Task<CheckpointSummary?> Checkpoint(CheckpointDigest? digest = null, ulong? sequenceNumber = null)
Parameters
digest CheckpointDigest?
sequenceNumber UInt64?
Returns
Exceptions
Checkpoints(GraphQlPaginationFilter)
Get a page of CheckpointSummary for the provided parameters.
public async Task<GraphQlCheckpointSummaryPage> Checkpoints(GraphQlPaginationFilter? paginationFilter = null)
Parameters
paginationFilter GraphQlPaginationFilter?
Returns
Task<GraphQlCheckpointSummaryPage>
Exceptions
LatestCheckpointSequenceNumber()
Return the sequence number of the latest checkpoint that has been executed.
public async Task<ulong?> LatestCheckpointSequenceNumber()
Returns
Exceptions
TotalTransactionBlocks()
The total number of transaction blocks in the network by the end of the last known checkpoint.
public async Task<ulong?> TotalTransactionBlocks()
Returns
Exceptions
TotalTransactionBlocksByDigest(CheckpointDigest)
The total number of transaction blocks in the network by the end of the provided checkpoint digest.
public async Task<ulong?> TotalTransactionBlocksByDigest(CheckpointDigest digest)
Parameters
digest CheckpointDigest
Returns
Exceptions
TotalTransactionBlocksBySequenceNumber(UInt64)
The total number of transaction blocks in the network by the end of the provided checkpoint sequence number.
public async Task<ulong?> TotalTransactionBlocksBySequenceNumber(ulong sequenceNumber)
Parameters
sequenceNumber UInt64
Returns
Exceptions
CoinMetadata(StructTag)
Get the coin metadata for the coin type.
public async Task<GraphQlCoinMetadata?> CoinMetadata(StructTag coinType)
Parameters
coinType StructTag
Returns
Exceptions
Coins(Address, GraphQlPaginationFilter, StructTag)
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.
public async Task<GraphQlCoinPage> Coins(Address owner, GraphQlPaginationFilter? paginationFilter = null, StructTag? coinType = null)
Parameters
owner Address
paginationFilter GraphQlPaginationFilter?
coinType StructTag?
Returns
Exceptions
GasCoins(Address, GraphQlPaginationFilter)
Get the list of gas coins for the specified address.
public async Task<GraphQlCoinPage> GasCoins(Address owner, GraphQlPaginationFilter? paginationFilter = null)
Parameters
owner Address
paginationFilter GraphQlPaginationFilter?
Returns
Exceptions
TotalSupply(StructTag)
Get total supply for the coin type.
public async Task<ulong?> TotalSupply(StructTag coinType)
Parameters
coinType StructTag
Returns
Exceptions
DryRunTransaction(Transaction, Boolean)
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.
public async Task<GraphQlDryRunResult> DryRunTransaction(Transaction transaction, bool skipChecks = false)
Parameters
transaction Transaction
skipChecks Boolean
Returns
Exceptions
DryRunTransactionKind(TransactionKind, GraphQlTransactionMetadata, Boolean)
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.
public async Task<GraphQlDryRunResult> DryRunTransactionKind(TransactionKind transactionKind, GraphQlTransactionMetadata transactionMetadata, bool skipChecks = false)
Parameters
transactionKind TransactionKind
transactionMetadata GraphQlTransactionMetadata
skipChecks Boolean
Returns
Exceptions
DynamicField(Address, TypeTag, String)
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.
public async Task<GraphQlDynamicFieldOutput?> DynamicField(Address address, TypeTag typeTag, string name)
Parameters
address Address
typeTag TypeTag
name String
Returns
Task<GraphQlDynamicFieldOutput>
Exceptions
DynamicFields(Address, GraphQlPaginationFilter)
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.
public async Task<GraphQlDynamicFieldOutputPage> DynamicFields(Address address, GraphQlPaginationFilter? paginationFilter = null)
Parameters
address Address
paginationFilter GraphQlPaginationFilter?
Returns
Task<GraphQlDynamicFieldOutputPage>
Exceptions
DynamicObjectField(Address, TypeTag, String)
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.
public async Task<GraphQlDynamicFieldOutput?> DynamicObjectField(Address address, TypeTag typeTag, string name)
Parameters
address Address
typeTag TypeTag
name String
Returns
Task<GraphQlDynamicFieldOutput>
Exceptions
Epoch(UInt64?)
Return the epoch information for the provided epoch. If no epoch is provided, it will return the last known epoch.
public async Task<GraphQlEpoch?> Epoch(ulong? epoch = null)
Parameters
epoch UInt64?
Returns
Exceptions
EpochTotalCheckpoints(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).
public async Task<ulong?> EpochTotalCheckpoints(ulong? epoch = null)
Parameters
epoch UInt64?
Returns
Exceptions
EpochTotalTransactionBlocks(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).
public async Task<ulong?> EpochTotalTransactionBlocks(ulong? epoch = null)
Parameters
epoch UInt64?
Returns
Exceptions
Events(GraphQlEventFilter, GraphQlPaginationFilter)
Return a page of tuple (event, transaction digest) based on the (optional) event filter.
public async Task<GraphQlEventPage> Events(GraphQlEventFilter? filter = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
filter GraphQlEventFilter?
paginationFilter GraphQlPaginationFilter?
Returns
Exceptions
IotaNamesDefaultName(Address, NameFormat?)
Get the default name pointing to this address, if one exists.
public async Task<Name?> IotaNamesDefaultName(Address address, NameFormat? format)
Parameters
address Address
format NameFormat?
Returns
Exceptions
IotaNamesLookup(Name)
Return the resolved address for the given name.
public async Task<Address?> IotaNamesLookup(Name name)
Parameters
name Name
Returns
Exceptions
IotaNamesRegistrations(Address, GraphQlPaginationFilter)
Find all registration NFTs for the given address.
public async Task<GraphQlNameRegistrationPage> IotaNamesRegistrations(Address address, GraphQlPaginationFilter paginationFilter)
Parameters
address Address
paginationFilter GraphQlPaginationFilter
Returns
Task<GraphQlNameRegistrationPage>
Exceptions
MoveViewCall(ObjectId, String, String, TypeTag[], MoveViewArg[])
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.
public async Task<GraphQlMoveViewResult> MoveViewCall(ObjectId package, string module, string function, TypeTag[]? typeArguments = null, MoveViewArg[]? arguments = null)
Parameters
package ObjectId
module String
function String
typeArguments TypeTag[]?
arguments MoveViewArg[]?
Returns
Exceptions
MoveViewCallJson(ObjectId, String, String, String[], String[])
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.
public async Task<GraphQlMoveViewResult> MoveViewCallJson(ObjectId package, string module, string function, String[]? typeArguments = null, String[]? arguments = null)
Parameters
package ObjectId
module String
function String
typeArguments String[]?
arguments String[]?
Returns
Exceptions
ActiveValidators(UInt64?, GraphQlPaginationFilter)
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.
public async Task<GraphQlValidatorPage> ActiveValidators(ulong? epoch = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
epoch UInt64?
paginationFilter GraphQlPaginationFilter?
Returns
Exceptions
ChainId()
Get the chain identifier.
public async Task<string> ChainId()
Returns
Exceptions
ProtocolConfig(UInt64?)
Get the protocol configuration.
public async Task<GraphQlProtocolConfigs> ProtocolConfig(ulong? version = null)
Parameters
version UInt64?
Returns
Exceptions
ReferenceGasPrice(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).
public async Task<ulong?> ReferenceGasPrice(ulong? epoch = null)
Parameters
epoch UInt64?
Returns
Exceptions
MoveObjectContents(ObjectId, Version)
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).
public async Task<string?> MoveObjectContents(ObjectId objectId, Version? version = null)
Parameters
objectId ObjectId
version Version?
Returns
Exceptions
MoveObjectContentsBcs(ObjectId, Version)
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).
public async Task<Byte[]?> MoveObjectContentsBcs(ObjectId objectId, Version? version = null)
Parameters
objectId ObjectId
version Version?
Returns
Exceptions
Object(ObjectId, Version)
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).
public async Task<Object?> Object(ObjectId objectId, Version? version = null)
Parameters
objectId ObjectId
version Version?
Returns
Exceptions
ObjectBcs(ObjectId)
public async Task<Byte[]?> ObjectBcs(ObjectId objectId)
Parameters
objectId ObjectId
Returns
Objects(GraphQlObjectFilter, GraphQlPaginationFilter)
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.
public async Task<GraphQlObjectPage> Objects(GraphQlObjectFilter? filter = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
filter GraphQlObjectFilter?
paginationFilter GraphQlPaginationFilter?
Returns
Exceptions
NormalizedMoveFunction(Address, String, String, Version)
Return the normalized Move function data for the provided package, module, and function.
public async Task<GraphQlMoveFunction?> NormalizedMoveFunction(Address package, string module, string function, Version? version = null)
Parameters
package Address
module String
function String
version Version?
Returns
Exceptions
NormalizedMoveModule(Address, String, Version, GraphQlPaginationFilter, GraphQlPaginationFilter, GraphQlPaginationFilter, GraphQlPaginationFilter)
Return the normalized Move module data for the provided module.
public async Task<GraphQlMoveModule?> NormalizedMoveModule(Address package, string module, Version? version = null, GraphQlPaginationFilter? paginationFilterEnums = null, GraphQlPaginationFilter? paginationFilterFriends = null, GraphQlPaginationFilter? paginationFilterFunctions = null, GraphQlPaginationFilter? paginationFilterStructs = null)
Parameters
package Address
module String
version Version?
paginationFilterEnums GraphQlPaginationFilter?
paginationFilterFriends GraphQlPaginationFilter?
paginationFilterFunctions GraphQlPaginationFilter?
paginationFilterStructs GraphQlPaginationFilter?
Returns
Exceptions
Package(Address, Version)
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).
public async Task<MovePackage?> Package(Address address, Version? version = null)
Parameters
address Address
version Version?
Returns
Exceptions
PackageLatest(Address)
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.
public async Task<MovePackage?> PackageLatest(Address address)
Parameters
address Address
Returns
Exceptions
PackageVersions(Address, Version, Version, GraphQlPaginationFilter)
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.
public async Task<GraphQlMovePackagePage> PackageVersions(Address address, Version? afterVersion = null, Version? beforeVersion = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
address Address
afterVersion Version?
beforeVersion Version?
paginationFilter GraphQlPaginationFilter?
Returns
Exceptions
Packages(UInt64?, UInt64?, GraphQlPaginationFilter)
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.
public async Task<GraphQlMovePackagePage> Packages(ulong? afterCheckpoint = null, ulong? beforeCheckpoint = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
afterCheckpoint UInt64?
beforeCheckpoint UInt64?
paginationFilter GraphQlPaginationFilter?
Returns
Exceptions
AddressTransactions(Address, GraphQlAddressTransactionRelationship?, GraphQlTransactionsFilter, GraphQlPaginationFilter)
Get a page of transactions related to the given address.
relation selects how the address relates to them, defaulting to the transactions it sent.
public async Task<GraphQlSignedTransactionPage> AddressTransactions(Address address, GraphQlAddressTransactionRelationship? relation = null, GraphQlTransactionsFilter? filter = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
address Address
relation GraphQlAddressTransactionRelationship?
filter GraphQlTransactionsFilter?
paginationFilter GraphQlPaginationFilter?
Returns
Task<GraphQlSignedTransactionPage>
Exceptions
ExecuteTransaction(UserSignature[], Transaction, WaitForTransaction?)
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.
public async Task<TransactionEffects> ExecuteTransaction(UserSignature[] signatures, Transaction transaction, WaitForTransaction? waitFor = null)
Parameters
signatures UserSignature[]
transaction Transaction
waitFor WaitForTransaction?
Returns
Exceptions
IsTransactionFinalized(TransactionDigest)
Returns whether the transaction for the given digest has been included in a checkpoint (finalized).
public async Task<bool> IsTransactionFinalized(TransactionDigest digest)
Parameters
digest TransactionDigest
Returns
Exceptions
IsTransactionIndexedOnNode(TransactionDigest)
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.
public async Task<bool> IsTransactionIndexedOnNode(TransactionDigest digest)
Parameters
digest TransactionDigest
Returns
Exceptions
Transaction(TransactionDigest)
Get a transaction by its digest.
public async Task<SignedTransaction?> Transaction(TransactionDigest digest)
Parameters
digest TransactionDigest
Returns
Exceptions
TransactionDataEffects(TransactionDigest)
Get a transaction's data and effects by its digest.
public async Task<GraphQlTransactionDataEffects?> TransactionDataEffects(TransactionDigest digest)
Parameters
digest TransactionDigest
Returns
Task<GraphQlTransactionDataEffects>
Exceptions
TransactionEffects(TransactionDigest)
Get a transaction's effects by its digest.
public async Task<TransactionEffects?> TransactionEffects(TransactionDigest digest)
Parameters
digest TransactionDigest
Returns
Exceptions
Transactions(GraphQlTransactionsFilter, GraphQlPaginationFilter)
Get a page of transactions based on the provided filters.
public async Task<GraphQlSignedTransactionPage> Transactions(GraphQlTransactionsFilter? filter = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
filter GraphQlTransactionsFilter?
paginationFilter GraphQlPaginationFilter?
Returns
Task<GraphQlSignedTransactionPage>
Exceptions
TransactionsDataEffects(GraphQlTransactionsFilter, GraphQlPaginationFilter)
Get a page of transactions' data and effects based on the provided filters.
public async Task<GraphQlTransactionDataEffectsPage> TransactionsDataEffects(GraphQlTransactionsFilter? filter = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
filter GraphQlTransactionsFilter?
paginationFilter GraphQlPaginationFilter?
Returns
Task<GraphQlTransactionDataEffectsPage>
Exceptions
TransactionsEffects(GraphQlTransactionsFilter, GraphQlPaginationFilter)
Get a page of transactions' effects based on the provided filters.
public async Task<GraphQlTransactionEffectsPage> TransactionsEffects(GraphQlTransactionsFilter? filter = null, GraphQlPaginationFilter? paginationFilter = null)
Parameters
filter GraphQlTransactionsFilter?
paginationFilter GraphQlPaginationFilter?
Returns
Task<GraphQlTransactionEffectsPage>
Exceptions
WaitForTransaction(TransactionDigest, WaitForTransaction, TimeSpan?)
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).
public async Task WaitForTransaction(TransactionDigest digest, WaitForTransaction waitFor, TimeSpan? timeout = null)
Parameters
digest TransactionDigest
waitFor WaitForTransaction
timeout TimeSpan?
Returns
Exceptions
MaxPageSize()
Lazily fetch the max page size
public async Task<int> MaxPageSize()
Returns
Exceptions
RunQuery(GraphQlQuery)
Run a query.
public async Task<string> RunQuery(GraphQlQuery query)
Parameters
query GraphQlQuery
Returns
Exceptions
ServiceConfig()
Get the GraphQL service configuration, including complexity limits, read and mutation limits, supported versions, and others.
public async Task<GraphQlServiceConfig> ServiceConfig()
Returns
Exceptions
TransactionBuilder(Address)
Create a new transaction builder with the given sender address, backed by this client.
public GraphQlTransactionBuilder TransactionBuilder(Address sender)
Parameters
sender Address
Returns
WithSubscriptionUrl(String)
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.
public GraphQlClient WithSubscriptionUrl(string url)
Parameters
url String
Returns
Exceptions
EventsSubscription(GraphQlSubscriptionEventFilter, TransactionDigest)
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.
public GraphQlEventSubscription EventsSubscription(GraphQlSubscriptionEventFilter? filter = null, TransactionDigest? startAfter = null)
Parameters
filter GraphQlSubscriptionEventFilter?
startAfter TransactionDigest?
Returns
TransactionsSubscription(GraphQlSubscriptionTransactionFilter, TransactionDigest)
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.
public GraphQlTransactionSubscription TransactionsSubscription(GraphQlSubscriptionTransactionFilter? filter = null, TransactionDigest? startAfter = null)
Parameters
filter GraphQlSubscriptionTransactionFilter?
startAfter TransactionDigest?
Returns
GraphQlTransactionSubscription
NewDevnet()
public static GraphQlClient NewDevnet()
Returns
NewLocalnet()
public static GraphQlClient NewLocalnet()
Returns
NewMainnet()
public static GraphQlClient NewMainnet()
Returns
NewTestnet()
public static GraphQlClient NewTestnet()
Returns
NewWithHttpOptions(String, HttpClientOptions)
Create a new GraphQL client with the provided server address, using an HTTP client built to the given options.
public static GraphQlClient NewWithHttpOptions(string server, HttpClientOptions options)
Parameters
server String
options HttpClientOptions