diff --git a/bindings/go/examples/owned_objects/main.go b/bindings/go/examples/owned_objects/main.go new file mode 100644 index 000000000..b728e0d4f --- /dev/null +++ b/bindings/go/examples/owned_objects/main.go @@ -0,0 +1,36 @@ +// 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() + + address, err := sdk.AddressFromHex("0x0") + if err != nil { + log.Fatalf("Failed to parse address: %v", err) + } + + objectFilter := sdk.ObjectFilter{ + Owner: &address, + } + paginationFilter := sdk.PaginationFilter{ + Direction: sdk.DirectionForward, + } + + objectsPage, err := client.Objects(&objectFilter, &paginationFilter) + if err.(*sdk.SdkFfiError) != nil { + log.Fatalf("Failed to get owned objects: %v", err) + } + fmt.Printf("Owned objects (%d):\n", len(objectsPage.Data)) + for _, obj := range objectsPage.Data { + fmt.Println(obj.ObjectId().ToHex()) + } +} diff --git a/bindings/kotlin/examples/OwnedObjects.kt b/bindings/kotlin/examples/OwnedObjects.kt new file mode 100644 index 000000000..c3a50c5b4 --- /dev/null +++ b/bindings/kotlin/examples/OwnedObjects.kt @@ -0,0 +1,22 @@ +// Copyright (c) 2025 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import iota_sdk.Address +import iota_sdk.GraphQlClient +import iota_sdk.ObjectFilter +import kotlinx.coroutines.runBlocking + +fun main() = runBlocking { + try { + val client = GraphQlClient.newDevnet() + val address = Address.fromHex("0x0") + val objectFilter = ObjectFilter(owner = address) + val objectsPage = client.objects(objectFilter) + println("Owned objects (${objectsPage.data.size}):") + for (obj in objectsPage.data) { + println(obj.objectId().toHex()) + } + } catch (e: Exception) { + e.printStackTrace() + } +} diff --git a/bindings/python/examples/owned_objects.py b/bindings/python/examples/owned_objects.py new file mode 100644 index 000000000..74d2dc404 --- /dev/null +++ b/bindings/python/examples/owned_objects.py @@ -0,0 +1,18 @@ +# Copyright (c) 2025 IOTA Stiftung +# SPDX-License-Identifier: Apache-2.0 + +from lib.iota_sdk_ffi import * +import asyncio + +async def main(): + client = GraphQlClient.new_devnet() + address = Address.from_hex("0x0") + objects_page = await client.objects( + ObjectFilter(owner=address) + ) + print(f"Owned objects({len(objects_page.data)}):") + for obj in objects_page.data: + print(obj.object_id().to_hex()) + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/crates/iota-graphql-client/examples/owned_objects.rs b/crates/iota-graphql-client/examples/owned_objects.rs new file mode 100644 index 000000000..8e7725202 --- /dev/null +++ b/crates/iota-graphql-client/examples/owned_objects.rs @@ -0,0 +1,28 @@ +// Copyright (c) 2025 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use anyhow::Result; +use iota_graphql_client::{Client, pagination::PaginationFilter, query_types::ObjectFilter}; +use iota_types::Address; + +#[tokio::main] +async fn main() -> Result<()> { + let client = Client::new_devnet(); + + let address = Address::from_hex("0x0")?; + let owned_objects_page = client + .objects( + Some(ObjectFilter { + owner: Some(address), + ..Default::default() + }), + PaginationFilter::default(), + ) + .await?; + println!("Owned objects ({}):", owned_objects_page.data.len()); + for obj in owned_objects_page.data { + println!("{}", obj.object_id()); + } + + Ok(()) +}