Skip to main content

GrpcClient

GrpcClient Objects​

class GrpcClient(GrpcClientProtocol)

The gRPC client for interacting with the IOTA blockchain.

new_devnet​

@classmethod
def new_devnet(cls) -> GrpcClient

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

new_localnet​

@classmethod
def new_localnet(cls) -> GrpcClient

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

new_mainnet​

@classmethod
def new_mainnet(cls) -> GrpcClient

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

new_testnet​

@classmethod
def new_testnet(cls) -> GrpcClient

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

all_coins​

async def all_coins(
owner: Address,
coin_type: typing.Union[object, typing.Optional[StructTag]] = _DEFAULT,
limit: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> typing.List[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.

all_dynamic_fields​

async def all_dynamic_fields(
parent: ObjectId,
limit: typing.Union[object, typing.Optional[int]] = _DEFAULT,
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcDynamicFieldField]]] = _DEFAULT
) -> typing.List[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.

all_owned_objects​

async def all_owned_objects(
owner: Address,
object_type: typing.Union[object, typing.Optional[StructTag]] = _DEFAULT,
limit: typing.Union[object, typing.Optional[int]] = _DEFAULT,
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcOwnedObjectField]]] = _DEFAULT
) -> typing.List[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.

all_package_versions​

async def all_package_versions(
package_id: ObjectId,
limit: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> typing.List[GrpcPackageVersion]

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

checkpoint_by_digest​

async def checkpoint_by_digest(
digest: CheckpointDigest,
transactions_filter: typing.Union[
object, typing.Optional[GrpcTransactionFilter]] = _DEFAULT,
events_filter: typing.Union[object,
typing.Optional[GrpcEventFilter]] = _DEFAULT,
read_mask: typing.Union[
object,
typing.Optional[typing.List[GrpcCheckpointResponseField]]] = _DEFAULT
) -> 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.

checkpoint_by_sequence_number​

async def checkpoint_by_sequence_number(
sequence_number: int,
transactions_filter: typing.Union[
object, typing.Optional[GrpcTransactionFilter]] = _DEFAULT,
events_filter: typing.Union[object,
typing.Optional[GrpcEventFilter]] = _DEFAULT,
read_mask: typing.Union[
object,
typing.Optional[typing.List[GrpcCheckpointResponseField]]] = _DEFAULT
) -> 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.

checkpoint_latest​

async def checkpoint_latest(
transactions_filter: typing.Union[
object, typing.Optional[GrpcTransactionFilter]] = _DEFAULT,
events_filter: typing.Union[object,
typing.Optional[GrpcEventFilter]] = _DEFAULT,
read_mask: typing.Union[
object,
typing.Optional[typing.List[GrpcCheckpointResponseField]]] = _DEFAULT
) -> 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.

checkpoints_stream​

async def checkpoints_stream(
start_sequence_number: typing.Union[object,
typing.Optional[int]] = _DEFAULT,
end_sequence_number: typing.Union[object, typing.Optional[int]] = _DEFAULT,
transactions_filter: typing.Union[
object, typing.Optional[GrpcTransactionFilter]] = _DEFAULT,
events_filter: typing.Union[object,
typing.Optional[GrpcEventFilter]] = _DEFAULT,
read_mask: typing.Union[
object,
typing.Optional[typing.List[GrpcCheckpointResponseField]]] = _DEFAULT
) -> 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.

checkpoints_stream_filtered​

async def checkpoints_stream_filtered(
start_sequence_number: typing.Union[object,
typing.Optional[int]] = _DEFAULT,
end_sequence_number: typing.Union[object, typing.Optional[int]] = _DEFAULT,
transactions_filter: typing.Union[
object, typing.Optional[GrpcTransactionFilter]] = _DEFAULT,
events_filter: typing.Union[object,
typing.Optional[GrpcEventFilter]] = _DEFAULT,
progress_interval_ms: typing.Union[object,
typing.Optional[int]] = _DEFAULT,
read_mask: typing.Union[
object,
typing.Optional[typing.List[GrpcCheckpointResponseField]]] = _DEFAULT
) -> 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.

coin_info​

async def coin_info(coin_type: StructTag) -> 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​

async def coins(
owner: Address,
coin_type: typing.Union[object, typing.Optional[StructTag]] = _DEFAULT,
page_size: typing.Union[object, typing.Optional[int]] = _DEFAULT,
page_token: typing.Union[object, typing.Optional[bytes]] = _DEFAULT
) -> 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.

dynamic_fields​

async def dynamic_fields(
parent: ObjectId,
page_size: typing.Union[object, typing.Optional[int]] = _DEFAULT,
page_token: typing.Union[object, typing.Optional[bytes]] = _DEFAULT,
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcDynamicFieldField]]] = _DEFAULT
) -> 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​

