Skip to main content

GrpcClient

GrpcClient​

class GrpcClient

The gRPC client for interacting with the IOTA blockchain.

init(uri:)​

convenience init(uri: String) throws

Create a new gRPC client with the provided server URI.

allCoins(owner:coinType:limit:)​

func allCoins(owner: Address, coinType: StructTag? = nil, limit: UInt32? = nil) async throws -> [Coin]

List all coins owned by an address, optionally filtered by coin type (the inner type T of Coin<T>), auto-paginating up to limit coins. If coin_type is None, coins of all types are returned. If limit is None, all coins are returned.

allDynamicFields(parent:limit:readMask:)​

func allDynamicFields(parent: ObjectId, limit: UInt32? = nil, readMask: [GrpcDynamicFieldField]? = nil) async throws -> [GrpcDynamicField]

List all dynamic fields of an object, auto-paginating up to limit fields. If limit is None, all fields are returned.

The optional read_mask controls which fields the server returns. If None, the parent and field id are returned.

allOwnedObjects(owner:objectType:limit:readMask:)​

func allOwnedObjects(owner: Address, objectType: StructTag? = nil, limit: UInt32? = nil, readMask: [GrpcOwnedObjectField]? = nil) async throws -> [GrpcObject]

List all objects owned by an address, optionally filtered by object type, auto-paginating up to limit objects. If limit is None, all objects are returned.

The optional read_mask controls which fields the server returns. If None, the object reference and the BCS-encoded object are returned.

allPackageVersions(packageId:limit:)​

func allPackageVersions(packageId: ObjectId, limit: UInt32? = nil) async throws -> [GrpcPackageVersion]

List all versions of a Move package, auto-paginating up to limit versions. If limit is None, all versions are returned.

checkpointByDigest(digest:transactionsFilter:eventsFilter:readMask:)​

func checkpointByDigest(digest: CheckpointDigest, transactionsFilter: GrpcTransactionFilter? = nil, eventsFilter: GrpcEventFilter? = nil, readMask: [GrpcCheckpointResponseField]? = nil) async throws -> GrpcCheckpointResponse

Get a checkpoint by its digest.

The optional transactions_filter and events_filter narrow the transactions and events returned for the checkpoint.

The optional read_mask controls which fields the server returns. If None, only the checkpoint summary is returned.

checkpointBySequenceNumber(sequenceNumber:transactionsFilter:eventsFilter:readMask:)​

func checkpointBySequenceNumber(sequenceNumber: UInt64, transactionsFilter: GrpcTransactionFilter? = nil, eventsFilter: GrpcEventFilter? = nil, readMask: [GrpcCheckpointResponseField]? = nil) async throws -> GrpcCheckpointResponse

Get a checkpoint by its sequence number.

The optional transactions_filter and events_filter narrow the transactions and events returned for the checkpoint.

The optional read_mask controls which fields the server returns. If None, only the checkpoint summary is returned.

checkpointLatest(transactionsFilter:eventsFilter:readMask:)​

func checkpointLatest(transactionsFilter: GrpcTransactionFilter? = nil, eventsFilter: GrpcEventFilter? = nil, readMask: [GrpcCheckpointResponseField]? = nil) async throws -> GrpcCheckpointResponse

Get the latest checkpoint.

The optional transactions_filter and events_filter narrow the transactions and events returned for the checkpoint.

The optional read_mask controls which fields the server returns. If None, only the checkpoint summary is returned.

checkpointsStream(startSequenceNumber:endSequenceNumber:transactionsFilter:eventsFilter:readMask:)​

func checkpointsStream(startSequenceNumber: UInt64? = nil, endSequenceNumber: UInt64? = nil, transactionsFilter: GrpcTransactionFilter? = nil, eventsFilter: GrpcEventFilter? = nil, readMask: [GrpcCheckpointResponseField]? = nil) async throws -> GrpcCheckpointStream

Stream checkpoints across a range of sequence numbers.

Every checkpoint in the range is yielded, even if the filters produce no matching transactions or events within it.

If start_sequence_number is None, the stream starts from the latest checkpoint. If end_sequence_number is None, the stream continues indefinitely.

The optional transactions_filter and events_filter narrow the transactions and events returned for each checkpoint.

The optional read_mask controls which fields the server returns for each checkpoint. If None, only the checkpoint summary is returned.

checkpointsStreamFiltered(startSequenceNumber:endSequenceNumber:transactionsFilter:eventsFilter:progressIntervalMs:readMask:)​

func checkpointsStreamFiltered(startSequenceNumber: UInt64? = nil, endSequenceNumber: UInt64? = nil, transactionsFilter: GrpcTransactionFilter? = nil, eventsFilter: GrpcEventFilter? = nil, progressIntervalMs: UInt32? = nil, readMask: [GrpcCheckpointResponseField]? = nil) async throws -> GrpcFilteredCheckpointStream

Stream checkpoints across a range of sequence numbers, skipping checkpoints with no data matching the filters.

