forked from iotaledger/iota-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update 'getting started' examples and link to them (iotaledger#1130)
* Update getting started started examples and link to them * Update wallet getting started * snake_case * Update sdk/examples/client/getting_started.rs Co-authored-by: Thibault Martinez <[email protected]> * consistency * Fix comment * Clean readmes --------- Co-authored-by: Thibault Martinez <[email protected]> Co-authored-by: Thibault Martinez <[email protected]>
- Loading branch information
1 parent
9f4fbbf
commit 007c417
Showing
10 changed files
with
152 additions
and
140 deletions.
There are no files selected for viewing
This file contains 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 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 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,23 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Client } from '@iota/sdk'; | ||
|
||
// Run with command: | ||
// yarn run-example ./client/getting-started.ts | ||
|
||
// In this example we will get information about the node | ||
async function run() { | ||
const client = new Client({ | ||
nodes: ['https://api.testnet.shimmer.network'], | ||
}); | ||
|
||
try { | ||
const nodeInfo = (await client.getInfo()).nodeInfo; | ||
console.log(nodeInfo); | ||
} catch (error) { | ||
console.error('Error: ', error); | ||
} | ||
} | ||
|
||
run().then(() => process.exit()); |
This file contains 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,60 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import { Wallet, CoinType, WalletOptions, Utils } from '@iota/sdk'; | ||
|
||
// Run with command: | ||
// yarn run-example ./wallet/getting-started.ts | ||
|
||
// The database path. | ||
const WALLET_DB_PATH = 'getting-started-db'; | ||
|
||
// A name to associate with the created account. | ||
const ACCOUNT_ALIAS = 'Alice'; | ||
|
||
// The node to connect to. | ||
const NODE_URL = 'https://api.testnet.shimmer.network'; | ||
|
||
// A password to encrypt the stored data. | ||
// WARNING: Never hardcode passwords in production code. | ||
const STRONGHOLD_PASSWORD = 'a-secure-password'; | ||
|
||
// The path to store the account snapshot. | ||
const STRONGHOLD_SNAPSHOT_PATH = 'vault.stronghold'; | ||
|
||
async function main() { | ||
const walletOptions: WalletOptions = { | ||
storagePath: WALLET_DB_PATH, | ||
clientOptions: { | ||
nodes: [NODE_URL], | ||
}, | ||
coinType: CoinType.Shimmer, | ||
secretManager: { | ||
stronghold: { | ||
snapshotPath: STRONGHOLD_SNAPSHOT_PATH, | ||
password: STRONGHOLD_PASSWORD, | ||
}, | ||
}, | ||
}; | ||
|
||
const wallet = new Wallet(walletOptions); | ||
|
||
// Generate a mnemonic and store its seed in the Stronghold vault. | ||
// INFO: It is best practice to back up the mnemonic somewhere secure. | ||
const mnemonic = Utils.generateMnemonic(); | ||
console.log('Mnemonic:' + mnemonic); | ||
await wallet.storeMnemonic(mnemonic); | ||
|
||
// Create an account. | ||
const account = await wallet.createAccount({ | ||
alias: ACCOUNT_ALIAS, | ||
}); | ||
|
||
// Get the first address and print it. | ||
const address = (await account.addresses())[0]; | ||
console.log(`Address: ${address.address}\n`); | ||
|
||
process.exit(0); | ||
} | ||
|
||
main(); |
This file contains 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 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,8 @@ | ||
from iota_sdk import Client | ||
|
||
# Create a Client instance | ||
client = Client(nodes=['https://api.testnet.shimmer.network']) | ||
|
||
# Get the node info | ||
node_info = client.get_info() | ||
print(f'{node_info}') |
This file contains 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 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 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,23 @@ | ||
// Copyright 2023 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//! This examples shows how to get the node info. | ||
//! | ||
//! ```sh | ||
//! cargo run --release --example client_getting_started | ||
//! ``` | ||
use iota_sdk::client::{Client, Result}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let client = Client::builder() | ||
.with_node("https://api.testnet.shimmer.network")? // Insert your node URL here | ||
.finish() | ||
.await?; | ||
|
||
let info = client.get_info().await?; | ||
println!("Node Info: {info:?}"); | ||
|
||
Ok(()) | ||
} |
This file contains 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