diff --git a/bindings/go/examples/example/main.go b/bindings/go/examples/coin_balances/main.go similarity index 60% rename from bindings/go/examples/example/main.go rename to bindings/go/examples/coin_balances/main.go index a861af49d..8951ced00 100644 --- a/bindings/go/examples/example/main.go +++ b/bindings/go/examples/coin_balances/main.go @@ -24,7 +24,7 @@ func main() { } for _, coin := range coins.Data { - fmt.Printf("ID = 0x%s Balance = %d\n", coin.Id().ToHex(), coin.Balance()) + fmt.Printf("Coin = 0x%s Balance = %d\n", coin.Id().ToHex(), coin.Balance()) } balance, err := client.Balance(address, nil) @@ -32,20 +32,4 @@ func main() { log.Fatalf("Failed to get balance: %v", err) } fmt.Printf("Total Balance = %d\n", *balance) - - atCheckpoint := uint64(3) - inputObject, err := sdk.ObjectIdFromHex("0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f") - if err != nil { - log.Fatalf("Failed to parse object ID: %v", err) - } - txFilter := sdk.TransactionsFilter{ - AtCheckpoint: &atCheckpoint, - InputObject: &inputObject, - } - eventFilter := sdk.EventFilter{ - Sender: &address, - } - - _ = txFilter - _ = eventFilter } diff --git a/bindings/kotlin/examples/CoinBalances.kt b/bindings/kotlin/examples/CoinBalances.kt new file mode 100644 index 000000000..dc091a988 --- /dev/null +++ b/bindings/kotlin/examples/CoinBalances.kt @@ -0,0 +1,26 @@ +// Copyright (c) 2025 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +import iota_sdk.Address +import iota_sdk.GraphQlClient +import kotlinx.coroutines.runBlocking + +fun main() = runBlocking { + try { + val client = GraphQlClient.newDevnet() + val address = + Address.fromHex( + "0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f", + ) + + val coins = client.coins(address) + for (coin in coins.data) { + println("Coin = 0x${coin.id().toHex()} Balance = ${coin.balance()}") + } + + val balance = client.balance(address) + println("Total Balance = $balance") + } catch (e: Exception) { + e.printStackTrace() + } +} diff --git a/bindings/kotlin/examples/GetObject.kt b/bindings/kotlin/examples/GetObject.kt index 37db35dbb..721538aee 100644 --- a/bindings/kotlin/examples/GetObject.kt +++ b/bindings/kotlin/examples/GetObject.kt @@ -7,6 +7,7 @@ import kotlinx.coroutines.runBlocking fun main() = runBlocking { try { + val client = GraphQlClient.newDevnet() val objectId = diff --git a/bindings/python/examples/chain_id.py b/bindings/python/examples/chain_id.py index e015ac5a7..f5c81dbce 100644 --- a/bindings/python/examples/chain_id.py +++ b/bindings/python/examples/chain_id.py @@ -8,9 +8,10 @@ async def main(): client = GraphQlClient.new_devnet() - + chain_id = await client.chain_id() print("Chain ID:", chain_id) + if __name__ == "__main__": asyncio.run(main()) diff --git a/bindings/python/examples/coin_balances.py b/bindings/python/examples/coin_balances.py new file mode 100644 index 000000000..59300598a --- /dev/null +++ b/bindings/python/examples/coin_balances.py @@ -0,0 +1,24 @@ +# 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( + "0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f" + ) + + coins = await client.coins(address) + for coin in coins.data: + print(f"Coin = {coin.id().to_hex()} Balance = {coin.balance()}") + + balance = await client.balance(address) + print(f"Total Balance = {balance}") + + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/bindings/python/examples/epoch.py b/bindings/python/examples/epoch.py index 66b9de278..79ff6f44b 100644 --- a/bindings/python/examples/epoch.py +++ b/bindings/python/examples/epoch.py @@ -1,16 +1,17 @@ # Copyright (c) 2025 IOTA Stiftung # SPDX-License-Identifier: Apache-2.0 -import asyncio from lib.iota_sdk_ffi import GraphQlClient +import asyncio + async def main(): try: client = GraphQlClient.new_devnet() # Get current epoch - current_epoch = await client.epoch(None) + current_epoch = await client.epoch() if current_epoch is None: print("Current epoch is None") return diff --git a/bindings/python/examples/example.py b/bindings/python/examples/example.py deleted file mode 100644 index 38a7e84f0..000000000 --- a/bindings/python/examples/example.py +++ /dev/null @@ -1,131 +0,0 @@ -from lib.iota_sdk_ffi import * - -import asyncio - - -async def main(): - client = GraphQlClient.new_devnet() - - my_address = Address.from_hex( - "0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f" - ) - - coins = await client.coins(my_address) - for coin in coins.data: - print(f"ID = {coin.id().to_hex()} Balance = {coin.balance()}") - - balance = await client.balance(my_address) - - print(f"Total Balance = {balance}") - - filter = TransactionsFilter( - at_checkpoint=3, - input_object=ObjectId.from_hex( - "0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f" - ), - ) - - filter = EventFilter(sender=my_address) - - txn = await client.transaction( - Digest.from_base58("HT1wvebXV4LUisLa4aJQEyoxt1HEMqznjf5UtStmdxyM") - ) - - if txn is not None: - for sig in txn.signatures: - print("Scheme: ", sig.scheme(), sig.scheme().value) - print("Sender: ", txn.transaction.sender().to_hex()) - - service_config = ServiceConfig( - default_page_size=2, - enabled_features=[], - max_move_value_depth=0, - max_output_nodes=0, - max_page_size=0, - max_query_depth=0, - max_query_nodes=0, - max_query_payload_size=0, - max_type_argument_depth=0, - max_type_argument_width=0, - max_type_nodes=0, - mutation_timeout_ms=0, - request_timeout_ms=0, - ) - - coin_metadata = CoinMetadata( - address=ObjectId.from_hex( - "0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f" - ), - decimals=2, - description="test", - icon_url=None, - name="test", - symbol=None, - supply="1000", - version=0, - ) - - move_struct = MoveStruct( - struct_type=StructTag.coin(TypeTag.new_vector(TypeTag.new_u8())), - version=1, - contents=bytes(), - ) - - id = ObjectId.from_hex( - "0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f" - ) - type_origin = TypeOrigin( - module_name=Identifier("module_name"), - struct_name=Identifier("struct_name"), - package=id, - ) - upgrade_info = UpgradeInfo(upgraded_id=id, upgraded_version=43) - move_package = MovePackage( - id, - version=42, - modules={Identifier("some_id"): bytes.fromhex("48656c6c6f")}, - type_origin_table=[type_origin], - linkage_table={id: upgrade_info}, - ) - - builder = TransactionBuilder() - framework_addr = Address.from_hex( - "0x0000000000000000000000000000000000000000000000000000000000000002" - ) - builder.move_call( - Function( - package=framework_addr, - module=Identifier("coin"), - function=Identifier("value"), - type_args=[ - TypeTag.new_struct( - StructTag( - framework_addr, Identifier("iota"), Identifier("IOTA"), [] - ) - ) - ], - ), - [Argument.new_input(0)], - ) - builder.set_sender(my_address) - builder.set_gas_budget(50000000) - builder.set_gas_price(await client.reference_gas_price() or 100) - coin_0 = await client.object(coins.data[0].id()) - if coin_0 is None: - raise InternalError - coin_1 = await client.object(coins.data[1].id()) - if coin_1 is None: - raise InternalError - builder.input(UnresolvedInput.from_object(coin_0).with_owned_kind()) - builder.add_gas_objects([UnresolvedInput.from_object(coin_1).with_owned_kind()]) - txn = builder.finish() - - res = await client.dry_run_tx(txn) - if res.error is not None: - print(res.error) - elif res.effects is not None: - print(res.effects.as_v1()) - - -if __name__ == "__main__": - asyncio.run(main()) diff --git a/bindings/python/examples/transactions_with_shared.py b/bindings/python/examples/transactions_with_shared.py index 111678075..ecb406223 100644 --- a/bindings/python/examples/transactions_with_shared.py +++ b/bindings/python/examples/transactions_with_shared.py @@ -1,9 +1,10 @@ # Copyright (c) 2025 IOTA Stiftung # SPDX-License-Identifier: Apache-2.0 -import asyncio from lib.iota_sdk_ffi import * +import asyncio + async def main(): try: diff --git a/crates/iota-graphql-client/examples/coin_balances.rs b/crates/iota-graphql-client/examples/coin_balances.rs new file mode 100644 index 000000000..f2396a88c --- /dev/null +++ b/crates/iota-graphql-client/examples/coin_balances.rs @@ -0,0 +1,23 @@ +// Copyright (c) 2025 IOTA Stiftung +// SPDX-License-Identifier: Apache-2.0 + +use iota_graphql_client::{Client, error::Result}; + +#[tokio::main] +async fn main() -> Result<()> { + let client = Client::new_devnet(); + let address = "0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f".parse()?; + + for coin in client + .coins(address, None, Default::default()) + .await? + .data() + { + println!("Coin = {}, Balance = {}", coin.id(), coin.balance()); + } + + let balance = client.balance(address, None).await?.unwrap_or_default(); + println!("Total balance = {balance}"); + + Ok(()) +}