diff --git a/bindings/go/examples/objects_by_type/main.go b/bindings/go/examples/objects_by_type/main.go new file mode 100644 index 000000000..d23c3a83c --- /dev/null +++ b/bindings/go/examples/objects_by_type/main.go @@ -0,0 +1,30 @@ +// Copyright (c) 2025 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +package main + +import ( + "fmt" + "log" + + sdk "bindings/iota_sdk_ffi" +) + +func main() { + client := sdk.GraphQlClientNewDevnet() + + stakedIotaType := "0x3::staking_pool::StakedIota" + stakedIotas, err := client.Objects(&sdk.ObjectFilter{TypeTag: &stakedIotaType}, nil) + if err.(*sdk.SdkFfiError) != nil { + log.Fatalf("Failed to get staked iota: %v", err) + } + + if len(stakedIotas.Data) == 0 { + fmt.Println("No StakedIota objects found") + } else { + fmt.Println("StakedIota object IDs:") + for _, stakedIota := range stakedIotas.Data { + fmt.Printf("%s\n", stakedIota.ObjectId().ToHex()) + } + } +} diff --git a/bindings/kotlin/examples/ObjectsByType.kt b/bindings/kotlin/examples/ObjectsByType.kt new file mode 100644 index 000000000..d513a4764 --- /dev/null +++ b/bindings/kotlin/examples/ObjectsByType.kt @@ -0,0 +1,25 @@ +// Copyright (c) 2025 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import iota_sdk.GraphQlClient +import iota_sdk.ObjectFilter +import kotlinx.coroutines.runBlocking + +fun main() = runBlocking { + try { + val client = GraphQlClient.newDevnet() + + val stakedIotas = client.objects(ObjectFilter(typeTag = "0x3::staking_pool::StakedIota")) + + if (stakedIotas.data.isEmpty()) { + println("No StakedIota objects found") + } else { + println("StakedIota object IDs:") + for (stakedIota in stakedIotas.data) { + println(stakedIota.objectId().toHex()) + } + } + } catch (e: Exception) { + e.printStackTrace() + } +} diff --git a/bindings/python/examples/objects_by_type.py b/bindings/python/examples/objects_by_type.py new file mode 100644 index 000000000..ee5d98e9c --- /dev/null +++ b/bindings/python/examples/objects_by_type.py @@ -0,0 +1,28 @@ +# Copyright (c) 2025 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 + +import asyncio +from lib.iota_sdk_ffi import * + + +async def main(): + try: + client = GraphQlClient.new_devnet() + + staked_iotas = await client.objects( + filter=ObjectFilter(type_tag="0x3::staking_pool::StakedIota") + ) + + if len(staked_iotas.data) == 0: + print("No StakedIota objects found") + else: + print("StakedIota object IDs:") + for staked_iota in staked_iotas.data: + print(staked_iota.object_id().to_hex()) + + except Exception as e: + print(f"Error: {e}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/crates/iota-graphql-client/examples/objects_by_type.rs b/crates/iota-graphql-client/examples/objects_by_type.rs new file mode 100644 index 000000000..1d91c9ba9 --- /dev/null +++ b/crates/iota-graphql-client/examples/objects_by_type.rs @@ -0,0 +1,30 @@ +// Copyright (c) 2025 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use iota_graphql_client::{Client, error::Result, query_types::ObjectFilter}; + +#[tokio::main] +async fn main() -> Result<()> { + let client = Client::new_devnet(); + + let staked_iotas = client + .objects( + ObjectFilter { + type_: "0x3::staking_pool::StakedIota".to_owned().into(), + ..Default::default() + }, + Default::default(), + ) + .await?; + + if staked_iotas.data.is_empty() { + println!("No StakedIota objects found"); + } else { + println!("StakedIota object IDs:"); + for staked_iota in staked_iotas.data { + println!("{}", staked_iota.object_id()); + } + } + + Ok(()) +}