async def epoch(
epoch: typing.Union[object, typing.Optional[int]] = _DEFAULT,
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcEpochField]]] = _DEFAULT
) -> 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.

execute_transaction​

async def execute_transaction(
signed_transaction: SignedTransaction,
checkpoint_inclusion_timeout_ms: typing.Union[
object, typing.Optional[int]] = _DEFAULT,
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcTransactionField]]] = _DEFAULT
) -> 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.

execute_transactions​

async def execute_transactions(
transactions: typing.List[SignedTransaction],
checkpoint_inclusion_timeout_ms: typing.Union[
object, typing.Optional[int]] = _DEFAULT,
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcTransactionField]]] = _DEFAULT
) -> 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​

async def health(
threshold_ms: typing.Union[object, typing.Optional[int]] = _DEFAULT
) -> 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​

async def objects(
object_ids: typing.List[ObjectId],
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcObjectField]]] = _DEFAULT
) -> 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.

objects_with_versions​

async def objects_with_versions(
requests: typing.List[GrpcObjectRequest],
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcObjectField]]] = _DEFAULT
) -> 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.

owned_objects​

async def owned_objects(
owner: Address,
object_type: typing.Union[object, typing.Optional[StructTag]] = _DEFAULT,
page_size: typing.Union[object, typing.Optional[int]] = _DEFAULT,
page_token: typing.Union[object, typing.Optional[bytes]] = _DEFAULT,
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcOwnedObjectField]]] = _DEFAULT
) -> 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.

package_versions​

async def package_versions(
package_id: ObjectId,
page_size: typing.Union[object, typing.Optional[int]] = _DEFAULT,
page_token: typing.Union[object, typing.Optional[bytes]] = _DEFAULT
) -> GrpcPackageVersionPage

List a single page of versions of a Move package.

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

reference_gas_price​

async def reference_gas_price() -> int

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

service_info​

async def service_info(
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcServiceInfoField]]] = _DEFAULT
) -> GrpcServiceInfo

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

The optional read_mask controls which fields the server returns.

set_basic_auth​

def set_basic_auth(username: str, password: typing.Optional[str]) -> None

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

set_bearer_auth​

def set_bearer_auth(token: str) -> None

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

set_max_decoding_message_size​

def set_max_decoding_message_size(limit: int) -> None

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

simulate_transaction​

async def simulate_transaction(
transaction: Transaction,
skip_checks: bool = False,
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcSimulateField]]] = _DEFAULT
) -> 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.

simulate_transactions​

async def simulate_transactions(
transactions: typing.List[GrpcSimulateTransactionInput],
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcSimulateField]]] = _DEFAULT
) -> typing.List[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.

transaction_builder​

def transaction_builder(sender: Address) -> GrpcTransactionBuilder

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

transactions​

async def transactions(
digests: typing.List[TransactionDigest],
read_mask: typing.Union[
object, typing.Optional[typing.List[GrpcTransactionField]]] = _DEFAULT
) -> 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.

view_function_call​

async def view_function_call(
fq_function_name: str,
type_args: typing.Union[object, typing.List[TypeTag]] = _DEFAULT,
call_args: typing.Union[object, typing.List[MoveViewArg]] = _DEFAULT,
read_mask: typing.Union[
object,
typing.Optional[typing.List[GrpcViewFunctionCallField]]] = _DEFAULT
) -> 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.

view_function_calls​

async def view_function_calls(
function_calls: typing.List[GrpcViewFunctionCallInput],
read_mask: typing.Union[
object,
typing.Optional[typing.List[GrpcViewFunctionCallField]]] = _DEFAULT
) -> typing.List[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.

wait_for_transaction​

async def wait_for_transaction(digest: TransactionDigest,
wait_for: WaitForTransaction) -> None

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.