Skip to content
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

SDK - Import Code Examples for Getting Started Sections #1168

Merged
merged 2 commits into from
Sep 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 4 additions & 38 deletions docs/build/iota-sdk/1.0.0/docs/getting-started/nodejs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -121,50 +121,16 @@ Prebuild requires that the binary is in `build/Release` as though it was built w

After you [installed the library](#install-the-iota-sdk), you can create a `Client` instance and interface with it.

```javascript
const { Client, initLogger } = require('@iota/sdk');

async function run() {
initLogger();

const client = new Client({
nodes: ['https://api.testnet.shimmer.network'],
localPow: true,
});

try {
const nodeInfo = await client.getInfo();
console.log('Node info: ', nodeInfo);
} catch (error) {
console.error('Error: ', error);
}
}

run().then(() => process.exit());
```typescript reference
https://github.com/iotaledger/iota-sdk/blob/develop/bindings/nodejs/examples/client/getting-started.ts#L4-L23
```

### Wallet

After you [installed the library](#installing-the-iota-sdk), you can create a `Wallet` instance and interact with it.

```javascript
import { Wallet, CoinType, WalletOptions } from '@iota/sdk';

const walletOptions: WalletOptions = {
storagePath: `Alice`, // A name to associate with the created account.
clientOptions: {
nodes: ['https://api.testnet.shimmer.network'], // The node to connect to.
},
coinType: CoinType.Shimmer,
secretManager: {
// Setup Stronghold secret manager
stronghold: {
snapshotPath: 'vault.stronghold', // The path to store the account snapshot.
password: 'a-secure-password', // A password to encrypt the stored data. WARNING: Never hardcode passwords in production code.
},
},
};
const wallet = new Wallet(walletOptions);
```typescript reference
https://github.com/iotaledger/iota-sdk/blob/develop/bindings/nodejs/examples/wallet/getting-started.ts#L4-L60
```

## What's next?
Expand Down
32 changes: 4 additions & 28 deletions docs/build/iota-sdk/1.0.0/docs/getting-started/python.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -92,40 +92,16 @@ deactivate

After you [installed the library](#install-the-iota-sdk), you can create a `Client` instance and interface with it.

```python
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}')
```python reference
https://github.com/iotaledger/iota-sdk/blob/develop/bindings/python/examples/client/getting_started.py
```

### Wallet

After you [installed the library](#install-the-iota-sdk), you can create a `Wallet` instance and interact with it.

```python
from iota_sdk import Wallet, StrongholdSecretManager, CoinType

# This example creates a new database and account

wallet_options = {
'nodes': ['https://api.testnet.shimmer.network'],
}

secret_manager = StrongholdSecretManager("wallet.stronghold", "some_hopefully_secure_password")

wallet = Wallet('./alice-database', wallet_options, coin_type=CoinType.SHIMMER, secret_manager)

# Store the mnemonic in the Stronghold snapshot. This only needs to be done once
account = wallet.store_mnemonic("flame fever pig forward exact dash body idea link scrub tennis minute " +
"surge unaware prosper over waste kitten ceiling human knife arch situate civil")

account = wallet.create_account('Alice')
print(account)
```python reference
https://github.com/iotaledger/iota-sdk/blob/develop/bindings/python/examples/wallet/getting_started.py#L4-L48
```

## What's next?
Expand Down
60 changes: 4 additions & 56 deletions docs/build/iota-sdk/1.0.0/docs/getting-started/rust.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,69 +137,17 @@ iota-sdk = "1.0.0"

To use the Client module, you simply need to create a `Client`.

```rust
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(())
}
```rust reference
https://github.com/iotaledger/iota-sdk/blob/develop/sdk/examples/client/getting_started.rs#L10-L23
```

### Wallet

To use the Wallet module, you need to create a `Wallet`.
For this example to work `features = ["stronghold"]` is needed in the Cargo.toml import. To persist the wallet in a database, `"rocksdb"` can be added.

```rust
use iota_sdk::{
client::{
constants::SHIMMER_COIN_TYPE,
secret::{stronghold::StrongholdSecretManager, SecretManager},
},
wallet::{ClientOptions, Result, Wallet},
};

#[tokio::main]
async fn main() -> Result<()> {
// Setup Stronghold secret manager.
// WARNING: Never hardcode passwords in production code.
let secret_manager = StrongholdSecretManager::builder()
.password("password".to_owned()) // A password to encrypt the stored data.
.build("vault.stronghold")?; // The path to store the account snapshot.

let client_options = ClientOptions::new().with_node("https://api.testnet.shimmer.network")?;

// Set up and store the wallet.
let wallet = Wallet::builder()
.with_secret_manager(SecretManager::Stronghold(secret_manager))
.with_client_options(client_options)
.with_coin_type(SHIMMER_COIN_TYPE)
.finish()
.await?;

// Generate a mnemonic and store it in the Stronghold vault.
// INFO: It is best practice to back up the mnemonic somewhere secure.
let mnemonic = wallet.generate_mnemonic()?;
wallet.store_mnemonic(mnemonic).await?;

// Create an account.
let account = wallet
.create_account()
.with_alias("Alice") // A name to associate with the created account.
.finish()
.await?;

Ok(())
}
```rust reference
https://github.com/iotaledger/iota-sdk/blob/develop/sdk/examples/wallet/getting_started.rs#L12-L56
```

## What's next?
Expand Down
42 changes: 4 additions & 38 deletions docs/build/iota-sdk/1.0.0/docs/getting-started/wasm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -147,50 +147,16 @@ A bundler such as [webpack](https://webpack.js.org/) or [rollup](https://rollupj

After you [installed the library](#install-the-iota-sdk), you can create a `Client` instance and interface with it.

```javascript
const { Client, initLogger } = require('@iota/sdk');

async function run() {
initLogger();

const client = new Client({
nodes: ['https://api.testnet.shimmer.network'],
localPow: true,
});

try {
const nodeInfo = await client.getInfo();
console.log('Node info: ', nodeInfo);
} catch (error) {
console.error('Error: ', error);
}
}

run().then(() => process.exit());
```typescript reference
https://github.com/iotaledger/iota-sdk/blob/develop/bindings/nodejs/examples/client/getting-started.ts#L4-L23
```

### Wallet

After you [installed the library](#installing-the-iota-sdk), you can create a `Wallet` instance and interact with it.

```javascript
import { Wallet, CoinType, WalletOptions } from '@iota/sdk';

const walletOptions: WalletOptions = {
storagePath: `Alice`, // A name to associate with the created account.
clientOptions: {
nodes: ['https://api.testnet.shimmer.network'], // The node to connect to.
},
coinType: CoinType.Shimmer,
secretManager: {
// Setup Stronghold secret manager
stronghold: {
snapshotPath: 'vault.stronghold', // The path to store the account snapshot.
password: 'a-secure-password', // A password to encrypt the stored data. WARNING: Never hardcode passwords in production code.
},
},
};
const wallet = new Wallet(walletOptions);
```typescript reference
https://github.com/iotaledger/iota-sdk/blob/develop/bindings/nodejs/examples/wallet/getting-started.ts#L4-L60
```

### Web Usage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ This operation cannot be reverted.

- `s` (`uint32`): The serial number of the foundry.


### `mintNFT(I ImmutableData, a AgentID, C CollectionID, w WithdrawOnMint)`

Mints an NFT with ImmutableData `I` that will be owned by the AgentID `a`.
Expand All @@ -144,8 +143,6 @@ The mint can be done directly to any L1 address (it is not necessary for the tar

- `D` (`MintID`): the internal ID of the NFT at the time of minting that can be used by users/contracts to obtain the resulting NFTID on the next block



---

## Views
Expand Down Expand Up @@ -307,7 +304,6 @@ Returns the NFTID `z` for a given MintID `D`.

- `z` (`NFTID`): The ID of the NFT


### `getAccountNonce(a AgentID)`

Returns the current account nonce for a give AgentID `a`.
Expand Down Expand Up @@ -335,7 +331,6 @@ FoundrySerialNumber = uint32
TokenID = [38]byte
```


### `NFTID`

```
Expand All @@ -348,8 +343,6 @@ NFTID = [32]byte
MintID = [6]byte
```



### `NFTData`

`NFTData` is encoded as the concatenation of:
Expand Down