feat: add IOTA Names example in Rust and all bindings#990
feat: add IOTA Names example in Rust and all bindings#990EasonC13 wants to merge 5 commits intoiotaledger:developfrom
Conversation
Add comprehensive IOTA Names example demonstrating: 1. Name lookup (name -> address) using resolve_address 2. Reverse lookup (address -> name) 3. Name record details (expiration timestamp, target address) 4. Check name existence (has_record) All operations use dev_inspect (dry run) so no gas or signing is needed. Examples added for: - Rust: crates/iota-sdk/examples/iota_names.rs - Python: bindings/python/examples/iota_names.py - Kotlin: bindings/kotlin/examples/IotaNames.kt - Go: bindings/go/examples/iota_names/main.go - Swift: bindings/swift/examples/iota_names.swift Closes iotaledger#514
- Add IotaNamesConfig for devnet/mainnet addresses - Support CLI args: cargo run --example iota_names -- <name> <network> - Handle names with no target address set (Option::None) - Tested on devnet (name.iota) and mainnet (giverep.iota)
- Add mainnet IOTA Names config (package + object addresses) to all 5 languages - Add CLI args support (name, network) to Python, Kotlin, Go, Swift - Fix name_record_details to check existence before querying (prevents option::borrow abort) - Tested on devnet and mainnet for Rust, Python, Swift, Kotlin, Go
| let name = args.get(1).map(|s| s.as_str()).unwrap_or("name.iota"); | ||
| let network = args.get(2).map(|s| s.as_str()).unwrap_or("devnet"); | ||
|
|
||
| let (client, config) = match network { | ||
| "mainnet" => (Client::new_mainnet(), IotaNamesConfig::mainnet()?), | ||
| _ => (Client::new_devnet(), IotaNamesConfig::devnet()?), | ||
| }; |
There was a problem hiding this comment.
I would just use testnet here, no need to make the examples more complicated with multiple networks and the devnet will be reset next week
Also right now the example only does read operations, there should be also examples (dry run) for how to register a name, register a subname, extend the expiration, set metadata (might make sense to have these in another file to not make this one too big)
Also the copyright year in the files should be 2026
thibault-martinez
left a comment
There was a problem hiding this comment.
We have merged C# since you opened the PR, would you mind adding an example for it? Otherwise we will do it.
|
Let me look into it. |
Add IotaNames example for C# bindings with all 4 operations: 1. Name lookup (name -> address) 2. Reverse lookup (address -> name) 3. Name record details (expiration timestamp, target address) 4. Check name existence (has_record) Includes devnet/mainnet config and CLI args support. Matches the pattern of existing Rust, Python, Kotlin, Go, Swift examples.
|
@thibault-martinez done, please check. |
| } | ||
|
|
||
| impl IotaNamesConfig { | ||
| fn devnet() -> Result<Self> { |
There was a problem hiding this comment.
These are available in the library via IotaNamesConfig
| let obj = config.object_id; | ||
| let sender = Address::from_str("0x0")?; | ||
|
|
||
| let mut builder = TransactionBuilder::new(sender).with_client(client.clone()); |
There was a problem hiding this comment.
| let mut builder = TransactionBuilder::new(sender).with_client(client.clone()); | |
| let mut builder = TransactionBuilder::new(sender).with_client(client); |
There was a problem hiding this comment.
These fetches may be better as dynamic field queries rather than dry runs. This is how it's done in the CLI for instance. We could use the client's dynamic_field fn like so:
let entry: RegistryEntry = bcs::deserialize(&client.dynamic_field(IotaNamesConfig::testnet().registry_id.into(), TypeTag::new_name(), Name::from_str(name)?)).await?)?;
let target_address = entry.name_record.target_address;
Summary
Closes #514
Add a comprehensive IOTA Names example demonstrating all major operations, implemented in Rust and all bindings (Python, Kotlin, Go, Swift).
What's included
New files:
crates/iota-sdk/examples/iota_names.rsbindings/python/examples/iota_names.pybindings/kotlin/examples/IotaNames.ktbindings/go/examples/iota_names/main.gobindings/swift/examples/iota_names.swift4 operations demonstrated:
name.iota) to an addressAll operations use
dev_inspect(dry run), so no gas or signing is needed.Network support:
cargo run --example iota_names -- name.iota mainnetname.iotaTesting
All 5 languages tested on both devnet and mainnet:
Sample output (Rust, devnet):