-
Notifications
You must be signed in to change notification settings - Fork 3
chore(examples): Add examples to show coin balances and total balance per address #191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 8 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
20e2872
add python example
Alex6323 416f843
add kotlin example
Alex6323 113a801
add go example
Alex6323 06195f6
add rs example
Alex6323 027d71c
rename files
Alex6323 670bb25
clean up
Alex6323 f282e76
coin
Alex6323 28c5939
Merge branch 'sdk-bindings' into chore/get-coin-balances-example
Alex6323 fb04991
review
Alex6323 0d9c303
reformat kotlin files
Alex6323 2b46969
Merge branch 'sdk-bindings' into chore/get-coin-balances-example
Alex6323 f509e91
remove unused import
Alex6323 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| // Copyright (c) 2025 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package main | ||
|
|
||
| import ( | ||
| "fmt" | ||
| "log" | ||
|
|
||
| sdk "bindings/iota_sdk_ffi" | ||
| ) | ||
|
|
||
| func isNilError(err error) bool { | ||
| if sdkErr, ok := err.(*sdk.SdkFfiError); ok { | ||
| return sdkErr == nil | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| func main() { | ||
| client := sdk.GraphQlClientNewDevnet() | ||
|
|
||
| address, err := sdk.AddressFromHex("0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f") | ||
| if err != nil { | ||
| log.Fatalf("Failed to parse address: %v", err) | ||
| } | ||
|
|
||
| coins, err := client.Coins(address, nil, nil) | ||
| if !isNilError(err) { | ||
| log.Fatalf("Failed to get coins: %v", err) | ||
| } | ||
|
|
||
| for _, coin := range coins.Data { | ||
| fmt.Printf("Coin = 0x%s Balance = %d\n", coin.Id().ToHex(), coin.Balance()) | ||
| } | ||
|
|
||
| balance, err := client.Balance(address, nil) | ||
| if !isNilError(err) { | ||
| log.Fatalf("Failed to get balance: %v", err) | ||
| } | ||
| fmt.Printf("Total Balance = %d\n", *balance) | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
DaughterOfMars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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() | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) 2025 IOTA Stiftung | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| use iota_graphql_client::{ | ||
| Client, | ||
| error::Result, | ||
| pagination::{Direction, PaginationFilter}, | ||
| }; | ||
|
|
||
| #[tokio::main] | ||
| async fn main() -> Result<()> { | ||
| let client = Client::new_devnet(); | ||
| let address = "0xb14f13f5343641e5b52d144fd6f106a7058efe2f1ad44598df5cda73acf0101f".parse()?; | ||
| let (_, coins) = client | ||
| .coins( | ||
| address, | ||
| None, | ||
| PaginationFilter { | ||
| direction: Direction::Forward, | ||
| ..Default::default() | ||
| }, | ||
DaughterOfMars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ) | ||
| .await? | ||
| .into_parts(); | ||
DaughterOfMars marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| for coin in &coins { | ||
| println!("Coin = {}, Balance = {}", coin.id(), coin.balance()); | ||
| } | ||
|
|
||
| let balance = client.balance(address, None).await?.unwrap_or_default(); | ||
| println!("Total balance = {balance}"); | ||
|
|
||
| Ok(()) | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.