Unlike [GrpcClient::checkpoints_stream], the filters decide which checkpoints are returned at all; checkpoints without any matching transactions or events are skipped entirely. At least one of transactions_filter or events_filter must be set.

While the server scans non-matching checkpoints, the stream yields progress items indicating the current scan position (default every 2000ms, configurable via progress_interval_ms, minimum 500ms).

If start_sequence_number is None, the stream starts from the latest checkpoint. If end_sequence_number is None, the stream continues indefinitely.

The optional read_mask controls which fields the server returns for each checkpoint. If None, only the checkpoint summary is returned.

coinInfo(coinType:)​

func coinInfo(coinType: StructTag) async throws -> GrpcCoinInfo

Get information about a coin type, including its metadata, treasury, and regulated metadata.

coin_type is the inner type T of Coin<T>, e.g. 0x2::iota::IOTA, not the Coin<T> wrapper.

coins(owner:coinType:pageSize:pageToken:)​

func coins(owner: Address, coinType: StructTag? = nil, pageSize: UInt32? = nil, pageToken: Data? = nil) async throws -> GrpcCoinPage

List a single page of coins owned by an address, optionally filtered by coin type (the inner type T of Coin<T>). If coin_type is None, coins of all types are returned.

Pass the returned next_page_token back in to retrieve the next page.

dynamicFields(parent:pageSize:pageToken:readMask:)​

func dynamicFields(parent: ObjectId, pageSize: UInt32? = nil, pageToken: Data? = nil, readMask: [GrpcDynamicFieldField]? = nil) async throws -> GrpcDynamicFieldPage

List a single page of dynamic fields of an object.

Pass the returned next_page_token back in to retrieve the next page.

The optional read_mask controls which fields the server returns. If None, the parent and field id are returned.

epoch(epoch:readMask:)​

func epoch(epoch: UInt64? = nil, readMask: [GrpcEpochField]? = nil) async throws -> GrpcEpochInfo

Get information about an epoch. If epoch is None, the current epoch is returned.

The optional read_mask controls which fields the server returns.

executeTransaction(signedTransaction:checkpointInclusionTimeoutMs:readMask:)​

func executeTransaction(signedTransaction: SignedTransaction, checkpointInclusionTimeoutMs: UInt64? = nil, readMask: [GrpcTransactionField]? = nil) async throws -> GrpcExecutedTransaction

Execute a signed transaction.

If checkpoint_inclusion_timeout_ms is provided, the server waits up to that long for the transaction to be included in a checkpoint before responding. Include checkpoint and timestamp in the read_mask to receive that data.

The optional read_mask controls which fields the server returns. If None, the transaction digest, effects, events, and input/output objects are returned.

executeTransactions(transactions:checkpointInclusionTimeoutMs:readMask:)​

func executeTransactions(transactions: [SignedTransaction], checkpointInclusionTimeoutMs: UInt64? = nil, readMask: [GrpcTransactionField]? = nil) async throws -> GrpcExecutedTransactionResults

Execute a batch of signed transactions.

An error the server reports for one transaction does not abort the rest of the batch; reading that transaction's item throws the server's error message. A transaction the server returns but that cannot be decoded fails the whole call.

If checkpoint_inclusion_timeout_ms is provided, the server waits up to that long for the transactions to be included in a checkpoint before responding. Include checkpoint and timestamp in the read_mask to receive that data.

The optional read_mask controls which fields the server returns. If None, the transaction digest, effects, events, and input/output objects are returned.

health(thresholdMs:)​

func health(thresholdMs: UInt64? = nil) async throws -> GrpcHealthInfo

Get the health of the node serving the gRPC service.

If threshold_ms is provided, the server returns an UNAVAILABLE error when the most recently executed checkpoint is older than the threshold.

objects(objectIds:readMask:)​

func objects(objectIds: [ObjectId], readMask: [GrpcObjectField]? = nil) async throws -> GrpcObjectResults

Get the latest version of objects by their ids.

Results are returned in the same order as the input ids, one per id. An object the serving node cannot return — because it is not found, was deleted, or has been pruned — fails only its own item, which reading throws with the server's error message. An object the server returns but that cannot be decoded fails the whole call.

The optional read_mask controls which fields the server returns. If None, the reference and the object are returned.

objectsWithVersions(requests:readMask:)​

func objectsWithVersions(requests: [GrpcObjectRequest], readMask: [GrpcObjectField]? = nil) async throws -> GrpcObjectResults

Get objects by their ids and optional versions.

Results are returned in the same order as the input requests, one per request. An object the serving node cannot return — because it is not found, was deleted, or has been pruned — fails only its own item, which reading throws with the server's error message. An object the server returns but that cannot be decoded fails the whole call.

The optional read_mask controls which fields the server returns. If None, the reference and the object are returned.

ownedObjects(owner:objectType:pageSize:pageToken:readMask:)​

func ownedObjects(owner: Address, objectType: StructTag? = nil, pageSize: UInt32? = nil, pageToken: Data? = nil, readMask: [GrpcOwnedObjectField]? = nil) async throws -> GrpcOwnedObjectPage

