Soroban Snippets: Basic of Building Dapp Part 2
Tags: stellar, soroban, javascript, web3
Published: 2023-12-13 09:34:09

# Validating Stellar/Soroban Information

In this section, we will explore straightforward validation methods available in the Soroban SDK, specifically designed to authenticate and validate public keys, secret keys, and contract IDs. These methods serve as essential tools to ensure the authenticity and validity of inputs in various contexts within your decentralized application (dApp). Whether validating a public key for an `Address` or confirming its suitability for a `xdr.ScVal` object, these techniques establish a robust foundation for data integrity, empowering your dApp with reliable and secure information handling.

[Validating Stellar/Soroban Information](https://soroban-snippet.vercel.app/?title=0adc6dfb0b29f3ab2991d2700e54fcc6e74333c8d2bdf8e6c9b4f8b0ee4821c0)

# Emitting and Retrieving Events
  
The provided React component appears to be a part of a larger project that involves emitting and retrieving events using Soroban on the Stellar network. The code snippet focuses on showcasing the process of emitting events in the Soroban smart contract. The `increment` method within the contract increments a counter, saves the updated count to the storage, and publishes an event with relevant details, including the count. The accompanying code demonstrates how to use the `stellar-sdk` library and the RPC API for interacting with the Soroban testnet. Additionally, the component includes a sample event query, allowing users to try out the code and retrieve contract events. The UI provides buttons for executing specific actions, such as getting events or triggering an increment event, and a console log for displaying the output. This component serves as a valuable resource for developers seeking hands-on experience with Soroban events on the Stellar network.
[Emitting and Retrieving Events](LINK)

# Migration between `soroban-client` to `stellar-sdk`

Within the realm of dapp development, two libraries are actively maintained—`soroban-client` and `stellar-sdk`. The primary emphasis in this context is streamlining the migration process from `soroban-client` to `stellar-sdk` for Soroban application development. The introductory section highlights the coexistence of these two JavaScript libraries and recommends opting for the more actively maintained `stellar-sdk` when constructing a Soroban/Stellar application. This superior library not only mirrors all the features of `soroban-client` but also integrates its implementation. The migration process between the two is straightforward, and the subsequent guide furnishes illustrative examples for transitioning key features, specifically focusing on `Server`, `SorobanRpc`, and `AssembleTransaction` functionalities.

[Migration between `soroban-client` to `stellar-sdk`](https://soroban-snippet.vercel.app/?title=006c32373d4763fded868582d4b15e586bcd05f3dba80c037b39d8fc4e509b3f)

# Soroban PRNG

In Preview 11, Soroban has implemented a Pseudo Random Generator (PRNG) in their smart contract SDK in `Rust`. This segment will take a look at Soroban Rust PRNG library, particularly relevant for Stellar smart contract development and adaptable for dapps seeking a reliable pseudorandom number generation (PRNG) solution. The library facilitates on-chain randomness and includes techniques for vector shuffling and generating random numbers within defined intervals. While it assures simplicity and reliability in generating randomness within the Stellar ecosystem, it's essential to note its unsuitability for security-sensitive applications or those with low risk tolerance. Further details and usage guidelines can be explored in the comprehensive documentation. The provided Rust code snippets offer practical demonstrations of these functionalities. Users can interactively experience the PRNG capabilities, such as rolling a dice and shuffling a provided list, through the demonstrated usage sections and associated buttons.

[Soroban PRNG](https://soroban-snippet.vercel.app/?title=c82e3da492308675b16f5122ff0980a54b5377805b51eb2a0466a6ef7f612578)

# Generating and Deriving Stellar Accounts with Seed Phrases

Stellar incorporates a key derivation protocol known as `SEP-0005`. This protocol plays a crucial role in enhancing key storage, fostering interoperability across wallets, supporting hardware wallets, and facilitating mnemonic code-based cold storage. The demonstration will leverage Bitcoin's BIP-0039 standard to generate a 12-word or 24-word seed phrase, serving as a standard for `SEP-0005`. The protocol utilizes the `m/44'/148'/0'` as the primary key. The article not only explores Stellar Ecosystem Proposal `SEP-0005` but also demonstrates how to generate word phrases for a Stellar account and derive them into Soroban's `KeyPair` for transaction use. This comprehensive overview equips developers with the knowledge and tools necessary for secure key management within the Stellar network, serving as a valuable guide for creating and integrating Stellar Wallets.

[Generating and Deriving Stellar Accounts with Seed Phrases](https://soroban-snippet.vercel.app/?title=8aac24da58aef76a88c54a9f6970d854f535402aebfeaf7300f4f2326a51e19b)