List a single page of objects owned by an address, optionally filtered by object type.

Pass the returned next_page_token back in to retrieve the next page.

The optional read_mask controls which fields the server returns. If None, the object reference and the BCS-encoded object are returned.

packageVersions(packageId:pageSize:pageToken:)​

func packageVersions(packageId: ObjectId, pageSize: UInt32? = nil, pageToken: Data? = nil) async throws -> GrpcPackageVersionPage

List a single page of versions of a Move package.

Pass the returned next_page_token back in to retrieve the next page.

referenceGasPrice()​

func referenceGasPrice() async throws -> UInt64

Get the reference gas price of the current epoch, denominated in NANOS.

serviceInfo(readMask:)​

func serviceInfo(readMask: [GrpcServiceInfoField]? = nil) async throws -> GrpcServiceInfo

Get information about the gRPC service and the node serving it.

The optional read_mask controls which fields the server returns.

setBasicAuth(username:password:)​

func setBasicAuth(username: String, password: String?)

Set a basic auth Authorization header that is sent with every request.

setBearerAuth(token:)​

func setBearerAuth(token: String) throws

Set a bearer auth Authorization header that is sent with every request.

setMaxDecodingMessageSize(limit:)​

func setMaxDecodingMessageSize(limit: UInt64)

Set the maximum size in bytes that a response message can be.

simulateTransaction(transaction:skipChecks:readMask:)​

func simulateTransaction(transaction: Transaction, skipChecks: Bool = false, readMask: [GrpcSimulateField]? = nil) async throws -> GrpcSimulatedTransaction

Simulate a transaction.

If skip_checks is true, the VM checks are skipped during the simulation.

The optional read_mask controls which fields the server returns.

simulateTransactions(transactions:readMask:)​

func simulateTransactions(transactions: [GrpcSimulateTransactionInput], readMask: [GrpcSimulateField]? = nil) async throws -> [GrpcSimulatedTransactionResult]

Simulate a batch of transactions.

An error the server reports for one transaction does not abort the rest of the batch; each result carries either the simulated transaction or the server's error message. A transaction the server returns but that cannot be decoded fails the whole call.

transactionBuilder(sender:)​

func transactionBuilder(sender: Address) -> GrpcTransactionBuilder

Create a new transaction builder with the given sender address, backed by this client.

transactions(digests:readMask:)​

func transactions(digests: [TransactionDigest], readMask: [GrpcTransactionField]? = nil) async throws -> GrpcExecutedTransactionResults

Get transactions by their digests.

Results are returned in the same order as the input digests, one per digest. A transaction the serving node cannot return — because it is not found or has been pruned — fails only its own item, which reading throws with the server's error message. A transaction the server returns but that cannot be decoded fails the whole call.

The optional read_mask controls which fields the server returns. If None, the transaction, signatures, checkpoint, and timestamp are returned.

viewFunctionCall(fqFunctionName:typeArgs:callArgs:readMask:)​

func viewFunctionCall(fqFunctionName: String, typeArgs: [TypeTag] = [], callArgs: [MoveViewArg] = [], readMask: [GrpcViewFunctionCallField]? = nil) async throws -> GrpcViewFunctionCallOutputs

Call a Move view function and read back what it returns, without submitting a transaction.

Only a function declared with the #[view] attribute can be called this way. fq_function_name is the fully qualified name <package>::<module>::<function>.

A call that ran and aborted is not an error: the abort is reported in the execution_error field of the outputs. The call fails only if the node refused to run it (unknown function, wrong argument count, not a view function).

The optional read_mask controls which fields the server returns.

viewFunctionCalls(functionCalls:readMask:)​

func viewFunctionCalls(functionCalls: [GrpcViewFunctionCallInput], readMask: [GrpcViewFunctionCallField]? = nil) async throws -> [GrpcViewFunctionCallResult]

Call a batch of Move view functions.

Each call runs in its own transaction on the server, so one call being rejected leaves the rest untouched. Results are returned in the same order as the input; each result carries either the outputs of the call or the error the node returned for it. A call that ran and aborted lands in outputs, with the abort in its execution_error field.

The optional read_mask controls which fields the server returns.

waitForTransaction(digest:waitFor:)​

func waitForTransaction(digest: TransactionDigest, waitFor: WaitForTransaction) async throws

Wait for the indexing (on the node) or finalization of a transaction by its digest, polling the node until then. Returns an error after 60s.

newDevnet()​

static func newDevnet() throws -> GrpcClient

Create a new gRPC client connected to the devnet gRPC server.

newLocalnet()​

static func newLocalnet() throws -> GrpcClient

Create a new gRPC client connected to a localnet gRPC server: http://localhost:50051.

newMainnet()​

static func newMainnet() throws -> GrpcClient

Create a new gRPC client connected to the mainnet gRPC server.

newTestnet()​

static func newTestnet() throws -> GrpcClient

Create a new gRPC client connected to the testnet gRPC server.